17 #include "llvm/ADT/StringRef.h" 18 using namespace clang;
21 {
"not a builtin function",
nullptr,
nullptr,
nullptr,
ALL_LANGUAGES,
nullptr},
22 #define BUILTIN(ID, TYPE, ATTRS) \ 23 { #ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, nullptr }, 24 #define LANGBUILTIN(ID, TYPE, ATTRS, LANGS) \ 25 { #ID, TYPE, ATTRS, nullptr, LANGS, nullptr }, 26 #define LIBBUILTIN(ID, TYPE, ATTRS, HEADER, LANGS) \ 27 { #ID, TYPE, ATTRS, HEADER, LANGS, nullptr }, 28 #include "clang/Basic/Builtins.def" 33 return BuiltinInfo[
ID];
35 (TSRecords.size() + AuxTSRecords.size())) &&
36 "Invalid builtin ID!");
44 assert(TSRecords.empty() &&
"Already initialized target?");
52 if (FuncName.equals(BuiltinInfo[i].
Name))
53 return strchr(BuiltinInfo[i].Attributes,
'f') !=
nullptr;
58 bool Builtin::Context::builtinIsSupported(
const Builtin::Info &BuiltinInfo,
60 bool BuiltinsUnsupported =
63 bool MathBuiltinsUnsupported =
64 LangOpts.NoMathBuiltin && BuiltinInfo.
HeaderName &&
65 llvm::StringRef(BuiltinInfo.
HeaderName).equals(
"math.h");
66 bool GnuModeUnsupported = !LangOpts.GNUMode && (BuiltinInfo.
Langs &
GNU_LANG);
67 bool MSModeUnsupported =
69 bool ObjCUnsupported = !LangOpts.ObjC && BuiltinInfo.
Langs ==
OBJC_LANG;
70 bool OclC1Unsupported = (LangOpts.OpenCLVersion / 100) != 1 &&
72 bool OclC2Unsupported =
73 (LangOpts.OpenCLVersion != 200 && !LangOpts.OpenCLCPlusPlus) &&
75 bool OclCUnsupported = !LangOpts.OpenCL &&
77 bool OpenMPUnsupported = !LangOpts.OpenMP && BuiltinInfo.
Langs ==
OMP_LANG;
78 bool CPlusPlusUnsupported =
80 return !BuiltinsUnsupported && !MathBuiltinsUnsupported && !OclCUnsupported &&
81 !OclC1Unsupported && !OclC2Unsupported && !OpenMPUnsupported &&
82 !GnuModeUnsupported && !MSModeUnsupported && !ObjCUnsupported &&
83 !CPlusPlusUnsupported;
93 if (builtinIsSupported(BuiltinInfo[i], LangOpts)) {
98 for (
unsigned i = 0, e = TSRecords.size(); i != e; ++i)
99 if (builtinIsSupported(TSRecords[i], LangOpts))
103 for (
unsigned i = 0, e = AuxTSRecords.size(); i != e; ++i)
104 Table.
get(AuxTSRecords[i].Name)
113 const char *WidthPos = ::strchr(getRecord(ID).Attributes,
'V');
118 assert(*WidthPos ==
':' &&
119 "Vector width specifier must be followed by a ':'");
123 unsigned Width = ::strtol(WidthPos, &EndPos, 10);
124 assert(*EndPos ==
':' &&
"Vector width specific must end with a ':'");
128 bool Builtin::Context::isLike(
unsigned ID,
unsigned &FormatIdx,
129 bool &HasVAListArg,
const char *Fmt)
const {
130 assert(Fmt &&
"Not passed a format string");
131 assert(::strlen(Fmt) == 2 &&
132 "Format string needs to be two characters long");
133 assert(::toupper(Fmt[0]) == Fmt[1] &&
134 "Format string is not in the form \"xX\"");
136 const char *Like = ::strpbrk(getRecord(
ID).Attributes, Fmt);
140 HasVAListArg = (*Like == Fmt[1]);
143 assert(*Like ==
':' &&
"Format specifier must be followed by a ':'");
146 assert(::strchr(Like,
':') &&
"Format specifier must end with a ':'");
147 FormatIdx = ::strtol(Like,
nullptr, 10);
152 bool &HasVAListArg) {
153 return isLike(ID, FormatIdx, HasVAListArg,
"pP");
157 bool &HasVAListArg) {
158 return isLike(ID, FormatIdx, HasVAListArg,
"sS");
163 const char *CalleePos = ::strchr(getRecord(ID).Attributes,
'C');
168 assert(*CalleePos ==
'<' &&
169 "Callback callee specifier must be followed by a '<'");
173 int CalleeIdx = ::strtol(CalleePos, &EndPos, 10);
174 assert(CalleeIdx >= 0 &&
"Callee index is supposed to be positive!");
175 Encoding.push_back(CalleeIdx);
177 while (*EndPos ==
',') {
178 const char *PayloadPos = EndPos + 1;
180 int PayloadIdx = ::strtol(PayloadPos, &EndPos, 10);
181 Encoding.push_back(PayloadIdx);
184 assert(*EndPos ==
'>' &&
"Callback callee specifier must end with a '>'");
190 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[]
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.
bool performsCallback(unsigned ID, llvm::SmallVectorImpl< int > &Encoding) const
Determine whether this builtin has callback behavior (see llvm::AbstractCallSites for details)...
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...
static bool isBuiltinFunc(llvm::StringRef Name)
Returns true if this is a libc/libm function without the '__builtin_' prefix.
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.