diff options
Diffstat (limited to 'contrib/llvm-project/clang/include/clang/Basic/Builtins.h')
-rw-r--r-- | contrib/llvm-project/clang/include/clang/Basic/Builtins.h | 114 |
1 files changed, 85 insertions, 29 deletions
diff --git a/contrib/llvm-project/clang/include/clang/Basic/Builtins.h b/contrib/llvm-project/clang/include/clang/Basic/Builtins.h index cdaaee48c32d..e85ec5b2dca1 100644 --- a/contrib/llvm-project/clang/include/clang/Basic/Builtins.h +++ b/contrib/llvm-project/clang/include/clang/Basic/Builtins.h @@ -16,6 +16,8 @@ #define LLVM_CLANG_BASIC_BUILTINS_H #include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/StringMap.h" +#include "llvm/ADT/StringRef.h" #include <cstring> // VC++ defines 'alloca' as an object-like macro, which interferes with our @@ -27,35 +29,51 @@ class TargetInfo; class IdentifierTable; class LangOptions; -enum LanguageID { - GNU_LANG = 0x1, // builtin requires GNU mode. - C_LANG = 0x2, // builtin for c only. - CXX_LANG = 0x4, // builtin for cplusplus only. - OBJC_LANG = 0x8, // builtin for objective-c and objective-c++ - MS_LANG = 0x10, // builtin requires MS mode. - OCLC20_LANG = 0x20, // builtin for OpenCL C 2.0 only. - OCLC1X_LANG = 0x40, // builtin for OpenCL C 1.x only. - OMP_LANG = 0x80, // builtin requires OpenMP. - CUDA_LANG = 0x100, // builtin requires CUDA. - COR_LANG = 0x200, // builtin requires use of 'fcoroutine-ts' option. +enum LanguageID : uint16_t { + GNU_LANG = 0x1, // builtin requires GNU mode. + C_LANG = 0x2, // builtin for c only. + CXX_LANG = 0x4, // builtin for cplusplus only. + OBJC_LANG = 0x8, // builtin for objective-c and objective-c++ + MS_LANG = 0x10, // builtin requires MS mode. + OMP_LANG = 0x20, // builtin requires OpenMP. + CUDA_LANG = 0x40, // builtin requires CUDA. + COR_LANG = 0x80, // builtin requires use of 'fcoroutine-ts' option. + OCL_GAS = 0x100, // builtin requires OpenCL generic address space. + OCL_PIPE = 0x200, // builtin requires OpenCL pipe. + OCL_DSE = 0x400, // builtin requires OpenCL device side enqueue. + ALL_OCL_LANGUAGES = 0x800, // builtin for OCL languages. + HLSL_LANG = 0x1000, // builtin requires HLSL. ALL_LANGUAGES = C_LANG | CXX_LANG | OBJC_LANG, // builtin for all languages. ALL_GNU_LANGUAGES = ALL_LANGUAGES | GNU_LANG, // builtin requires GNU mode. - ALL_MS_LANGUAGES = ALL_LANGUAGES | MS_LANG, // builtin requires MS mode. - ALL_OCLC_LANGUAGES = OCLC1X_LANG | OCLC20_LANG // builtin for OCLC languages. + ALL_MS_LANGUAGES = ALL_LANGUAGES | MS_LANG // builtin requires MS mode. +}; + +struct HeaderDesc { + enum HeaderID : uint16_t { +#define HEADER(ID, NAME) ID, +#include "clang/Basic/BuiltinHeaders.def" +#undef HEADER + } ID; + + constexpr HeaderDesc(HeaderID ID) : ID(ID) {} + + const char *getName() const; }; namespace Builtin { enum ID { NotBuiltin = 0, // This is not a builtin function. #define BUILTIN(ID, TYPE, ATTRS) BI##ID, -#include "clang/Basic/Builtins.def" +#include "clang/Basic/Builtins.inc" FirstTSBuiltin }; struct Info { - const char *Name, *Type, *Attributes, *HeaderName; - LanguageID Langs; + llvm::StringLiteral Name; + const char *Type, *Attributes; const char *Features; + HeaderDesc Header; + LanguageID Langs; }; /// Holds information about both target-independent and @@ -69,7 +87,7 @@ class Context { llvm::ArrayRef<Info> AuxTSRecords; public: - Context() {} + Context() = default; /// Perform target-specific initialization /// \param AuxTarget Target info to incorporate builtins from. May be nullptr. @@ -82,9 +100,7 @@ public: /// Return the identifier name for the specified builtin, /// e.g. "__builtin_abs". - const char *getName(unsigned ID) const { - return getRecord(ID).Name; - } + llvm::StringRef getName(unsigned ID) const { return getRecord(ID).Name; } /// Get the type descriptor string for the specified builtin. const char *getTypeString(unsigned ID) const { @@ -137,6 +153,10 @@ public: /// Determines whether this builtin is a predefined libc/libm /// function, such as "malloc", where we know the signature a /// priori. + /// In C, such functions behave as if they are predeclared, + /// possibly with a warning on first use. In Objective-C and C++, + /// they do not, but they are recognized as builtins once we see + /// a declaration. bool isPredefinedLibFunction(unsigned ID) const { return strchr(getRecord(ID).Attributes, 'f') != nullptr; } @@ -155,6 +175,23 @@ public: return strchr(getRecord(ID).Attributes, 'i') != nullptr; } + /// Determines whether this builtin is a C++ standard library function + /// that lives in (possibly-versioned) namespace std, possibly a template + /// specialization, where the signature is determined by the standard library + /// declaration. + bool isInStdNamespace(unsigned ID) const { + return strchr(getRecord(ID).Attributes, 'z') != nullptr; + } + + /// Determines whether this builtin can have its address taken with no + /// special action required. + bool isDirectlyAddressable(unsigned ID) const { + // Most standard library functions can have their addresses taken. C++ + // standard library functions formally cannot in C++20 onwards, and when + // we allow it, we need to ensure we instantiate a definition. + return isPredefinedLibFunction(ID) && !isInStdNamespace(ID); + } + /// Determines whether this builtin has custom typechecking. bool hasCustomTypechecking(unsigned ID) const { return strchr(getRecord(ID).Attributes, 't') != nullptr; @@ -183,7 +220,7 @@ public: /// If this is a library function that comes from a specific /// header, retrieve that header name. const char *getHeaderName(unsigned ID) const { - return getRecord(ID).HeaderName; + return getRecord(ID).Header.getName(); } /// Determine whether this builtin is like printf in its @@ -203,13 +240,18 @@ public: llvm::SmallVectorImpl<int> &Encoding) const; /// Return true if this function has no side effects and doesn't - /// read memory, except for possibly errno. + /// read memory, except for possibly errno or raising FP exceptions. /// - /// Such functions can be const when the MathErrno lang option is disabled. - bool isConstWithoutErrno(unsigned ID) const { + /// Such functions can be const when the MathErrno lang option and FP + /// exceptions are disabled. + bool isConstWithoutErrnoAndExceptions(unsigned ID) const { return strchr(getRecord(ID).Attributes, 'e') != nullptr; } + bool isConstWithoutExceptions(unsigned ID) const { + return strchr(getRecord(ID).Attributes, 'g') != nullptr; + } + const char *getRequiredFeatures(unsigned ID) const { return getRecord(ID).Features; } @@ -233,19 +275,33 @@ public: /// for non-builtins. bool canBeRedeclared(unsigned ID) const; + /// Return true if this function can be constant evaluated by Clang frontend. + bool isConstantEvaluated(unsigned ID) const { + return strchr(getRecord(ID).Attributes, 'E') != nullptr; + } + + /// Returns true if this is an immediate (consteval) function + bool isImmediate(unsigned ID) const { + return strchr(getRecord(ID).Attributes, 'G') != nullptr; + } + private: const Info &getRecord(unsigned ID) const; - /// Is this builtin supported according to the given language options? - bool builtinIsSupported(const Builtin::Info &BuiltinInfo, - const LangOptions &LangOpts); - /// Helper function for isPrintfLike and isScanfLike. bool isLike(unsigned ID, unsigned &FormatIdx, bool &HasVAListArg, const char *Fmt) const; }; -} +/// Returns true if the required target features of a builtin function are +/// enabled. +/// \p TargetFeatureMap maps a target feature to true if it is enabled and +/// false if it is disabled. +bool evaluateRequiredTargetFeatures( + llvm::StringRef RequiredFatures, + const llvm::StringMap<bool> &TargetFetureMap); + +} // namespace Builtin /// Kinds of BuiltinTemplateDecl. enum BuiltinTemplateKind : int { |