18 #include "llvm/ADT/StringRef.h" 19 using namespace clang;
22 {
"not a builtin function",
nullptr,
nullptr,
nullptr,
ALL_LANGUAGES,
nullptr},
23 #define BUILTIN(ID, TYPE, ATTRS) \ 24 { #ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, nullptr }, 25 #define LANGBUILTIN(ID, TYPE, ATTRS, LANGS) \ 26 { #ID, TYPE, ATTRS, nullptr, LANGS, nullptr }, 27 #define LIBBUILTIN(ID, TYPE, ATTRS, HEADER, LANGS) \ 28 { #ID, TYPE, ATTRS, HEADER, LANGS, nullptr }, 29 #include "clang/Basic/Builtins.def" 34 return BuiltinInfo[
ID];
36 (TSRecords.size() + AuxTSRecords.size())) &&
37 "Invalid builtin ID!");
45 assert(TSRecords.empty() &&
"Already initialized target?");
52 StringRef FuncName(Name);
54 if (FuncName.equals(BuiltinInfo[i].
Name))
55 return strchr(BuiltinInfo[i].Attributes,
'f') !=
nullptr;
60 bool Builtin::Context::builtinIsSupported(
const Builtin::Info &BuiltinInfo,
62 bool BuiltinsUnsupported =
65 bool MathBuiltinsUnsupported =
66 LangOpts.NoMathBuiltin && BuiltinInfo.
HeaderName &&
67 llvm::StringRef(BuiltinInfo.
HeaderName).equals(
"math.h");
68 bool GnuModeUnsupported = !LangOpts.GNUMode && (BuiltinInfo.
Langs &
GNU_LANG);
69 bool MSModeUnsupported =
71 bool ObjCUnsupported = !LangOpts.ObjC && BuiltinInfo.
Langs ==
OBJC_LANG;
72 bool OclC1Unsupported = (LangOpts.OpenCLVersion / 100) != 1 &&
74 bool OclC2Unsupported = LangOpts.OpenCLVersion != 200 &&
76 bool OclCUnsupported = !LangOpts.OpenCL &&
78 bool OpenMPUnsupported = !LangOpts.OpenMP && BuiltinInfo.
Langs ==
OMP_LANG;
79 return !BuiltinsUnsupported && !MathBuiltinsUnsupported && !OclCUnsupported &&
80 !OclC1Unsupported && !OclC2Unsupported && !OpenMPUnsupported &&
81 !GnuModeUnsupported && !MSModeUnsupported && !ObjCUnsupported;
91 if (builtinIsSupported(BuiltinInfo[i], LangOpts)) {
96 for (
unsigned i = 0, e = TSRecords.size(); i != e; ++i)
97 if (builtinIsSupported(TSRecords[i], LangOpts))
101 for (
unsigned i = 0, e = AuxTSRecords.size(); i != e; ++i)
102 Table.
get(AuxTSRecords[i].Name)
111 const char *WidthPos = ::strchr(getRecord(ID).Attributes,
'V');
116 assert(*WidthPos ==
':' &&
117 "Vector width specifier must be followed by a ':'");
121 unsigned Width = ::strtol(WidthPos, &EndPos, 10);
122 assert(*EndPos ==
':' &&
"Vector width specific must end with a ':'");
126 bool Builtin::Context::isLike(
unsigned ID,
unsigned &FormatIdx,
127 bool &HasVAListArg,
const char *Fmt)
const {
128 assert(Fmt &&
"Not passed a format string");
129 assert(::strlen(Fmt) == 2 &&
130 "Format string needs to be two characters long");
131 assert(::toupper(Fmt[0]) == Fmt[1] &&
132 "Format string is not in the form \"xX\"");
134 const char *Like = ::strpbrk(getRecord(
ID).Attributes, Fmt);
138 HasVAListArg = (*Like == Fmt[1]);
141 assert(*Like ==
':' &&
"Format specifier must be followed by a ':'");
144 assert(::strchr(Like,
':') &&
"Format specifier must end with a ':'");
145 FormatIdx = ::strtol(Like,
nullptr, 10);
150 bool &HasVAListArg) {
151 return isLike(ID, FormatIdx, HasVAListArg,
"pP");
155 bool &HasVAListArg) {
156 return isLike(ID, FormatIdx, HasVAListArg,
"sS");
161 ID == Builtin::BI__va_start ||
bool hasReferenceArgsOrResult(unsigned ID) const
Return true if this builtin has a result or any arguments which are reference types.
bool isNoBuiltinFunc(StringRef Name) const
Is this a libc/libm function that is no longer recognized as a builtin because a -fno-builtin-* optio...
static const Builtin::Info BuiltinInfo[]
static bool isBuiltinFunc(const char *Name)
Returns true if this is a libc/libm function without the '__builtin_' prefix.
void forgetBuiltin(unsigned ID, IdentifierTable &Table)
Completely forget that the given ID was ever considered a builtin, e.g., because the user provided a ...
bool isPrintfLike(unsigned ID, unsigned &FormatIdx, bool &HasVAListArg)
Determine whether this builtin is like printf in its formatting rules and, if so, set the index to th...
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
unsigned getAuxBuiltinID(unsigned ID) const
Return real builtin ID (i.e.
unsigned getRequiredVectorWidth(unsigned ID) const
Exposes information about the current target.
Defines the clang::LangOptions interface.
Implements an efficient mapping from strings to IdentifierInfo nodes.
bool canBeRedeclared(unsigned ID) const
Returns true if this is a builtin that can be redeclared.
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
bool isAuxBuiltinID(unsigned ID) const
Return true if builtin ID belongs to AuxTarget.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
void initializeBuiltins(IdentifierTable &Table, const LangOptions &LangOpts)
Mark the identifiers for all the builtins with their appropriate builtin ID # and mark any non-portab...
virtual ArrayRef< Builtin::Info > getTargetBuiltins() const =0
Return information about target-specific builtins for the current primary target, and info about whic...
bool isScanfLike(unsigned ID, unsigned &FormatIdx, bool &HasVAListArg)
Determine whether this builtin is like scanf in its formatting rules and, if so, set the index to the...
Dataflow Directional Tag Classes.
void setBuiltinID(unsigned ID)
Defines the clang::TargetInfo interface.
bool hasCustomTypechecking(unsigned ID) const
Determines whether this builtin has custom typechecking.
void InitializeTarget(const TargetInfo &Target, const TargetInfo *AuxTarget)
Perform target-specific initialization.
Defines enum values for all the target-independent builtin functions.