clang 23.0.0git
Builtins.h
Go to the documentation of this file.
1//===--- Builtins.h - Builtin function header -------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// Defines enum values for all the target-independent builtin
11/// functions.
12///
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CLANG_BASIC_BUILTINS_H
16#define LLVM_CLANG_BASIC_BUILTINS_H
17
18#include "llvm/ADT/ArrayRef.h"
19#include "llvm/ADT/StringMap.h"
20#include "llvm/ADT/StringRef.h"
21#include "llvm/ADT/StringTable.h"
22#include "llvm/TargetParser/Triple.h"
23#include <cstring>
24
25// VC++ defines 'alloca' as an object-like macro, which interferes with our
26// builtins.
27#undef alloca
28
29namespace clang {
30class TargetInfo;
31class IdentifierTable;
32class LangOptions;
33
34enum LanguageID : uint16_t {
35 GNU_LANG = 0x1, // builtin requires GNU mode.
36 C_LANG = 0x2, // builtin for c only.
37 CXX_LANG = 0x4, // builtin for cplusplus only.
38 OBJC_LANG = 0x8, // builtin for objective-c and objective-c++
39 MS_LANG = 0x10, // builtin requires MS mode.
40 OMP_LANG = 0x20, // builtin requires OpenMP.
41 CUDA_LANG = 0x40, // builtin requires CUDA.
42 COR_LANG = 0x80, // builtin requires use of 'fcoroutine-ts' option.
43 OCL_GAS = 0x100, // builtin requires OpenCL generic address space.
44 OCL_PIPE = 0x200, // builtin requires OpenCL pipe.
45 OCL_DSE = 0x400, // builtin requires OpenCL device side enqueue.
46 ALL_OCL_LANGUAGES = 0x800, // builtin for OCL languages.
47 HLSL_LANG = 0x1000, // builtin requires HLSL.
48 C23_LANG = 0x2000, // builtin requires C23 or later.
49 C2Y_LANG = 0x4000, // builtin requires C2y or later.
50 ALL_LANGUAGES = C_LANG | CXX_LANG | OBJC_LANG, // builtin for all languages.
51 ALL_GNU_LANGUAGES = ALL_LANGUAGES | GNU_LANG, // builtin requires GNU mode.
52 ALL_MS_LANGUAGES = ALL_LANGUAGES | MS_LANG // builtin requires MS mode.
53};
54
55struct HeaderDesc {
56 enum HeaderID : uint16_t {
57#define HEADER(ID, NAME) ID,
58#include "clang/Basic/BuiltinHeaders.def"
59#undef HEADER
60 } ID;
61
62 constexpr HeaderDesc() : ID() {}
63 constexpr HeaderDesc(HeaderID ID) : ID(ID) {}
64
65 const char *getName() const;
66};
67
68namespace Builtin {
69enum ID {
70 NotBuiltin = 0, // This is not a builtin function.
71#define GET_BUILTIN_ENUMERATORS
72#include "clang/Basic/Builtins.inc"
73#undef GET_BUILTIN_ENUMERATORS
75};
76
77struct InfosShard;
78
79/// The info used to represent each builtin.
80struct Info {
81 // Rather than store pointers to the string literals describing these four
82 // aspects of builtins, we store offsets into a common string table.
83 struct StrOffsets {
84 llvm::StringTable::Offset Name = {};
85 llvm::StringTable::Offset Type = {};
86 llvm::StringTable::Offset Attributes = {};
87
88 // Defaults to the empty string offset.
89 llvm::StringTable::Offset Features = {};
91
92 HeaderDesc Header = HeaderDesc::NO_HEADER;
94
95 /// Get the name for the builtin represented by this `Info` object.
96 ///
97 /// Must be provided the `Shard` for this `Info` object.
98 std::string getName(const InfosShard &Shard) const;
99
100 // Builtin non-null attribute modes.
101 // NonOptimizing: attaches Clang's `_Nonnull` type qualifier to parameters.
102 // Optimizing: emits the classic GNU-style `nonnull` attribute for
103 // optimization.
105};
106
107/// A constexpr function to construct an infos array from X-macros.
108///
109/// The input array uses the same data structure, but the offsets are actually
110/// _lengths_ when input. This is all we can compute from the X-macro approach
111/// to builtins. This function will convert these lengths into actual offsets to
112/// a string table built up through sequentially appending strings with the
113/// given lengths.
114template <size_t N>
115static constexpr std::array<Info, N> MakeInfos(std::array<Info, N> Infos) {
116 // Translate lengths to offsets. We start past the initial empty string at
117 // offset zero.
118 unsigned Offset = 1;
119 for (Info &I : Infos) {
120 Info::StrOffsets NewOffsets = {};
121 NewOffsets.Name = Offset;
122 Offset += I.Offsets.Name.value();
123 NewOffsets.Type = Offset;
124 Offset += I.Offsets.Type.value();
125 NewOffsets.Attributes = Offset;
126 Offset += I.Offsets.Attributes.value();
127 NewOffsets.Features = Offset;
128 Offset += I.Offsets.Features.value();
129 I.Offsets = NewOffsets;
130 }
131 return Infos;
132}
133
134/// A shard of a target's builtins string table and info.
135///
136/// Target builtins are sharded across multiple tables due to different
137/// structures, origins, and also to improve the overall scaling by avoiding a
138/// single table across all builtins.
140 const llvm::StringTable *Strings;
142
143 llvm::StringLiteral NamePrefix = "";
144};
145
146// A detail macro used below to emit a string literal that, after string literal
147// concatenation, ends up triggering the `-Woverlength-strings` warning. While
148// the warning is useful in general to catch accidentally excessive strings,
149// here we are creating them intentionally.
150//
151// This relies on a subtle aspect of `_Pragma`: that the *diagnostic* ones don't
152// turn into actual tokens that would disrupt string literal concatenation.
153#ifdef __clang__
154#define CLANG_BUILTIN_DETAIL_STR_TABLE(S) \
155 _Pragma("clang diagnostic push") \
156 _Pragma("clang diagnostic ignored \"-Woverlength-strings\"") \
157 S _Pragma("clang diagnostic pop")
158#else
159#define CLANG_BUILTIN_DETAIL_STR_TABLE(S) S
160#endif
161
162// We require string tables to start with an empty string so that a `0` offset
163// can always be used to refer to an empty string. To satisfy that when building
164// string tables with X-macros, we use this start macro prior to expanding the
165// X-macros.
166#define CLANG_BUILTIN_STR_TABLE_START CLANG_BUILTIN_DETAIL_STR_TABLE("\0")
167
168// A macro that can be used with `Builtins.def` and similar files as an X-macro
169// to add the string arguments to a builtin string table. This is typically the
170// target for the `BUILTIN`, `LANGBUILTIN`, or `LIBBUILTIN` macros in those
171// files.
172#define CLANG_BUILTIN_STR_TABLE(ID, TYPE, ATTRS) \
173 CLANG_BUILTIN_DETAIL_STR_TABLE(#ID "\0" TYPE "\0" ATTRS "\0" /*FEATURE*/ "\0")
174
175// A macro that can be used with target builtin `.def` and `.inc` files as an
176// X-macro to add the string arguments to a builtin string table. this is
177// typically the target for the `TARGET_BUILTIN` macro.
178#define CLANG_TARGET_BUILTIN_STR_TABLE(ID, TYPE, ATTRS, FEATURE) \
179 CLANG_BUILTIN_DETAIL_STR_TABLE(#ID "\0" TYPE "\0" ATTRS "\0" FEATURE "\0")
180
181// A macro that can be used with target builtin `.def` and `.inc` files as an
182// X-macro to add the string arguments to a builtin string table. this is
183// typically the target for the `TARGET_HEADER_BUILTIN` macro. We can't delegate
184// to `TARGET_BUILTIN` because the `FEATURE` string changes position.
185#define CLANG_TARGET_HEADER_BUILTIN_STR_TABLE(ID, TYPE, ATTRS, HEADER, LANGS, \
186 FEATURE) \
187 CLANG_BUILTIN_DETAIL_STR_TABLE(#ID "\0" TYPE "\0" ATTRS "\0" FEATURE "\0")
188
189// A detail macro used internally to compute the desired string table
190// `StrOffsets` struct for arguments to `MakeInfos`.
191#define CLANG_BUILTIN_DETAIL_STR_OFFSETS(ID, TYPE, ATTRS) \
192 Builtin::Info::StrOffsets { \
193 sizeof(#ID), sizeof(TYPE), sizeof(ATTRS), sizeof("") \
194 }
195
196// A detail macro used internally to compute the desired string table
197// `StrOffsets` struct for arguments to `Storage::Make`.
198#define CLANG_TARGET_BUILTIN_DETAIL_STR_OFFSETS(ID, TYPE, ATTRS, FEATURE) \
199 Builtin::Info::StrOffsets { \
200 sizeof(#ID), sizeof(TYPE), sizeof(ATTRS), sizeof(FEATURE) \
201 }
202
203// A set of macros that can be used with builtin `.def' files as an X-macro to
204// create an `Info` struct for a particular builtin. It both computes the
205// `StrOffsets` value for the string table (the lengths here, translated to
206// offsets by the `MakeInfos` function), and the other metadata for each
207// builtin.
208//
209// There is a corresponding macro for each of `BUILTIN`, `LANGBUILTIN`,
210// `LIBBUILTIN`, `TARGET_BUILTIN`, and `TARGET_HEADER_BUILTIN`.
211#define CLANG_BUILTIN_ENTRY(ID, TYPE, ATTRS) \
212 Builtin::Info{CLANG_BUILTIN_DETAIL_STR_OFFSETS(ID, TYPE, ATTRS), \
213 HeaderDesc::NO_HEADER, ALL_LANGUAGES},
214#define CLANG_LANGBUILTIN_ENTRY(ID, TYPE, ATTRS, LANG) \
215 Builtin::Info{CLANG_BUILTIN_DETAIL_STR_OFFSETS(ID, TYPE, ATTRS), \
216 HeaderDesc::NO_HEADER, LANG},
217#define CLANG_LIBBUILTIN_ENTRY(ID, TYPE, ATTRS, HEADER, LANG) \
218 Builtin::Info{CLANG_BUILTIN_DETAIL_STR_OFFSETS(ID, TYPE, ATTRS), \
219 HeaderDesc::HEADER, LANG},
220#define CLANG_TARGET_BUILTIN_ENTRY(ID, TYPE, ATTRS, FEATURE) \
221 Builtin::Info{ \
222 CLANG_TARGET_BUILTIN_DETAIL_STR_OFFSETS(ID, TYPE, ATTRS, FEATURE), \
223 HeaderDesc::NO_HEADER, ALL_LANGUAGES},
224#define CLANG_TARGET_HEADER_BUILTIN_ENTRY(ID, TYPE, ATTRS, HEADER, LANG, \
225 FEATURE) \
226 Builtin::Info{ \
227 CLANG_TARGET_BUILTIN_DETAIL_STR_OFFSETS(ID, TYPE, ATTRS, FEATURE), \
228 HeaderDesc::HEADER, LANG},
229
230/// Holds information about both target-independent and
231/// target-specific builtins, allowing easy queries by clients.
232///
233/// Builtins from an optional auxiliary target are stored in
234/// AuxTSRecords. Their IDs are shifted up by TSRecords.size() and need to
235/// be translated back with getAuxBuiltinID() before use.
236class Context {
237 llvm::SmallVector<InfosShard> BuiltinShards;
238
240 llvm::SmallVector<InfosShard> AuxTargetShards;
241
242 unsigned NumTargetBuiltins = 0;
243 unsigned NumAuxTargetBuiltins = 0;
244
245public:
246 Context();
247
248 /// Perform target-specific initialization
249 /// \param AuxTarget Target info to incorporate builtins from. May be nullptr.
250 void InitializeTarget(const TargetInfo &Target, const TargetInfo *AuxTarget);
251
252 /// Mark the identifiers for all the builtins with their
253 /// appropriate builtin ID # and mark any non-portable builtin identifiers as
254 /// such.
255 void initializeBuiltins(IdentifierTable &Table, const LangOptions& LangOpts);
256
257 /// Return the identifier name for the specified builtin,
258 /// e.g. "__builtin_abs".
259 std::string getName(unsigned ID) const;
260
261 /// Return the identifier name for the specified builtin inside single quotes
262 /// for a diagnostic, e.g. "'__builtin_abs'".
263 std::string getQuotedName(unsigned ID) const;
264
265 /// Get the type descriptor string for the specified builtin.
266 const char *getTypeString(unsigned ID) const;
267
268 /// Get the attributes descriptor string for the specified builtin.
269 const char *getAttributesString(unsigned ID) const;
270
271 /// Return true if this function is a target-specific builtin.
272 bool isTSBuiltin(unsigned ID) const {
273 return ID >= Builtin::FirstTSBuiltin;
274 }
275
276 /// Return true if this function has no side effects.
277 bool isPure(unsigned ID) const {
278 return strchr(getAttributesString(ID), 'U') != nullptr;
279 }
280
281 /// Return true if this function has no side effects and doesn't
282 /// read memory.
283 bool isConst(unsigned ID) const {
284 return strchr(getAttributesString(ID), 'c') != nullptr;
285 }
286
287 /// Return true if we know this builtin never throws an exception.
288 bool isNoThrow(unsigned ID) const {
289 return strchr(getAttributesString(ID), 'n') != nullptr;
290 }
291
292 /// Return true if we know this builtin never returns.
293 bool isNoReturn(unsigned ID) const {
294 return strchr(getAttributesString(ID), 'r') != nullptr;
295 }
296
297 /// Return true if we know this builtin can return twice.
298 bool isReturnsTwice(unsigned ID) const {
299 return strchr(getAttributesString(ID), 'j') != nullptr;
300 }
301
302 /// Returns true if this builtin does not perform the side-effects
303 /// of its arguments.
304 bool isUnevaluated(unsigned ID) const {
305 return strchr(getAttributesString(ID), 'u') != nullptr;
306 }
307
308 /// Return true if this is a builtin for a libc/libm function,
309 /// with a "__builtin_" prefix (e.g. __builtin_abs).
310 bool isLibFunction(unsigned ID) const {
311 return strchr(getAttributesString(ID), 'F') != nullptr;
312 }
313
314 /// Determines whether this builtin is a predefined libc/libm
315 /// function, such as "malloc", where we know the signature a
316 /// priori.
317 /// In C, such functions behave as if they are predeclared,
318 /// possibly with a warning on first use. In Objective-C and C++,
319 /// they do not, but they are recognized as builtins once we see
320 /// a declaration.
321 bool isPredefinedLibFunction(unsigned ID) const {
322 return strchr(getAttributesString(ID), 'f') != nullptr;
323 }
324
325 /// Returns true if this builtin requires appropriate header in other
326 /// compilers. In Clang it will work even without including it, but we can emit
327 /// a warning about missing header.
328 bool isHeaderDependentFunction(unsigned ID) const {
329 return strchr(getAttributesString(ID), 'h') != nullptr;
330 }
331
332 /// Determines whether this builtin is a predefined compiler-rt/libgcc
333 /// function, such as "__clear_cache", where we know the signature a
334 /// priori.
335 bool isPredefinedRuntimeFunction(unsigned ID) const {
336 return strchr(getAttributesString(ID), 'i') != nullptr;
337 }
338
339 /// Determines whether this builtin is a C++ standard library function
340 /// that lives in (possibly-versioned) namespace std, possibly a template
341 /// specialization, where the signature is determined by the standard library
342 /// declaration.
343 bool isInStdNamespace(unsigned ID) const {
344 return strchr(getAttributesString(ID), 'z') != nullptr;
345 }
346
347 /// Determines whether this builtin can have its address taken with no
348 /// special action required.
349 bool isDirectlyAddressable(unsigned ID) const {
350 // Most standard library functions can have their addresses taken. C++
351 // standard library functions formally cannot in C++20 onwards, and when
352 // we allow it, we need to ensure we instantiate a definition.
354 }
355
356 /// Determines whether this builtin has custom typechecking.
357 bool hasCustomTypechecking(unsigned ID) const {
358 return strchr(getAttributesString(ID), 't') != nullptr;
359 }
360
361 /// Determines whether a declaration of this builtin should be recognized
362 /// even if the type doesn't match the specified signature.
363 bool allowTypeMismatch(unsigned ID) const {
364 return strchr(getAttributesString(ID), 'T') != nullptr ||
366 }
367
368 /// Determines whether this builtin has a result or any arguments which
369 /// are pointer types.
370 bool hasPtrArgsOrResult(unsigned ID) const {
371 return strchr(getTypeString(ID), '*') != nullptr;
372 }
373
374 /// Return true if this builtin has a result or any arguments which are
375 /// reference types.
376 bool hasReferenceArgsOrResult(unsigned ID) const {
377 return strchr(getTypeString(ID), '&') != nullptr ||
378 strchr(getTypeString(ID), 'A') != nullptr;
379 }
380
381 /// If this is a library function that comes from a specific
382 /// header, retrieve that header name.
383 const char *getHeaderName(unsigned ID) const {
384 return getInfo(ID).Header.getName();
385 }
386
387 /// Determine whether this builtin is like printf in its
388 /// formatting rules and, if so, set the index to the format string
389 /// argument and whether this function as a va_list argument.
390 bool isPrintfLike(unsigned ID, unsigned &FormatIdx, bool &HasVAListArg);
391
392 /// Determine whether this builtin is like scanf in its
393 /// formatting rules and, if so, set the index to the format string
394 /// argument and whether this function as a va_list argument.
395 bool isScanfLike(unsigned ID, unsigned &FormatIdx, bool &HasVAListArg);
396
397 /// Determine whether this builtin has callback behavior (see
398 /// llvm::AbstractCallSites for details). If so, add the index to the
399 /// callback callee argument and the callback payload arguments.
400 bool performsCallback(unsigned ID,
401 llvm::SmallVectorImpl<int> &Encoding) const;
402
403 /// Return true if this builtin has parameters that must be non-null.
404 /// The parameter indices are appended into 'Indxs'.
405 bool isNonNull(unsigned ID, llvm::SmallVectorImpl<int> &Indxs,
406 Info::NonNullMode &Mode) const;
407
408 /// Return true if this function has no side effects and doesn't
409 /// read memory, except for possibly errno or raising FP exceptions.
410 ///
411 /// Such functions can be const when the MathErrno lang option and FP
412 /// exceptions are disabled.
414 return strchr(getAttributesString(ID), 'e') != nullptr;
415 }
416
417 bool isConstWithoutExceptions(unsigned ID) const {
418 return strchr(getAttributesString(ID), 'g') != nullptr;
419 }
420
421 /// Determine whether we can generate LLVM intrinsics for the given
422 /// builtin ID, based on whether it has side effects such as setting errno.
423 ///
424 /// \param BuiltinID The builtin ID to check.
425 /// \param Trip The target triple.
426 /// \param ErrnoOverwritten Indicates whether the errno setting behavior
427 /// has been overwritten via '#pragma float_control(precise, on/off)'.
428 /// \param MathErrnoEnabled Indicates whether math-errno is enabled on
429 /// command line.
430 /// \param HasOptNoneAttr True iff 'attribute__((optnone))' is used.
431 /// \param IsOptimizationEnabled True iff the optimization level is not 'O0'.
432 bool shouldGenerateFPMathIntrinsic(unsigned BuiltinID, llvm::Triple Trip,
433 std::optional<bool> ErrnoOverwritten,
434 bool MathErrnoEnabled, bool HasOptNoneAttr,
435 bool IsOptimizationEnabled) const;
436
437 const char *getRequiredFeatures(unsigned ID) const;
438
439 unsigned getRequiredVectorWidth(unsigned ID) const;
440
441 /// Return true if the builtin ID belongs exclusively to the AuxTarget,
442 /// and false if it belongs to both primary and aux target, or neither.
443 bool isAuxBuiltinID(unsigned ID) const {
444 return ID >= (Builtin::FirstTSBuiltin + NumTargetBuiltins);
445 }
446
447 /// Return real builtin ID (i.e. ID it would have during compilation
448 /// for AuxTarget).
449 unsigned getAuxBuiltinID(unsigned ID) const { return ID - NumTargetBuiltins; }
450
451 /// Returns true if this is a libc/libm function without the '__builtin_'
452 /// prefix.
453 static bool isBuiltinFunc(llvm::StringRef Name);
454
455 /// Returns true if this is a builtin that can be redeclared. Returns true
456 /// for non-builtins.
457 bool canBeRedeclared(unsigned ID) const;
458
459 /// Return true if this function can be constant evaluated by Clang frontend.
460 bool isConstantEvaluated(unsigned ID) const {
461 return strchr(getAttributesString(ID), 'E') != nullptr;
462 }
463
464 /// Returns true if this is an immediate (consteval) function
465 bool isImmediate(unsigned ID) const {
466 return strchr(getAttributesString(ID), 'G') != nullptr;
467 }
468
469private:
470 std::pair<const InfosShard &, const Info &>
471 getShardAndInfo(unsigned ID) const;
472
473 const Info &getInfo(unsigned ID) const { return getShardAndInfo(ID).second; }
474
475 /// Helper function for isPrintfLike and isScanfLike.
476 bool isLike(unsigned ID, unsigned &FormatIdx, bool &HasVAListArg,
477 const char *Fmt) const;
478};
479
480/// Returns true if the required target features of a builtin function are
481/// enabled.
482/// \p TargetFeatureMap maps a target feature to true if it is enabled and
483/// false if it is disabled.
485 llvm::StringRef RequiredFatures,
486 const llvm::StringMap<bool> &TargetFetureMap);
487
488} // namespace Builtin
489
490/// Kinds of BuiltinTemplateDecl.
492#define BuiltinTemplate(BTName) BTK##BTName,
493#include "clang/Basic/BuiltinTemplates.inc"
494};
495
496} // end namespace clang
497#endif
static const TypeInfo & getInfo(unsigned id)
Definition Types.cpp:44
bool shouldGenerateFPMathIntrinsic(unsigned BuiltinID, llvm::Triple Trip, std::optional< bool > ErrnoOverwritten, bool MathErrnoEnabled, bool HasOptNoneAttr, bool IsOptimizationEnabled) const
Determine whether we can generate LLVM intrinsics for the given builtin ID, based on whether it has s...
Definition Builtins.cpp:228
bool isUnevaluated(unsigned ID) const
Returns true if this builtin does not perform the side-effects of its arguments.
Definition Builtins.h:304
std::string getQuotedName(unsigned ID) const
Return the identifier name for the specified builtin inside single quotes for a diagnostic,...
Definition Builtins.cpp:85
bool hasReferenceArgsOrResult(unsigned ID) const
Return true if this builtin has a result or any arguments which are reference types.
Definition Builtins.h:376
bool performsCallback(unsigned ID, llvm::SmallVectorImpl< int > &Encoding) const
Determine whether this builtin has callback behavior (see llvm::AbstractCallSites for details).
Definition Builtins.cpp:434
bool isAuxBuiltinID(unsigned ID) const
Return true if the builtin ID belongs exclusively to the AuxTarget, and false if it belongs to both p...
Definition Builtins.h:443
bool isLibFunction(unsigned ID) const
Return true if this is a builtin for a libc/libm function, with a "__builtin_" prefix (e....
Definition Builtins.h:310
bool isNonNull(unsigned ID, llvm::SmallVectorImpl< int > &Indxs, Info::NonNullMode &Mode) const
Return true if this builtin has parameters that must be non-null.
Definition Builtins.cpp:409
const char * getHeaderName(unsigned ID) const
If this is a library function that comes from a specific header, retrieve that header name.
Definition Builtins.h:383
bool hasPtrArgsOrResult(unsigned ID) const
Determines whether this builtin has a result or any arguments which are pointer types.
Definition Builtins.h:370
bool isReturnsTwice(unsigned ID) const
Return true if we know this builtin can return twice.
Definition Builtins.h:298
bool isImmediate(unsigned ID) const
Returns true if this is an immediate (consteval) function.
Definition Builtins.h:465
bool isConstWithoutErrnoAndExceptions(unsigned ID) const
Return true if this function has no side effects and doesn't read memory, except for possibly errno o...
Definition Builtins.h:413
static bool isBuiltinFunc(llvm::StringRef Name)
Returns true if this is a libc/libm function without the '__builtin_' prefix.
Definition Builtins.cpp:123
unsigned getRequiredVectorWidth(unsigned ID) const
Definition Builtins.cpp:340
unsigned getAuxBuiltinID(unsigned ID) const
Return real builtin ID (i.e.
Definition Builtins.h:449
bool allowTypeMismatch(unsigned ID) const
Determines whether a declaration of this builtin should be recognized even if the type doesn't match ...
Definition Builtins.h:363
bool isTSBuiltin(unsigned ID) const
Return true if this function is a target-specific builtin.
Definition Builtins.h:272
bool hasCustomTypechecking(unsigned ID) const
Determines whether this builtin has custom typechecking.
Definition Builtins.h:357
std::string getName(unsigned ID) const
Return the identifier name for the specified builtin, e.g.
Definition Builtins.cpp:80
bool isHeaderDependentFunction(unsigned ID) const
Returns true if this builtin requires appropriate header in other compilers.
Definition Builtins.h:328
void initializeBuiltins(IdentifierTable &Table, const LangOptions &LangOpts)
Mark the identifiers for all the builtins with their appropriate builtin ID # and mark any non-portab...
Definition Builtins.cpp:296
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...
Definition Builtins.cpp:384
bool isInStdNamespace(unsigned ID) const
Determines whether this builtin is a C++ standard library function that lives in (possibly-versioned)...
Definition Builtins.h:343
bool canBeRedeclared(unsigned ID) const
Returns true if this is a builtin that can be redeclared.
Definition Builtins.cpp:446
const char * getAttributesString(unsigned ID) const
Get the attributes descriptor string for the specified builtin.
Definition Builtins.cpp:97
bool isConstantEvaluated(unsigned ID) const
Return true if this function can be constant evaluated by Clang frontend.
Definition Builtins.h:460
bool isPredefinedLibFunction(unsigned ID) const
Determines whether this builtin is a predefined libc/libm function, such as "malloc",...
Definition Builtins.h:321
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...
Definition Builtins.cpp:379
const char * getTypeString(unsigned ID) const
Get the type descriptor string for the specified builtin.
Definition Builtins.cpp:92
bool isNoReturn(unsigned ID) const
Return true if we know this builtin never returns.
Definition Builtins.h:293
const char * getRequiredFeatures(unsigned ID) const
Definition Builtins.cpp:102
bool isDirectlyAddressable(unsigned ID) const
Determines whether this builtin can have its address taken with no special action required.
Definition Builtins.h:349
bool isConstWithoutExceptions(unsigned ID) const
Definition Builtins.h:417
bool isPredefinedRuntimeFunction(unsigned ID) const
Determines whether this builtin is a predefined compiler-rt/libgcc function, such as "__clear_cache",...
Definition Builtins.h:335
bool isPure(unsigned ID) const
Return true if this function has no side effects.
Definition Builtins.h:277
bool isNoThrow(unsigned ID) const
Return true if we know this builtin never throws an exception.
Definition Builtins.h:288
void InitializeTarget(const TargetInfo &Target, const TargetInfo *AuxTarget)
Perform target-specific initialization.
Definition Builtins.cpp:109
bool isConst(unsigned ID) const
Return true if this function has no side effects and doesn't read memory.
Definition Builtins.h:283
Implements an efficient mapping from strings to IdentifierInfo nodes.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Exposes information about the current target.
Definition TargetInfo.h:227
bool evaluateRequiredTargetFeatures(llvm::StringRef RequiredFatures, const llvm::StringMap< bool > &TargetFetureMap)
Returns true if the required target features of a builtin function are enabled.
static constexpr std::array< Info, N > MakeInfos(std::array< Info, N > Infos)
A constexpr function to construct an infos array from X-macros.
Definition Builtins.h:115
The JSON file list parser is used to communicate input to InstallAPI.
LanguageID
Definition Builtins.h:34
@ ALL_LANGUAGES
Definition Builtins.h:50
@ MS_LANG
Definition Builtins.h:39
@ CUDA_LANG
Definition Builtins.h:41
@ OMP_LANG
Definition Builtins.h:40
@ CXX_LANG
Definition Builtins.h:37
@ OBJC_LANG
Definition Builtins.h:38
@ OCL_DSE
Definition Builtins.h:45
@ C_LANG
Definition Builtins.h:36
@ C23_LANG
Definition Builtins.h:48
@ ALL_OCL_LANGUAGES
Definition Builtins.h:46
@ HLSL_LANG
Definition Builtins.h:47
@ C2Y_LANG
Definition Builtins.h:49
@ OCL_GAS
Definition Builtins.h:43
@ ALL_GNU_LANGUAGES
Definition Builtins.h:51
@ ALL_MS_LANGUAGES
Definition Builtins.h:52
@ GNU_LANG
Definition Builtins.h:35
@ COR_LANG
Definition Builtins.h:42
@ OCL_PIPE
Definition Builtins.h:44
BuiltinTemplateKind
Kinds of BuiltinTemplateDecl.
Definition Builtins.h:491
llvm::StringTable::Offset Name
Definition Builtins.h:84
llvm::StringTable::Offset Features
Definition Builtins.h:89
llvm::StringTable::Offset Attributes
Definition Builtins.h:86
llvm::StringTable::Offset Type
Definition Builtins.h:85
The info used to represent each builtin.
Definition Builtins.h:80
HeaderDesc Header
Definition Builtins.h:92
LanguageID Langs
Definition Builtins.h:93
struct clang::Builtin::Info::StrOffsets Offsets
std::string getName(const InfosShard &Shard) const
Get the name for the builtin represented by this Info object.
Definition Builtins.cpp:74
A shard of a target's builtins string table and info.
Definition Builtins.h:139
const llvm::StringTable * Strings
Definition Builtins.h:140
llvm::StringLiteral NamePrefix
Definition Builtins.h:143
llvm::ArrayRef< Info > Infos
Definition Builtins.h:141
const char * getName() const
Definition Builtins.cpp:21
constexpr HeaderDesc()
Definition Builtins.h:62
enum clang::HeaderDesc::HeaderID ID
constexpr HeaderDesc(HeaderID ID)
Definition Builtins.h:63