File indexing completed on 2026-05-10 08:36:48
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef LLVM_CLANG_BASIC_BUILTINS_H
0016 #define LLVM_CLANG_BASIC_BUILTINS_H
0017
0018 #include "llvm/ADT/ArrayRef.h"
0019 #include "llvm/ADT/StringMap.h"
0020 #include "llvm/ADT/StringRef.h"
0021 #include <cstring>
0022
0023
0024
0025 #undef alloca
0026
0027 namespace clang {
0028 class TargetInfo;
0029 class IdentifierTable;
0030 class LangOptions;
0031
0032 enum LanguageID : uint16_t {
0033 GNU_LANG = 0x1,
0034 C_LANG = 0x2,
0035 CXX_LANG = 0x4,
0036 OBJC_LANG = 0x8,
0037 MS_LANG = 0x10,
0038 OMP_LANG = 0x20,
0039 CUDA_LANG = 0x40,
0040 COR_LANG = 0x80,
0041 OCL_GAS = 0x100,
0042 OCL_PIPE = 0x200,
0043 OCL_DSE = 0x400,
0044 ALL_OCL_LANGUAGES = 0x800,
0045 HLSL_LANG = 0x1000,
0046 ALL_LANGUAGES = C_LANG | CXX_LANG | OBJC_LANG,
0047 ALL_GNU_LANGUAGES = ALL_LANGUAGES | GNU_LANG,
0048 ALL_MS_LANGUAGES = ALL_LANGUAGES | MS_LANG
0049 };
0050
0051 struct HeaderDesc {
0052 enum HeaderID : uint16_t {
0053 #define HEADER(ID, NAME) ID,
0054 #include "clang/Basic/BuiltinHeaders.def"
0055 #undef HEADER
0056 } ID;
0057
0058 constexpr HeaderDesc(HeaderID ID) : ID(ID) {}
0059
0060 const char *getName() const;
0061 };
0062
0063 namespace Builtin {
0064 enum ID {
0065 NotBuiltin = 0,
0066 #define BUILTIN(ID, TYPE, ATTRS) BI##ID,
0067 #include "clang/Basic/Builtins.inc"
0068 FirstTSBuiltin
0069 };
0070
0071 struct Info {
0072 llvm::StringLiteral Name;
0073 const char *Type, *Attributes;
0074 const char *Features;
0075 HeaderDesc Header;
0076 LanguageID Langs;
0077 };
0078
0079
0080
0081
0082
0083
0084
0085 class Context {
0086 llvm::ArrayRef<Info> TSRecords;
0087 llvm::ArrayRef<Info> AuxTSRecords;
0088
0089 public:
0090 Context() = default;
0091
0092
0093
0094 void InitializeTarget(const TargetInfo &Target, const TargetInfo *AuxTarget);
0095
0096
0097
0098
0099 void initializeBuiltins(IdentifierTable &Table, const LangOptions& LangOpts);
0100
0101
0102
0103 llvm::StringRef getName(unsigned ID) const { return getRecord(ID).Name; }
0104
0105
0106 std::string getQuotedName(unsigned ID) const;
0107
0108
0109 const char *getTypeString(unsigned ID) const { return getRecord(ID).Type; }
0110
0111
0112 bool isTSBuiltin(unsigned ID) const {
0113 return ID >= Builtin::FirstTSBuiltin;
0114 }
0115
0116
0117 bool isPure(unsigned ID) const {
0118 return strchr(getRecord(ID).Attributes, 'U') != nullptr;
0119 }
0120
0121
0122
0123 bool isConst(unsigned ID) const {
0124 return strchr(getRecord(ID).Attributes, 'c') != nullptr;
0125 }
0126
0127
0128 bool isNoThrow(unsigned ID) const {
0129 return strchr(getRecord(ID).Attributes, 'n') != nullptr;
0130 }
0131
0132
0133 bool isNoReturn(unsigned ID) const {
0134 return strchr(getRecord(ID).Attributes, 'r') != nullptr;
0135 }
0136
0137
0138 bool isReturnsTwice(unsigned ID) const {
0139 return strchr(getRecord(ID).Attributes, 'j') != nullptr;
0140 }
0141
0142
0143
0144 bool isUnevaluated(unsigned ID) const {
0145 return strchr(getRecord(ID).Attributes, 'u') != nullptr;
0146 }
0147
0148
0149
0150 bool isLibFunction(unsigned ID) const {
0151 return strchr(getRecord(ID).Attributes, 'F') != nullptr;
0152 }
0153
0154
0155
0156
0157
0158
0159
0160
0161 bool isPredefinedLibFunction(unsigned ID) const {
0162 return strchr(getRecord(ID).Attributes, 'f') != nullptr;
0163 }
0164
0165
0166
0167
0168 bool isHeaderDependentFunction(unsigned ID) const {
0169 return strchr(getRecord(ID).Attributes, 'h') != nullptr;
0170 }
0171
0172
0173
0174
0175 bool isPredefinedRuntimeFunction(unsigned ID) const {
0176 return strchr(getRecord(ID).Attributes, 'i') != nullptr;
0177 }
0178
0179
0180
0181
0182
0183 bool isInStdNamespace(unsigned ID) const {
0184 return strchr(getRecord(ID).Attributes, 'z') != nullptr;
0185 }
0186
0187
0188
0189 bool isDirectlyAddressable(unsigned ID) const {
0190
0191
0192
0193 return isPredefinedLibFunction(ID) && !isInStdNamespace(ID);
0194 }
0195
0196
0197 bool hasCustomTypechecking(unsigned ID) const {
0198 return strchr(getRecord(ID).Attributes, 't') != nullptr;
0199 }
0200
0201
0202
0203 bool allowTypeMismatch(unsigned ID) const {
0204 return strchr(getRecord(ID).Attributes, 'T') != nullptr ||
0205 hasCustomTypechecking(ID);
0206 }
0207
0208
0209
0210 bool hasPtrArgsOrResult(unsigned ID) const {
0211 return strchr(getRecord(ID).Type, '*') != nullptr;
0212 }
0213
0214
0215
0216 bool hasReferenceArgsOrResult(unsigned ID) const {
0217 return strchr(getRecord(ID).Type, '&') != nullptr ||
0218 strchr(getRecord(ID).Type, 'A') != nullptr;
0219 }
0220
0221
0222
0223 const char *getHeaderName(unsigned ID) const {
0224 return getRecord(ID).Header.getName();
0225 }
0226
0227
0228
0229
0230 bool isPrintfLike(unsigned ID, unsigned &FormatIdx, bool &HasVAListArg);
0231
0232
0233
0234
0235 bool isScanfLike(unsigned ID, unsigned &FormatIdx, bool &HasVAListArg);
0236
0237
0238
0239
0240 bool performsCallback(unsigned ID,
0241 llvm::SmallVectorImpl<int> &Encoding) const;
0242
0243
0244
0245
0246
0247
0248 bool isConstWithoutErrnoAndExceptions(unsigned ID) const {
0249 return strchr(getRecord(ID).Attributes, 'e') != nullptr;
0250 }
0251
0252 bool isConstWithoutExceptions(unsigned ID) const {
0253 return strchr(getRecord(ID).Attributes, 'g') != nullptr;
0254 }
0255
0256 const char *getRequiredFeatures(unsigned ID) const {
0257 return getRecord(ID).Features;
0258 }
0259
0260 unsigned getRequiredVectorWidth(unsigned ID) const;
0261
0262
0263 bool isAuxBuiltinID(unsigned ID) const {
0264 return ID >= (Builtin::FirstTSBuiltin + TSRecords.size());
0265 }
0266
0267
0268
0269 unsigned getAuxBuiltinID(unsigned ID) const { return ID - TSRecords.size(); }
0270
0271
0272
0273 static bool isBuiltinFunc(llvm::StringRef Name);
0274
0275
0276
0277 bool canBeRedeclared(unsigned ID) const;
0278
0279
0280 bool isConstantEvaluated(unsigned ID) const {
0281 return strchr(getRecord(ID).Attributes, 'E') != nullptr;
0282 }
0283
0284
0285 bool isImmediate(unsigned ID) const {
0286 return strchr(getRecord(ID).Attributes, 'G') != nullptr;
0287 }
0288
0289 private:
0290 const Info &getRecord(unsigned ID) const;
0291
0292
0293 bool isLike(unsigned ID, unsigned &FormatIdx, bool &HasVAListArg,
0294 const char *Fmt) const;
0295 };
0296
0297
0298
0299
0300
0301 bool evaluateRequiredTargetFeatures(
0302 llvm::StringRef RequiredFatures,
0303 const llvm::StringMap<bool> &TargetFetureMap);
0304
0305 }
0306
0307
0308 enum BuiltinTemplateKind : int {
0309
0310 BTK__make_integer_seq,
0311
0312
0313 BTK__type_pack_element,
0314
0315
0316 BTK__builtin_common_type,
0317 };
0318
0319 }
0320 #endif