|
clang 24.0.0git
|
Holds information about both target-independent and target-specific builtins, allowing easy queries by clients. More...
#include "clang/Basic/Builtins.h"
Public Member Functions | |
| Context () | |
| void | InitializeTarget (const TargetInfo &Target, const TargetInfo *AuxTarget) |
| Perform target-specific initialization. | |
| void | initializeBuiltins (IdentifierTable &Table, const LangOptions &LangOpts) |
| Mark the identifiers for all the builtins with their appropriate builtin ID # and mark any non-portable builtin identifiers as such. | |
| std::string | getName (unsigned ID) const |
| Return the identifier name for the specified builtin, e.g. | |
| llvm::SmallString< 64 > | getQuotedName (unsigned ID) const |
| Return the identifier name for the specified builtin inside single quotes for a diagnostic, e.g. | |
| const char * | getTypeString (unsigned ID) const |
| Get the type descriptor string for the specified builtin. | |
| const char * | getAttributesString (unsigned ID) const |
| Get the attributes descriptor string for the specified builtin. | |
| bool | isTSBuiltin (unsigned ID) const |
| Return true if this function is a target-specific builtin. | |
| bool | isPure (unsigned ID) const |
| Return true if this function has no side effects. | |
| bool | isConst (unsigned ID) const |
| Return true if this function has no side effects and doesn't read memory. | |
| bool | isNoThrow (unsigned ID) const |
| Return true if we know this builtin never throws an exception. | |
| bool | isNoReturn (unsigned ID) const |
| Return true if we know this builtin never returns. | |
| bool | isReturnsTwice (unsigned ID) const |
| Return true if we know this builtin can return twice. | |
| bool | isUnevaluated (unsigned ID) const |
| Returns true if this builtin does not perform the side-effects of its arguments. | |
| bool | isLibFunction (unsigned ID) const |
| Return true if this is a builtin for a libc/libm function, with a "__builtin_" prefix (e.g. | |
| bool | isPredefinedLibFunction (unsigned ID) const |
| Determines whether this builtin is a predefined libc/libm function, such as "malloc", where we know the signature a priori. | |
| bool | isHeaderDependentFunction (unsigned ID) const |
| Returns true if this builtin requires appropriate header in other compilers. | |
| bool | isPredefinedRuntimeFunction (unsigned ID) const |
| Determines whether this builtin is a predefined compiler-rt/libgcc function, such as "__clear_cache", where we know the signature a priori. | |
| bool | isInStdNamespace (unsigned ID) const |
| Determines whether this builtin is a C++ standard library function that lives in (possibly-versioned) namespace std, possibly a template specialization, where the signature is determined by the standard library declaration. | |
| bool | isDirectlyAddressable (unsigned ID) const |
| Determines whether this builtin can have its address taken with no special action required. | |
| bool | hasCustomTypechecking (unsigned ID) const |
| Determines whether this builtin has custom typechecking. | |
| bool | allowTypeMismatch (unsigned ID) const |
| Determines whether a declaration of this builtin should be recognized even if the type doesn't match the specified signature. | |
| bool | hasPtrArgsOrResult (unsigned ID) const |
| Determines whether this builtin has a result or any arguments which are pointer types. | |
| bool | hasReferenceArgsOrResult (unsigned ID) const |
| Return true if this builtin has a result or any arguments which are reference types. | |
| const char * | getHeaderName (unsigned ID) const |
| If this is a library function that comes from a specific header, retrieve that header name. | |
| 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 the format string argument and whether this function as a va_list argument. | |
| 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 format string argument and whether this function as a va_list argument. | |
| bool | performsCallback (unsigned ID, llvm::SmallVectorImpl< int > &Encoding) const |
| Determine whether this builtin has callback behavior (see llvm::AbstractCallSites for details). | |
| bool | isNonNull (unsigned ID, llvm::SmallVectorImpl< int > &Indxs, Info::NonNullMode &Mode) const |
| Return true if this builtin has parameters that must be non-null. | |
| bool | isConstWithoutErrnoAndExceptions (unsigned ID) const |
| Return true if this function has no side effects and doesn't read memory, except for possibly errno or raising FP exceptions. | |
| bool | isConstWithoutExceptions (unsigned ID) const |
| 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 side effects such as setting errno. | |
| const char * | getRequiredFeatures (unsigned ID) const |
| unsigned | getRequiredVectorWidth (unsigned ID) const |
| bool | isAuxBuiltinID (unsigned ID) const |
| Return true if the builtin ID belongs exclusively to the AuxTarget, and false if it belongs to both primary and aux target, or neither. | |
| unsigned | getAuxBuiltinID (unsigned ID) const |
| Return real builtin ID (i.e. | |
| bool | canBeRedeclared (unsigned ID) const |
| Returns true if this is a builtin that can be redeclared. | |
| bool | isConstantEvaluated (unsigned ID) const |
| Return true if this function can be constant evaluated by Clang frontend. | |
| bool | isImmediate (unsigned ID) const |
| Returns true if this is an immediate (consteval) function. | |
| bool | isReflectionMetafunctionBuiltin (unsigned ID) const |
| Returns true if this is a reflection metafunction builtin. | |
Static Public Member Functions | |
| static bool | isBuiltinFunc (llvm::StringRef Name) |
| Returns true if this is a libc/libm function without the '__builtin_' prefix. | |
Holds information about both target-independent and target-specific builtins, allowing easy queries by clients.
Builtins from an optional auxiliary target are stored in AuxTSRecords. Their IDs are shifted up by TSRecords.size() and need to be translated back with getAuxBuiltinID() before use.
Definition at line 238 of file Builtins.h.
| Builtin::Context::Context | ( | ) |
Definition at line 123 of file Builtins.cpp.
References BuiltinInfos, and BuiltinStrings.
Determines whether a declaration of this builtin should be recognized even if the type doesn't match the specified signature.
Definition at line 365 of file Builtins.h.
References getAttributesString(), and hasCustomTypechecking().
Returns true if this is a builtin that can be redeclared.
Returns true for non-builtins.
Definition at line 466 of file Builtins.cpp.
References hasCustomTypechecking(), hasReferenceArgsOrResult(), isInStdNamespace(), and clang::Builtin::NotBuiltin.
| const char * Builtin::Context::getAttributesString | ( | unsigned | ID | ) | const |
Get the attributes descriptor string for the specified builtin.
Definition at line 113 of file Builtins.cpp.
Referenced by allowTypeMismatch(), getRequiredVectorWidth(), hasCustomTypechecking(), isConst(), isConstantEvaluated(), isConstWithoutErrnoAndExceptions(), isConstWithoutExceptions(), isHeaderDependentFunction(), isImmediate(), isInStdNamespace(), isLibFunction(), isNonNull(), isNoReturn(), isNoThrow(), isPredefinedLibFunction(), isPredefinedRuntimeFunction(), isPure(), isReturnsTwice(), isUnevaluated(), and performsCallback().
Return real builtin ID (i.e.
ID it would have during compilation for AuxTarget).
Definition at line 451 of file Builtins.h.
Referenced by ConvertBuiltinIDToX86BuiltinID(), clang::SemaAMDGPU::ExpandAMDGPUPredicateBuiltIn(), clang::SemaARM::SmeAliasValid(), and clang::SemaARM::SveAliasValid().
|
inline |
If this is a library function that comes from a specific header, retrieve that header name.
Definition at line 385 of file Builtins.h.
Referenced by emitReplacement(), and getHeaderName().
| std::string Builtin::Context::getName | ( | unsigned | ID | ) | const |
Return the identifier name for the specified builtin, e.g.
"__builtin_abs".
Definition at line 94 of file Builtins.cpp.
Referenced by clang::CodeGen::CodeGenFunction::EmitBuiltinExpr(), clang::CIRGen::CIRGenFunction::emitBuiltinExpr(), emitCommonNeonBuiltinExpr(), emitCommonNeonSISDBuiltinExpr(), emitReplacement(), errorBuiltinNYI(), and clang::ento::CheckerContext::isCLibraryFunction().
| SmallString< 64 > Builtin::Context::getQuotedName | ( | unsigned | ID | ) | const |
Return the identifier name for the specified builtin inside single quotes for a diagnostic, e.g.
"'__builtin_abs'".
Definition at line 99 of file Builtins.cpp.
References clang::Result.
Referenced by BuiltinMaskedGather(), BuiltinMaskedScatter(), BuiltinMaskedStore(), clang::SemaAMDGPU::CheckAMDGCNBuiltinFunctionCall(), clang::interp::diagnoseNonConstexprBuiltin(), clang::interp::interp__builtin_load8(), clang::interp::interp__builtin_memchr(), and clang::interp::interp__builtin_memcmp().
| const char * Builtin::Context::getRequiredFeatures | ( | unsigned | ID | ) | const |
Definition at line 118 of file Builtins.cpp.
Referenced by clang::checkArmStreamingBuiltin(), clang::CodeGenUtils::checkTargetFeatures(), clang::CodeGen::CodeGenFunction::EmitAMDGPUBuiltinExpr(), and clang::SemaAMDGPU::ExpandAMDGPUPredicateBuiltIn().
Definition at line 360 of file Builtins.cpp.
References getAttributesString().
| const char * Builtin::Context::getTypeString | ( | unsigned | ID | ) | const |
Get the type descriptor string for the specified builtin.
Definition at line 108 of file Builtins.cpp.
Referenced by hasPtrArgsOrResult(), and hasReferenceArgsOrResult().
Determines whether this builtin has custom typechecking.
Definition at line 359 of file Builtins.h.
References getAttributesString().
Referenced by allowTypeMismatch(), and canBeRedeclared().
Determines whether this builtin has a result or any arguments which are pointer types.
Definition at line 372 of file Builtins.h.
References getTypeString().
Return true if this builtin has a result or any arguments which are reference types.
Definition at line 378 of file Builtins.h.
References getTypeString().
Referenced by canBeRedeclared().
| void Builtin::Context::initializeBuiltins | ( | IdentifierTable & | Table, |
| const LangOptions & | LangOpts ) |
Mark the identifiers for all the builtins with their appropriate builtin ID # and mark any non-portable builtin identifiers as such.
initializeBuiltins - Mark the identifiers for all the builtins with their appropriate builtin ID # and mark any non-portable builtin identifiers as such.
Definition at line 315 of file Builtins.cpp.
References builtinIsSupported(), clang::IdentifierTable::end(), clang::IdentifierTable::find(), clang::Builtin::FirstTSBuiltin, clang::IdentifierTable::get(), getBuiltinNameInto(), isInStdNamespace(), isPredefinedLibFunction(), clang::LangOptions::NoBuiltinFuncs, clang::Builtin::NotBuiltin, and clang::IdentifierInfo::setBuiltinID().
Referenced by clang::FrontendAction::BeginSourceFile(), and clang::createChainedIncludesSource().
| void Builtin::Context::InitializeTarget | ( | const TargetInfo & | Target, |
| const TargetInfo * | AuxTarget ) |
Perform target-specific initialization.
| AuxTarget | Target info to incorporate builtins from. May be nullptr. |
Definition at line 125 of file Builtins.cpp.
References clang::TargetInfo::getTargetBuiltins(), and clang::Target.
Return true if the builtin ID belongs exclusively to the AuxTarget, and false if it belongs to both primary and aux target, or neither.
Definition at line 445 of file Builtins.h.
References clang::Builtin::FirstTSBuiltin.
Referenced by ConvertBuiltinIDToX86BuiltinID(), and clang::SemaAMDGPU::ExpandAMDGPUPredicateBuiltIn().
|
static |
Returns true if this is a libc/libm function without the '__builtin_' prefix.
Definition at line 139 of file Builtins.cpp.
References BuiltinInfos, and BuiltinStrings.
Referenced by getAllNoBuiltinFuncValues(), and handleNoBuiltinAttr().
Return true if this function has no side effects and doesn't read memory.
Definition at line 285 of file Builtins.h.
References getAttributesString().
Referenced by shouldGenerateFPMathIntrinsic().
Return true if this function can be constant evaluated by Clang frontend.
Definition at line 462 of file Builtins.h.
References getAttributesString().
Return true if this function has no side effects and doesn't read memory, except for possibly errno or raising FP exceptions.
Such functions can be const when the MathErrno lang option and FP exceptions are disabled.
Definition at line 415 of file Builtins.h.
References getAttributesString().
Referenced by shouldGenerateFPMathIntrinsic().
Definition at line 419 of file Builtins.h.
References getAttributesString().
Referenced by shouldGenerateFPMathIntrinsic().
Determines whether this builtin can have its address taken with no special action required.
Definition at line 351 of file Builtins.h.
References isInStdNamespace(), and isPredefinedLibFunction().
Returns true if this builtin requires appropriate header in other compilers.
In Clang it will work even without including it, but we can emit a warning about missing header.
Definition at line 330 of file Builtins.h.
References getAttributesString().
Returns true if this is an immediate (consteval) function.
Definition at line 467 of file Builtins.h.
References getAttributesString().
Determines whether this builtin is a C++ standard library function that lives in (possibly-versioned) namespace std, possibly a template specialization, where the signature is determined by the standard library declaration.
Definition at line 345 of file Builtins.h.
References getAttributesString().
Referenced by canBeRedeclared(), initializeBuiltins(), and isDirectlyAddressable().
Return true if this is a builtin for a libc/libm function, with a "__builtin_" prefix (e.g.
__builtin_abs).
Definition at line 312 of file Builtins.h.
References getAttributesString().
Referenced by errorBuiltinNYI().
| bool Builtin::Context::isNonNull | ( | unsigned | ID, |
| llvm::SmallVectorImpl< int > & | Indxs, | ||
| Info::NonNullMode & | Mode ) const |
Return true if this builtin has parameters that must be non-null.
The parameter indices are appended into 'Indxs'.
Definition at line 429 of file Builtins.cpp.
References getAttributesString(), clang::Builtin::Info::NonOptimizing, clang::Builtin::Info::Optimizing, and parseCommaSeparatedIndices().
Return true if we know this builtin never returns.
Definition at line 295 of file Builtins.h.
References getAttributesString().
Return true if we know this builtin never throws an exception.
Definition at line 290 of file Builtins.h.
References getAttributesString().
Determines whether this builtin is a predefined libc/libm function, such as "malloc", where we know the signature a priori.
In C, such functions behave as if they are predeclared, possibly with a warning on first use. In Objective-C and C++, they do not, but they are recognized as builtins once we see a declaration.
Definition at line 323 of file Builtins.h.
References getAttributesString().
Referenced by EmitDirectCallee(), initializeBuiltins(), and isDirectlyAddressable().
Determines whether this builtin is a predefined compiler-rt/libgcc function, such as "__clear_cache", where we know the signature a priori.
Definition at line 337 of file Builtins.h.
References getAttributesString().
Determine whether this builtin is like printf in its formatting rules and, if so, set the index to the format string argument and whether this function as a va_list argument.
Definition at line 399 of file Builtins.cpp.
Return true if this function has no side effects.
Definition at line 279 of file Builtins.h.
References getAttributesString().
Returns true if this is a reflection metafunction builtin.
Definition at line 472 of file Builtins.h.
References clang::REFLECTION_LANG.
Return true if we know this builtin can return twice.
Definition at line 300 of file Builtins.h.
References getAttributesString().
Determine whether this builtin is like scanf in its formatting rules and, if so, set the index to the format string argument and whether this function as a va_list argument.
Definition at line 404 of file Builtins.cpp.
Return true if this function is a target-specific builtin.
Definition at line 274 of file Builtins.h.
References clang::Builtin::FirstTSBuiltin.
Returns true if this builtin does not perform the side-effects of its arguments.
Definition at line 306 of file Builtins.h.
References getAttributesString().
Referenced by clang::CallExpr::isUnevaluatedBuiltinCall().
| bool Builtin::Context::performsCallback | ( | unsigned | ID, |
| llvm::SmallVectorImpl< int > & | Encoding ) const |
Determine whether this builtin has callback behavior (see llvm::AbstractCallSites for details).
If so, add the index to the callback callee argument and the callback payload arguments.
Definition at line 454 of file Builtins.cpp.
References getAttributesString(), and parseCommaSeparatedIndices().
| bool Builtin::Context::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 side effects such as setting errno.
| BuiltinID | The builtin ID to check. |
| Trip | The target triple. |
| ErrnoOverwritten | Indicates whether the errno setting behavior has been overwritten via '#pragma float_control(precise, on/off)'. |
| MathErrnoEnabled | Indicates whether math-errno is enabled on command line. |
| HasOptNoneAttr | True iff 'attribute__((optnone))' is used. |
| IsOptimizationEnabled | True iff the optimization level is not 'O0'. |
Definition at line 247 of file Builtins.cpp.
References isBuiltinConstForTriple(), isConst(), isConstWithoutErrnoAndExceptions(), and isConstWithoutExceptions().
Referenced by clang::CodeGen::CodeGenFunction::EmitBuiltinExpr(), and shouldCIREmitFPMathIntrinsic().