clang 22.0.0git
SemaTemplateInstantiateDecl.cpp File Reference
#include "TreeTransform.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/ASTMutationListener.h"
#include "clang/AST/DeclTemplate.h"
#include "clang/AST/DependentDiagnostic.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ExprCXX.h"
#include "clang/AST/PrettyDeclStackTrace.h"
#include "clang/AST/TypeLoc.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Sema/EnterExpressionEvaluationContext.h"
#include "clang/Sema/Initialization.h"
#include "clang/Sema/Lookup.h"
#include "clang/Sema/ScopeInfo.h"
#include "clang/Sema/SemaAMDGPU.h"
#include "clang/Sema/SemaCUDA.h"
#include "clang/Sema/SemaHLSL.h"
#include "clang/Sema/SemaObjC.h"
#include "clang/Sema/SemaOpenMP.h"
#include "clang/Sema/SemaSwift.h"
#include "clang/Sema/Template.h"
#include "clang/Sema/TemplateInstCallback.h"
#include "llvm/Support/TimeProfiler.h"
#include <optional>
#include "clang/Sema/AttrTemplateInstantiate.inc"
#include "clang/Basic/OpenACCClauses.def"

Go to the source code of this file.

Macros

#define VISIT_CLAUSE(CLAUSE_NAME)
#define CLAUSE_NOT_ON_DECLS(CLAUSE_NAME)

Functions

static bool isDeclWithinFunction (const Decl *D)
template<typename DeclT>
static bool SubstQualifier (Sema &SemaRef, const DeclT *OldDecl, DeclT *NewDecl, const MultiLevelTemplateArgumentList &TemplateArgs)
static void instantiateDependentAlignedAttr (Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, const AlignedAttr *Aligned, Decl *New, bool IsPackExpansion)
static void instantiateDependentAlignedAttr (Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, const AlignedAttr *Aligned, Decl *New)
static void instantiateDependentAssumeAlignedAttr (Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, const AssumeAlignedAttr *Aligned, Decl *New)
static void instantiateDependentAlignValueAttr (Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, const AlignValueAttr *Aligned, Decl *New)
static void instantiateDependentAllocAlignAttr (Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, const AllocAlignAttr *Align, Decl *New)
static void instantiateDependentAnnotationAttr (Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, const AnnotateAttr *Attr, Decl *New)
template<typename Attr>
static void sharedInstantiateConstructorDestructorAttr (Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, const Attr *A, Decl *New, ASTContext &C)
static ExprinstantiateDependentFunctionAttrCondition (Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, const Attr *A, Expr *OldCond, const Decl *Tmpl, FunctionDecl *New)
static void instantiateDependentEnableIfAttr (Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, const EnableIfAttr *EIA, const Decl *Tmpl, FunctionDecl *New)
static void instantiateDependentDiagnoseIfAttr (Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, const DiagnoseIfAttr *DIA, const Decl *Tmpl, FunctionDecl *New)
static void instantiateDependentCUDALaunchBoundsAttr (Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, const CUDALaunchBoundsAttr &Attr, Decl *New)
static void instantiateDependentModeAttr (Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, const ModeAttr &Attr, Decl *New)
static void instantiateOMPDeclareSimdDeclAttr (Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, const OMPDeclareSimdDeclAttr &Attr, Decl *New)
 Instantiation of 'declare simd' attribute and its arguments.
static void instantiateOMPDeclareVariantAttr (Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, const OMPDeclareVariantAttr &Attr, Decl *New)
 Instantiation of 'declare variant' attribute and its arguments.
static void instantiateDependentAMDGPUFlatWorkGroupSizeAttr (Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, const AMDGPUFlatWorkGroupSizeAttr &Attr, Decl *New)
static void instantiateDependentReqdWorkGroupSizeAttr (Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, const ReqdWorkGroupSizeAttr &Attr, Decl *New)
static void instantiateDependentAMDGPUWavesPerEUAttr (Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, const AMDGPUWavesPerEUAttr &Attr, Decl *New)
static void instantiateDependentAMDGPUMaxNumWorkGroupsAttr (Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, const AMDGPUMaxNumWorkGroupsAttr &Attr, Decl *New)
static void instantiateDependentDeviceKernelAttr (Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, const DeviceKernelAttr &Attr, Decl *New)
static bool isRelevantAttr (Sema &S, const Decl *D, const Attr *A)
 Determine whether the attribute A might be relevant to the declaration D.
static void instantiateDependentHLSLParamModifierAttr (Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, const HLSLParamModifierAttr *Attr, Decl *New)
static Sema::RetainOwnershipKind attrToRetainOwnershipKind (const Attr *A)
static void instantiateDependentOpenACCRoutineDeclAttr (Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, const OpenACCRoutineDeclAttr *OldAttr, const Decl *Old, Decl *New)
template<typename DeclT>
static DeclT * getPreviousDeclForInstantiation (DeclT *D)
 Get the previous declaration of a declaration for the purposes of template instantiation.
static QualType adjustFunctionTypeForInstantiation (ASTContext &Context, FunctionDecl *D, TypeSourceInfo *TInfo)
 Adjust the given function type for an instantiation of the given declaration, to cope with modifications to the function's type that aren't reflected in the type-source information.
static void collectUnexpandedParameterPacks (Sema &S, TemplateParameterList *Params, SmallVectorImpl< UnexpandedParameterPack > &Unexpanded)
static bool isInstantiationOf (ClassTemplateDecl *Pattern, ClassTemplateDecl *Instance)
static bool isInstantiationOf (FunctionTemplateDecl *Pattern, FunctionTemplateDecl *Instance)
static bool isInstantiationOf (ClassTemplatePartialSpecializationDecl *Pattern, ClassTemplatePartialSpecializationDecl *Instance)
static bool isInstantiationOf (CXXRecordDecl *Pattern, CXXRecordDecl *Instance)
static bool isInstantiationOf (FunctionDecl *Pattern, FunctionDecl *Instance)
static bool isInstantiationOf (EnumDecl *Pattern, EnumDecl *Instance)
static bool isInstantiationOf (UsingShadowDecl *Pattern, UsingShadowDecl *Instance, ASTContext &C)
static bool isInstantiationOf (UsingDecl *Pattern, UsingDecl *Instance, ASTContext &C)
template<typename T>
static bool isInstantiationOfUnresolvedUsingDecl (T *Pattern, Decl *Other, ASTContext &Ctx)
static bool isInstantiationOfStaticDataMember (VarDecl *Pattern, VarDecl *Instance)
static bool isInstantiationOf (ASTContext &Ctx, NamedDecl *D, Decl *Other)
template<typename ForwardIterator>
static NamedDeclfindInstantiationOf (ASTContext &Ctx, NamedDecl *D, ForwardIterator first, ForwardIterator last)
static bool isDependentContextAtLevel (DeclContext *DC, unsigned Level)
 Determine whether the given context is dependent on template parameters at level Level or below.

Macro Definition Documentation

◆ CLAUSE_NOT_ON_DECLS

#define CLAUSE_NOT_ON_DECLS ( CLAUSE_NAME)
Value:
void OpenACCDeclClauseInstantiator::Visit##CLAUSE_NAME##Clause( \
const OpenACC##CLAUSE_NAME##Clause &) { \
llvm_unreachable("Clause type invalid on declaration construct, or " \
"instantiation not implemented"); \
}

Definition at line 1144 of file SemaTemplateInstantiateDecl.cpp.

◆ VISIT_CLAUSE

#define VISIT_CLAUSE ( CLAUSE_NAME)
Value:
void Visit##CLAUSE_NAME##Clause(const OpenACC##CLAUSE_NAME##Clause &Clause);

Definition at line 1122 of file SemaTemplateInstantiateDecl.cpp.

Function Documentation

◆ adjustFunctionTypeForInstantiation()

QualType adjustFunctionTypeForInstantiation ( ASTContext & Context,
FunctionDecl * D,
TypeSourceInfo * TInfo )
static

Adjust the given function type for an instantiation of the given declaration, to cope with modifications to the function's type that aren't reflected in the type-source information.

Parameters
DThe declaration we're instantiating.
TInfoThe already-instantiated type.

Definition at line 2633 of file SemaTemplateInstantiateDecl.cpp.

References clang::Type::castAs(), clang::FunctionProtoType::ExtProtoInfo::ExtInfo, clang::FunctionType::getExtInfo(), clang::TypeSourceInfo::getType(), and clang::ValueDecl::getType().

Referenced by clang::TemplateDeclInstantiator::VisitCXXMethodDecl(), and clang::TemplateDeclInstantiator::VisitFunctionDecl().

◆ attrToRetainOwnershipKind()

Sema::RetainOwnershipKind attrToRetainOwnershipKind ( const Attr * A)
static

◆ collectUnexpandedParameterPacks()

◆ findInstantiationOf()

template<typename ForwardIterator>
NamedDecl * findInstantiationOf ( ASTContext & Ctx,
NamedDecl * D,
ForwardIterator first,
ForwardIterator last )
static

◆ getPreviousDeclForInstantiation()

template<typename DeclT>
DeclT * getPreviousDeclForInstantiation ( DeclT * D)
static

Get the previous declaration of a declaration for the purposes of template instantiation.

If this finds a previous declaration, then the previous declaration of the instantiation of D should be an instantiation of the result of this function.

Definition at line 1034 of file SemaTemplateInstantiateDecl.cpp.

References clang::isa().

Referenced by clang::TemplateDeclInstantiator::InstantiateTypeAliasTemplateDecl(), clang::TemplateDeclInstantiator::InstantiateTypedefNameDecl(), and clang::TemplateDeclInstantiator::VisitBaseUsingDecls().

◆ instantiateDependentAlignedAttr() [1/2]

void instantiateDependentAlignedAttr ( Sema & S,
const MultiLevelTemplateArgumentList & TemplateArgs,
const AlignedAttr * Aligned,
Decl * New )
static

◆ instantiateDependentAlignedAttr() [2/2]

void instantiateDependentAlignedAttr ( Sema & S,
const MultiLevelTemplateArgumentList & TemplateArgs,
const AlignedAttr * Aligned,
Decl * New,
bool IsPackExpansion )
static

◆ instantiateDependentAlignValueAttr()

void instantiateDependentAlignValueAttr ( Sema & S,
const MultiLevelTemplateArgumentList & TemplateArgs,
const AlignValueAttr * Aligned,
Decl * New )
static

◆ instantiateDependentAllocAlignAttr()

void instantiateDependentAllocAlignAttr ( Sema & S,
const MultiLevelTemplateArgumentList & TemplateArgs,
const AllocAlignAttr * Align,
Decl * New )
static

◆ instantiateDependentAMDGPUFlatWorkGroupSizeAttr()

void instantiateDependentAMDGPUFlatWorkGroupSizeAttr ( Sema & S,
const MultiLevelTemplateArgumentList & TemplateArgs,
const AMDGPUFlatWorkGroupSizeAttr & Attr,
Decl * New )
static

◆ instantiateDependentAMDGPUMaxNumWorkGroupsAttr()

◆ instantiateDependentAMDGPUWavesPerEUAttr()

void instantiateDependentAMDGPUWavesPerEUAttr ( Sema & S,
const MultiLevelTemplateArgumentList & TemplateArgs,
const AMDGPUWavesPerEUAttr & Attr,
Decl * New )
static

◆ instantiateDependentAnnotationAttr()

◆ instantiateDependentAssumeAlignedAttr()

void instantiateDependentAssumeAlignedAttr ( Sema & S,
const MultiLevelTemplateArgumentList & TemplateArgs,
const AssumeAlignedAttr * Aligned,
Decl * New )
static

◆ instantiateDependentCUDALaunchBoundsAttr()

void instantiateDependentCUDALaunchBoundsAttr ( Sema & S,
const MultiLevelTemplateArgumentList & TemplateArgs,
const CUDALaunchBoundsAttr & Attr,
Decl * New )
static

◆ instantiateDependentDeviceKernelAttr()

void instantiateDependentDeviceKernelAttr ( Sema & S,
const MultiLevelTemplateArgumentList & TemplateArgs,
const DeviceKernelAttr & Attr,
Decl * New )
static

◆ instantiateDependentDiagnoseIfAttr()

void instantiateDependentDiagnoseIfAttr ( Sema & S,
const MultiLevelTemplateArgumentList & TemplateArgs,
const DiagnoseIfAttr * DIA,
const Decl * Tmpl,
FunctionDecl * New )
static

◆ instantiateDependentEnableIfAttr()

void instantiateDependentEnableIfAttr ( Sema & S,
const MultiLevelTemplateArgumentList & TemplateArgs,
const EnableIfAttr * EIA,
const Decl * Tmpl,
FunctionDecl * New )
static

◆ instantiateDependentFunctionAttrCondition()

◆ instantiateDependentHLSLParamModifierAttr()

void instantiateDependentHLSLParamModifierAttr ( Sema & S,
const MultiLevelTemplateArgumentList & TemplateArgs,
const HLSLParamModifierAttr * Attr,
Decl * New )
static

◆ instantiateDependentModeAttr()

void instantiateDependentModeAttr ( Sema & S,
const MultiLevelTemplateArgumentList & TemplateArgs,
const ModeAttr & Attr,
Decl * New )
static

Definition at line 352 of file SemaTemplateInstantiateDecl.cpp.

References clang::Sema::AddModeAttr(), and New.

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

◆ instantiateDependentOpenACCRoutineDeclAttr()

void instantiateDependentOpenACCRoutineDeclAttr ( Sema & S,
const MultiLevelTemplateArgumentList & TemplateArgs,
const OpenACCRoutineDeclAttr * OldAttr,
const Decl * Old,
Decl * New )
static

◆ instantiateDependentReqdWorkGroupSizeAttr()

void instantiateDependentReqdWorkGroupSizeAttr ( Sema & S,
const MultiLevelTemplateArgumentList & TemplateArgs,
const ReqdWorkGroupSizeAttr & Attr,
Decl * New )
static

◆ instantiateOMPDeclareSimdDeclAttr()

◆ instantiateOMPDeclareVariantAttr()

◆ isDeclWithinFunction()

◆ isDependentContextAtLevel()

bool isDependentContextAtLevel ( DeclContext * DC,
unsigned Level )
static

Determine whether the given context is dependent on template parameters at level Level or below.

Sometimes we only substitute an inner set of template arguments and leave the outer templates alone. In such cases, contexts dependent only on the outer levels are not effectively dependent.

Definition at line 6801 of file SemaTemplateInstantiateDecl.cpp.

References clang::cast(), and clang::DeclContext::isDependentContext().

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

◆ isInstantiationOf() [1/9]

◆ isInstantiationOf() [2/9]

◆ isInstantiationOf() [3/9]

◆ isInstantiationOf() [4/9]

bool isInstantiationOf ( CXXRecordDecl * Pattern,
CXXRecordDecl * Instance )
static

◆ isInstantiationOf() [5/9]

bool isInstantiationOf ( EnumDecl * Pattern,
EnumDecl * Instance )
static

◆ isInstantiationOf() [6/9]

bool isInstantiationOf ( FunctionDecl * Pattern,
FunctionDecl * Instance )
static

◆ isInstantiationOf() [7/9]

bool isInstantiationOf ( FunctionTemplateDecl * Pattern,
FunctionTemplateDecl * Instance )
static

◆ isInstantiationOf() [8/9]

bool isInstantiationOf ( UsingDecl * Pattern,
UsingDecl * Instance,
ASTContext & C )
static

Definition at line 6674 of file SemaTemplateInstantiateDecl.cpp.

References clang::C, and clang::declaresSameEntity().

◆ isInstantiationOf() [9/9]

bool isInstantiationOf ( UsingShadowDecl * Pattern,
UsingShadowDecl * Instance,
ASTContext & C )
static

Definition at line 6667 of file SemaTemplateInstantiateDecl.cpp.

References clang::C, and clang::declaresSameEntity().

◆ isInstantiationOfStaticDataMember()

bool isInstantiationOfStaticDataMember ( VarDecl * Pattern,
VarDecl * Instance )
static

Definition at line 6706 of file SemaTemplateInstantiateDecl.cpp.

References clang::VarDecl::getCanonicalDecl().

Referenced by isInstantiationOf().

◆ isInstantiationOfUnresolvedUsingDecl()

template<typename T>
bool isInstantiationOfUnresolvedUsingDecl ( T * Pattern,
Decl * Other,
ASTContext & Ctx )
static

◆ isRelevantAttr()

◆ sharedInstantiateConstructorDestructorAttr()

template<typename Attr>
void sharedInstantiateConstructorDestructorAttr ( Sema & S,
const MultiLevelTemplateArgumentList & TemplateArgs,
const Attr * A,
Decl * New,
ASTContext & C )
static

◆ SubstQualifier()

template<typename DeclT>
bool SubstQualifier ( Sema & SemaRef,
const DeclT * OldDecl,
DeclT * NewDecl,
const MultiLevelTemplateArgumentList & TemplateArgs )
static