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