clang 19.0.0git
Public Member Functions | Static Public Member Functions | List of all members
clang::Builtin::Context Class Reference

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 ()=default
 
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.
 
llvm::StringRef getName (unsigned ID) const
 Return the identifier name for the specified builtin, e.g.
 
const char * getTypeString (unsigned ID) const
 Get the type 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 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
 
const char * getRequiredFeatures (unsigned ID) const
 
unsigned getRequiredVectorWidth (unsigned ID) const
 
bool isAuxBuiltinID (unsigned ID) const
 Return true if builtin ID belongs to AuxTarget.
 
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.
 

Static Public Member Functions

static bool isBuiltinFunc (llvm::StringRef Name)
 Returns true if this is a libc/libm function without the '__builtin_' prefix.
 

Detailed Description

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 85 of file Builtins.h.

Constructor & Destructor Documentation

◆ Context()

clang::Builtin::Context::Context ( )
default

Member Function Documentation

◆ allowTypeMismatch()

bool clang::Builtin::Context::allowTypeMismatch ( unsigned  ID) const
inline

Determines whether a declaration of this builtin should be recognized even if the type doesn't match the specified signature.

Definition at line 202 of file Builtins.h.

References hasCustomTypechecking().

Referenced by clang::Sema::ActOnFunctionDeclarator(), and clang::Sema::LazilyCreateBuiltin().

◆ canBeRedeclared()

bool Builtin::Context::canBeRedeclared ( unsigned  ID) const

Returns true if this is a builtin that can be redeclared.

Returns true for non-builtins.

Definition at line 236 of file Builtins.cpp.

References clang::Builtin::NotBuiltin.

Referenced by clang::ASTContext::canBuiltinBeRedeclared().

◆ getAuxBuiltinID()

unsigned clang::Builtin::Context::getAuxBuiltinID ( unsigned  ID) const
inline

Return real builtin ID (i.e.

ID it would have during compilation for AuxTarget).

Definition at line 268 of file Builtins.h.

Referenced by ArmSmeAliasValid(), and ArmSveAliasValid().

◆ getHeaderName()

const char * clang::Builtin::Context::getHeaderName ( unsigned  ID) const
inline

If this is a library function that comes from a specific header, retrieve that header name.

Definition at line 222 of file Builtins.h.

References clang::HeaderDesc::getName(), and clang::Builtin::Info::Header.

Referenced by emitReplacement(), and clang::Sema::LazilyCreateBuiltin().

◆ getName()

llvm::StringRef clang::Builtin::Context::getName ( unsigned  ID) const
inline

◆ getRequiredFeatures()

const char * clang::Builtin::Context::getRequiredFeatures ( unsigned  ID) const
inline

Definition at line 255 of file Builtins.h.

References clang::Builtin::Info::Features.

◆ getRequiredVectorWidth()

unsigned Builtin::Context::getRequiredVectorWidth ( unsigned  ID) const

Definition at line 160 of file Builtins.cpp.

◆ getTypeString()

const char * clang::Builtin::Context::getTypeString ( unsigned  ID) const
inline

Get the type descriptor string for the specified builtin.

Definition at line 106 of file Builtins.h.

References clang::Builtin::Info::Type.

Referenced by clang::ASTContext::GetBuiltinType().

◆ hasCustomTypechecking()

bool clang::Builtin::Context::hasCustomTypechecking ( unsigned  ID) const
inline

Determines whether this builtin has custom typechecking.

Definition at line 196 of file Builtins.h.

Referenced by allowTypeMismatch(), clang::Sema::BuildResolvedCallExpr(), clang::ASTContext::canBuiltinBeRedeclared(), and clang::Sema::ConvertArgumentsForCall().

◆ hasPtrArgsOrResult()

bool clang::Builtin::Context::hasPtrArgsOrResult ( unsigned  ID) const
inline

Determines whether this builtin has a result or any arguments which are pointer types.

Definition at line 209 of file Builtins.h.

Referenced by rewriteBuiltinFunctionDecl().

◆ hasReferenceArgsOrResult()

bool clang::Builtin::Context::hasReferenceArgsOrResult ( unsigned  ID) const
inline

Return true if this builtin has a result or any arguments which are reference types.

Definition at line 215 of file Builtins.h.

◆ initializeBuiltins()

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 128 of file Builtins.cpp.

References BuiltinInfo, builtinIsSupported(), clang::IdentifierTable::end(), clang::IdentifierTable::find(), clang::Builtin::FirstTSBuiltin, clang::IdentifierTable::get(), clang::LangOptions::NoBuiltinFuncs, clang::Builtin::NotBuiltin, and clang::IdentifierInfo::setBuiltinID().

Referenced by clang::FrontendAction::BeginSourceFile(), and clang::createChainedIncludesSource().

◆ InitializeTarget()

void Builtin::Context::InitializeTarget ( const TargetInfo Target,
const TargetInfo AuxTarget 
)

Perform target-specific initialization.

Parameters
AuxTargetTarget info to incorporate builtins from. May be nullptr.

Definition at line 55 of file Builtins.cpp.

References clang::TargetInfo::getTargetBuiltins().

◆ isAuxBuiltinID()

bool clang::Builtin::Context::isAuxBuiltinID ( unsigned  ID) const
inline

Return true if builtin ID belongs to AuxTarget.

Definition at line 262 of file Builtins.h.

References clang::Builtin::FirstTSBuiltin.

Referenced by clang::Sema::AddKnownFunctionAttributes(), ArmSmeAliasValid(), and ArmSveAliasValid().

◆ isBuiltinFunc()

bool Builtin::Context::isBuiltinFunc ( llvm::StringRef  Name)
static

Returns true if this is a libc/libm function without the '__builtin_' prefix.

Definition at line 63 of file Builtins.cpp.

References BuiltinInfo, clang::Builtin::FirstTSBuiltin, clang::Builtin::Info::Name, and clang::Builtin::NotBuiltin.

Referenced by getAllNoBuiltinFuncValues(), and handleNoBuiltinAttr().

◆ isConst()

bool clang::Builtin::Context::isConst ( unsigned  ID) const
inline

Return true if this function has no side effects and doesn't read memory.

Definition at line 122 of file Builtins.h.

Referenced by clang::Sema::AddKnownFunctionAttributes().

◆ isConstantEvaluated()

bool clang::Builtin::Context::isConstantEvaluated ( unsigned  ID) const
inline

Return true if this function can be constant evaluated by Clang frontend.

Definition at line 279 of file Builtins.h.

◆ isConstWithoutErrnoAndExceptions()

bool clang::Builtin::Context::isConstWithoutErrnoAndExceptions ( unsigned  ID) const
inline

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 247 of file Builtins.h.

Referenced by clang::Sema::AddKnownFunctionAttributes().

◆ isConstWithoutExceptions()

bool clang::Builtin::Context::isConstWithoutExceptions ( unsigned  ID) const
inline

Definition at line 251 of file Builtins.h.

Referenced by clang::Sema::AddKnownFunctionAttributes().

◆ isDirectlyAddressable()

bool clang::Builtin::Context::isDirectlyAddressable ( unsigned  ID) const
inline

Determines whether this builtin can have its address taken with no special action required.

Definition at line 188 of file Builtins.h.

References isInStdNamespace(), and isPredefinedLibFunction().

Referenced by clang::Sema::BuildDeclarationNameExpr(), and clang::Sema::FixOverloadedFunctionReference().

◆ isHeaderDependentFunction()

bool clang::Builtin::Context::isHeaderDependentFunction ( unsigned  ID) const
inline

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 167 of file Builtins.h.

Referenced by clang::Sema::LazilyCreateBuiltin().

◆ isInStdNamespace()

bool clang::Builtin::Context::isInStdNamespace ( unsigned  ID) const
inline

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 182 of file Builtins.h.

Referenced by clang::Sema::ActOnFunctionDeclarator(), clang::Sema::CheckPlaceholderExpr(), and isDirectlyAddressable().

◆ isLibFunction()

bool clang::Builtin::Context::isLibFunction ( unsigned  ID) const
inline

Return true if this is a builtin for a libc/libm function, with a "__builtin_" prefix (e.g.

__builtin_abs).

Definition at line 149 of file Builtins.h.

Referenced by clang::CodeGen::CodeGenModule::getBuiltinLibFunction().

◆ isNoReturn()

bool clang::Builtin::Context::isNoReturn ( unsigned  ID) const
inline

Return true if we know this builtin never returns.

Definition at line 132 of file Builtins.h.

Referenced by clang::ASTContext::GetBuiltinType().

◆ isNoThrow()

bool clang::Builtin::Context::isNoThrow ( unsigned  ID) const
inline

Return true if we know this builtin never throws an exception.

Definition at line 127 of file Builtins.h.

Referenced by clang::Sema::AddKnownFunctionAttributes(), and clang::ASTContext::GetBuiltinType().

◆ isPredefinedLibFunction()

bool clang::Builtin::Context::isPredefinedLibFunction ( unsigned  ID) const
inline

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 160 of file Builtins.h.

Referenced by clang::Sema::ActOnStartOfFunctionDef(), EmitDirectCallee(), clang::FunctionDecl::getBuiltinID(), isDirectlyAddressable(), clang::Sema::LazilyCreateBuiltin(), clang::Sema::LookupBuiltin(), and clang::Sema::MergeFunctionDecl().

◆ isPredefinedRuntimeFunction()

bool clang::Builtin::Context::isPredefinedRuntimeFunction ( unsigned  ID) const
inline

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 174 of file Builtins.h.

Referenced by clang::Sema::ActOnStartOfFunctionDef().

◆ isPrintfLike()

bool Builtin::Context::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.

Definition at line 199 of file Builtins.cpp.

Referenced by clang::Sema::AddKnownFunctionAttributes().

◆ isPure()

bool clang::Builtin::Context::isPure ( unsigned  ID) const
inline

Return true if this function has no side effects.

Definition at line 116 of file Builtins.h.

Referenced by clang::Sema::AddKnownFunctionAttributes().

◆ isReturnsTwice()

bool clang::Builtin::Context::isReturnsTwice ( unsigned  ID) const
inline

Return true if we know this builtin can return twice.

Definition at line 137 of file Builtins.h.

Referenced by clang::Sema::AddKnownFunctionAttributes().

◆ isScanfLike()

bool Builtin::Context::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.

Definition at line 204 of file Builtins.cpp.

Referenced by clang::Sema::AddKnownFunctionAttributes().

◆ isTSBuiltin()

bool clang::Builtin::Context::isTSBuiltin ( unsigned  ID) const
inline

Return true if this function is a target-specific builtin.

Definition at line 111 of file Builtins.h.

References clang::Builtin::FirstTSBuiltin.

Referenced by clang::Sema::AddKnownFunctionAttributes().

◆ isUnevaluated()

bool clang::Builtin::Context::isUnevaluated ( unsigned  ID) const
inline

Returns true if this builtin does not perform the side-effects of its arguments.

Definition at line 143 of file Builtins.h.

Referenced by clang::CallExpr::isUnevaluatedBuiltinCall().

◆ performsCallback()

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 209 of file Builtins.cpp.

Referenced by clang::Sema::AddKnownFunctionAttributes().


The documentation for this class was generated from the following files: