14#ifndef LLVM_CLANG_SEMA_SEMA_H
15#define LLVM_CLANG_SEMA_SEMA_H
60#include "llvm/ADT/ArrayRef.h"
61#include "llvm/ADT/SetVector.h"
62#include "llvm/ADT/SmallBitVector.h"
63#include "llvm/ADT/SmallPtrSet.h"
64#include "llvm/ADT/SmallSet.h"
65#include "llvm/ADT/SmallVector.h"
66#include "llvm/ADT/TinyPtrVector.h"
67#include "llvm/Frontend/OpenMP/OMPConstants.h"
77 template <
typename ValueT,
typename ValueInfoT>
class DenseSet;
79 struct InlineAsmIdentifierInfo;
86 class ASTMutationListener;
96 class CXXBindTemporaryExpr;
98 class CXXConstructorDecl;
99 class CXXConversionDecl;
101 class CXXDestructorDecl;
102 class CXXFieldCollector;
103 class CXXMemberCallExpr;
109 class ClassTemplateDecl;
110 class ClassTemplatePartialSpecializationDecl;
111 class ClassTemplateSpecializationDecl;
112 class VarTemplatePartialSpecializationDecl;
113 class CodeCompleteConsumer;
114 class CodeCompletionAllocator;
115 class CodeCompletionTUInfo;
116 class CodeCompletionResult;
117 class CoroutineBodyStmt;
119 class DeclAccessPair;
122 class DeclaratorDecl;
123 class DeducedTemplateArgument;
124 class DependentDiagnostic;
125 class DesignatedInitExpr;
128 class EnumConstantDecl;
134 class FunctionProtoType;
135 class FunctionTemplateDecl;
136 class ImplicitConversionSequence;
139 class InitializationKind;
140 class InitializationSequence;
141 class InitializedEntity;
142 class IntegerLiteral;
146 class LocalInstantiationScope;
151 class MultiLevelTemplateArgumentList;
153 class ObjCCategoryDecl;
154 class ObjCCategoryImplDecl;
155 class ObjCCompatibleAliasDecl;
156 class ObjCContainerDecl;
158 class ObjCImplementationDecl;
159 class ObjCInterfaceDecl;
161 template <
class T>
class ObjCList;
162 class ObjCMessageExpr;
163 class ObjCMethodDecl;
164 class ObjCPropertyDecl;
165 class ObjCProtocolDecl;
166 class OMPThreadPrivateDecl;
167 class OMPRequiresDecl;
168 class OMPDeclareReductionDecl;
169 class OMPDeclareSimdDecl;
171 struct OMPVarListLocTy;
172 struct OverloadCandidate;
175 class OverloadCandidateSet;
180 class PseudoDestructorTypeStorage;
181 class PseudoObjectExpr;
183 class StandardConversionSequence;
187 class TemplateArgument;
188 class TemplateArgumentList;
189 class TemplateArgumentLoc;
191 class TemplateInstantiationCallback;
192 class TemplateParameterList;
193 class TemplatePartialOrderingContext;
194 class TemplateTemplateParmDecl;
198 class TypedefNameDecl;
200 class TypoCorrectionConsumer;
202 class UnresolvedLookupExpr;
203 class UnresolvedMemberExpr;
204 class UnresolvedSetImpl;
205 class UnresolvedSetIterator;
207 class UsingShadowDecl;
210 class VarTemplateSpecializationDecl;
211 class VisibilityAttr;
212 class VisibleDeclConsumer;
213 class IndirectFieldDecl;
214 struct DeductionFailureInfo;
215 class TemplateSpecCandidateSet;
218 class AccessedEntity;
219 class BlockScopeInfo;
221 class CapturedRegionScopeInfo;
222 class CapturingScopeInfo;
223 class CompoundScopeInfo;
224 class DelayedDiagnostic;
225 class DelayedDiagnosticPool;
226 class FunctionScopeInfo;
227 class LambdaScopeInfo;
228 class PossiblyUnreachableDiag;
229 class RISCVIntrinsicManager;
230 class SemaPPCallbacks;
231 class TemplateDeductionInfo;
234namespace threadSafety {
241typedef std::pair<llvm::PointerUnion<const TemplateTypeParmType *, NamedDecl *>,
267 llvm::DenseMap<FileID, FileNullability> Map;
278 if (file ==
Cache.File)
279 return Cache.Nullability;
282 if (!
Cache.File.isInvalid()) {
288 Cache.Nullability = Map[file];
289 return Cache.Nullability;
317 llvm::function_ref<
QualType()> ComputeType);
335 if (!Enabled || Tok != ExpectedLoc)
340 return ComputeType();
352 llvm::function_ref<
QualType()> ComputeType;
358 void operator=(
const Sema &) =
delete;
363 static bool mightHaveNonExternalLinkage(
const DeclaratorDecl *FD);
368 bool shouldLinkPossiblyHiddenDecl(
const NamedDecl *Old,
376 "should not have found a non-externally-declarable previous decl");
383 void setupImplicitSpecialMemberType(
CXXMethodDecl *SpecialMem,
499 : PackAttr(
true), AlignMode(M), PackNumber(Num), XLStack(IsXL) {
500 assert(Num == PackNumber &&
"The pack number has been truncated.");
505 : PackAttr(
false), AlignMode(M),
506 PackNumber(M ==
Packed ? 1 : UninitPackVal), XLStack(IsXL) {}
516 std::uint32_t Encoding{};
518 Encoding |= IsXLMask;
520 Encoding |=
static_cast<uint32_t
>(Info.
getAlignMode()) << 1;
523 Encoding |= PackAttrMask;
525 Encoding |=
static_cast<uint32_t
>(Info.
getPackNumber()) << 4;
531 bool IsXL =
static_cast<bool>(Encoding & IsXLMask);
534 int PackNumber = (Encoding & PackNumMask) >> 4;
536 if (Encoding & PackAttrMask)
553 return PackNumber != UninitPackVal && PackNumber != 0;
559 return std::tie(AlignMode, PackNumber, PackAttr, XLStack) ==
560 std::tie(Info.AlignMode, Info.PackNumber, Info.PackAttr,
565 return !(*
this == Info);
577 unsigned char PackNumber;
583 static constexpr unsigned char UninitPackVal = -1;
586 static constexpr uint32_t IsXLMask{0x0000'0001};
587 static constexpr uint32_t AlignModeMask{0x0000'0006};
588 static constexpr uint32_t PackAttrMask{0x00000'0008};
589 static constexpr uint32_t PackNumMask{0x0000'01F0};
592 template<
typename ValueType>
607 llvm::StringRef StackSlotLabel, ValueType
Value) {
617 if (!StackSlotLabel.empty()) {
619 auto I = llvm::find_if(llvm::reverse(
Stack), [&](
const Slot &x) {
623 if (I !=
Stack.rend()) {
626 Stack.erase(std::prev(I.base()),
Stack.end());
628 }
else if (!
Stack.empty()) {
657 "Can only push / pop #pragma stack sentinels!");
919 std::unique_ptr<LateParsedTemplate>>
938 class DelayedDiagnostics;
972 state.SavedPool = CurPool;
981 CurPool = state.SavedPool;
988 state.SavedPool = CurPool;
995 assert(CurPool ==
nullptr);
996 CurPool = state.SavedPool;
998 } DelayedDiagnostics;
1007 unsigned SavedFunctionScopesStart;
1008 unsigned SavedInventedParameterInfosStart;
1018 assert(ContextToPush &&
"pushing null context");
1019 S.CurContext = ContextToPush;
1021 S.CXXThisTypeOverride =
QualType();
1023 S.FunctionScopesStart = S.FunctionScopes.size();
1024 S.InventedParameterInfosStart = S.InventedParameterInfos.size();
1028 if (!SavedContext)
return;
1029 S.CurContext = SavedContext;
1030 S.DelayedDiagnostics.popUndelayed(SavedContextState);
1031 S.CXXThisTypeOverride = SavedCXXThisTypeOverride;
1032 S.FunctionScopesStart = SavedFunctionScopesStart;
1033 S.InventedParameterInfosStart = SavedInventedParameterInfosStart;
1034 SavedContext =
nullptr;
1061 bool PushedCodeSynthesisContext =
false;
1065 : S(S), SavedContext(S, DC) {
1066 S.PushFunctionScope();
1067 S.PushExpressionEvaluationContext(
1069 if (
auto *FD = dyn_cast<FunctionDecl>(DC))
1070 FD->setWillHaveBody(
true);
1072 assert(isa<ObjCMethodDecl>(DC));
1076 assert(!PushedCodeSynthesisContext);
1081 Ctx.
Entity = cast<Decl>(S.CurContext);
1082 S.pushCodeSynthesisContext(Ctx);
1084 PushedCodeSynthesisContext =
true;
1088 if (PushedCodeSynthesisContext)
1089 S.popCodeSynthesisContext();
1090 if (
auto *FD = dyn_cast<FunctionDecl>(S.CurContext))
1091 FD->setWillHaveBody(
false);
1092 S.PopExpressionEvaluationContext();
1093 S.PopFunctionScopeInfo();
1109 llvm::SmallDenseSet<WeakInfo, 2u, WeakInfo::DenseMapInfoByAliasOnly>>>
1342 assert(
Decl &&
Context &&
"invalid initialization context");
1409 std::tuple<MangleNumberingContext *, Decl *>
1427 llvm::PointerIntPair<CXXMethodDecl *, 2> Pair;
1442 :
public llvm::FastFoldingSetNode,
1446 : FastFoldingSetNode(ID)
1472 typedef llvm::DenseMap<ParmVarDecl *, llvm::TinyPtrVector<ParmVarDecl *>>
1503 const llvm::MapVector<FieldDecl *, DeleteLocs> &
1508 using Lists = std::pair<ObjCMethodList, ObjCMethodList>;
1509 using iterator = llvm::DenseMap<Selector, Lists>::iterator;
1513 std::pair<iterator, bool>
insert(std::pair<Selector, Lists> &&Val) {
1514 return Methods.insert(Val);
1517 bool empty()
const {
return Methods.empty(); }
1520 llvm::DenseMap<Selector, Lists> Methods;
1551 typedef llvm::PointerIntPair<CXXRecordDecl *, 3, CXXSpecialMember>
1631 std::unique_ptr<sema::RISCVIntrinsicManager> RVIntrinsicManager;
1633 std::optional<std::unique_ptr<DarwinSDKInfo>> CachedDarwinSDKInfo;
1635 bool WarnedDarwinSDKInfoMissing =
false;
1667 StringRef Platform);
1687 llvm::function_ref<
void()> Fn);
1735 template <
typename T>
1746 template <
typename T,
1747 typename = std::enable_if_t<!std::is_lvalue_reference<T>::value>>
1750 BaseDiag << std::move(
V);
1812 template <
typename T>
1815 if (
Diag.ImmediateDiag)
1817 else if (
Diag.PartialDiagId)
1826 template <
typename T,
1827 typename = std::enable_if_t<!std::is_lvalue_reference<T>::value>>
1830 *ImmediateDiag << std::move(
V);
1831 else if (PartialDiagId)
1838 if (
Diag.ImmediateDiag)
1840 else if (
Diag.PartialDiagId)
1847 ImmediateDiag->AddFixItHint(Hint);
1848 else if (PartialDiagId)
1873 std::optional<ImmediateDiagBuilder> ImmediateDiag;
1874 std::optional<unsigned> PartialDiagId;
1883 bool DeferHint =
false);
1887 bool DeferHint =
false);
1898 bool SavedDeferDiags =
false;
1972 unsigned OpenMPCaptureLevel = 0);
1985 std::unique_ptr<sema::FunctionScopeInfo, PoppedFunctionScopeDeleter>;
1989 const Decl *D =
nullptr,
2023 getCurLambda(
bool IgnoreNonLambdaCapturingScope =
false);
2041 unsigned TemplateParameterDepth);
2062 Expr *ArraySize,
unsigned Quals,
2205 template <std::size_t... Is>
2207 std::index_sequence<Is...>)
const {
2209 bool Dummy[] = {
false, (DB << getPrintable(std::get<Is>(
Args)))...};
2216 assert(
DiagID != 0 &&
"no diagnostic for type diagnoser");
2221 emit(DB, std::index_sequence_for<Ts...>());
2240 template <
typename... Ts>
2248 this->
emit(DB, std::index_sequence_for<Ts...>());
2278 void CheckAddressOfNoDeref(
const Expr *E);
2279 void CheckMemberAccessOfNoDeref(
const MemberExpr *E);
2284 struct ModuleScope {
2287 bool ModuleInterface =
false;
2309 clang::Module *TheExportedImplicitGlobalModuleFragment =
nullptr;
2321 bool isCurrentModulePurview()
const {
2326 Module *PushGlobalModuleFragment(SourceLocation BeginLoc);
2328 void PopGlobalModuleFragment();
2331 Module *PushImplicitGlobalModuleFragment(SourceLocation BeginLoc,
2334 void PopImplicitGlobalModuleFragment();
2336 VisibleModuleSet VisibleModules;
2341 bool isUsableModule(
const Module *M);
2348 return ModuleScopes.empty() ? nullptr : ModuleScopes.back().Module;
2353 return ModuleScopes.empty() ?
false : ModuleScopes.back().ModuleInterface;
2358 return ModuleScopes.empty() ?
false
2359 : ModuleScopes.back().Module->isHeaderUnit();
2376 VisibleModules.setVisible(Mod, ImportLoc);
2425 bool OnlyNeedComplete =
false);
2434 bool OnlyNeedComplete =
false);
2442 bool OnlyNeedComplete =
false);
2497 return !RequireCompleteTypeImpl(Loc, T, Kind,
nullptr);
2512 template <
typename... Ts>
2514 const Ts &...Args) {
2519 template <
typename... Ts>
2521 const Ts &... Args) {
2538 TypeDiagnoser &Diagnoser);
2541 template <
typename... Ts>
2547 template <
typename... Ts>
2549 const Ts &... Args) {
2555 TypeDiagnoser &Diagnoser);
2558 template <
typename... Ts>
2560 const Ts &...Args) {
2567 TagDecl *OwnedTagDecl =
nullptr);
2615 bool isClassName =
false,
bool HasTrailingDot =
false,
2617 bool IsCtorOrDtorName =
false,
2618 bool WantNontrivialTypeSourceInfo =
false,
2619 bool IsClassTemplateDeductionContext =
true,
2630 bool IsTemplateName =
false);
2638 bool IsTemplateTypeArg);
2792 llvm_unreachable(
"unsupported name classification.");
2819 const Token &NextToken,
2831 bool IsAddressOfOperand);
2837 const Token &NextToken);
2860 if (
auto *DRE = dyn_cast<DeclRefExpr>(E.
get()))
2861 return !DRE->hasExplicitTemplateArgs();
2862 if (
auto *ME = dyn_cast<MemberExpr>(E.
get()))
2863 return !ME->hasExplicitTemplateArgs();
2865 if (
auto *DSDRE = dyn_cast<DependentScopeDeclRefExpr>(E.
get()))
2866 return !DSDRE->hasExplicitTemplateArgs();
2867 if (
auto *DSME = dyn_cast<CXXDependentScopeMemberExpr>(E.
get()))
2868 return !DSME->hasExplicitTemplateArgs();
2885 unsigned FailedFoldDiagID);
2920 llvm::DenseMap<const NamedDecl *, const NamedDecl *> ShadowingDecls;
2975 bool IsMemberSpecialization,
bool DeclIsDefn);
3044 unsigned NonTrivialKind);
3085 SkipBodyInfo *SkipBody =
nullptr);
3088 SkipBodyInfo *SkipBody =
nullptr,
3091 SkipBodyInfo *SkipBody =
nullptr,
3099 return D && isa<ObjCMethodDecl>(D);
3182 void HandleStartOfHeaderUnit();
3215 bool IsPartition =
false);
3288 bool IsExplicitInstantiation,
3345 bool &OwnedDecl,
bool &IsDependent,
3347 bool ScopedEnumUsesClassTag,
TypeResult UnderlyingType,
3348 bool IsTypeSpecifier,
bool IsTemplateParamOrArg,
3378 Expr *BitfieldWidth,
3386 bool Mutable,
Expr *BitfieldWidth,
3419 : SpecialMember(
CXXInvalid), Comparison(Comp) {}
3436 "invalid should have highest index");
3438 "none should be equal to zero");
3439 return SpecialMember + (
unsigned)Comparison;
3476 template <
typename T,
3477 typename = std::enable_if_t<std::is_base_of<NamedDecl, T>::value>>
3479 if (Duplicate->getODRHash() !=
Previous->getODRHash())
3499 bool IsFinalSpelledSealed,
3530 QualType EnumUnderlyingTy,
bool IsFixed,
3594 bool AllowInlineNamespace =
false)
const;
3653 VersionTuple Introduced, VersionTuple Deprecated,
3654 VersionTuple Obsoleted,
bool IsUnavailable,
3655 StringRef Message,
bool IsStrict, StringRef Replacement,
3657 TypeVisibilityAttr *
3659 TypeVisibilityAttr::VisibilityType Vis);
3661 VisibilityAttr::VisibilityType Vis);
3663 StringRef UuidAsWritten,
MSGuidDecl *GuidDecl);
3671 StringRef NewUserDiagnostic);
3689 const InternalLinkageAttr &AL);
3691 Decl *D,
const WebAssemblyImportNameAttr &AL);
3693 Decl *D,
const WebAssemblyImportModuleAttr &AL);
3696 const EnforceTCBLeafAttr &AL);
3700 int X,
int Y,
int Z);
3702 HLSLShaderAttr::ShaderType ShaderType);
3709 bool MergeTypeWithOld,
bool NewDeclIsDefn);
3711 Scope *S,
bool MergeTypeWithOld);
3751 bool UseMemberUsingDeclRules);
3753 bool UseMemberUsingDeclRules,
bool ConsiderCudaAttrs =
true,
3754 bool ConsiderRequiresClauses =
true);
3765 unsigned TemplateDepth,
3766 const Expr *Constraint);
3779 const Expr *OldConstr,
3781 const Expr *NewConstr);
3794 bool SuppressUserConversions,
3796 bool InOverloadResolution,
3798 bool AllowObjCWritebackConversion);
3804 bool InOverloadResolution,
3805 QualType& ConvertedType,
bool &IncompatibleObjC);
3807 QualType& ConvertedType,
bool &IncompatibleObjC);
3814 unsigned *ArgPos =
nullptr,
3824 bool IgnoreBaseAccess,
3827 bool InOverloadResolution,
3832 bool IgnoreBaseAccess);
3834 bool CStyle,
bool &ObjCLifetimeConversion);
3850 bool TopLevelOfInitList =
false,
3851 bool AllowExplicit =
false);
3931 bool AllowScopedEnumerations;
3937 AllowScopedEnumerations(AllowScopedEnumerations) {}
3993 bool PartialOverloading =
false,
bool AllowExplicit =
true,
3994 bool AllowExplicitConversion =
false,
4002 bool SuppressUserConversions =
false,
4003 bool PartialOverloading =
false,
4004 bool FirstArgumentIsBase =
false);
4010 bool SuppressUserConversion =
false,
4014 CXXRecordDecl *ActingContext, QualType ObjectType,
4015 Expr::Classification ObjectClassification,
4016 ArrayRef<Expr *> Args, OverloadCandidateSet &CandidateSet,
4017 bool SuppressUserConversions =
false,
4018 bool PartialOverloading =
false,
4022 DeclAccessPair FoundDecl,
4023 CXXRecordDecl *ActingContext,
4024 TemplateArgumentListInfo *ExplicitTemplateArgs,
4025 QualType ObjectType,
4026 Expr::Classification ObjectClassification,
4027 ArrayRef<Expr *> Args,
4028 OverloadCandidateSet& CandidateSet,
4029 bool SuppressUserConversions =
false,
4030 bool PartialOverloading =
false,
4034 TemplateArgumentListInfo *ExplicitTemplateArgs, ArrayRef<Expr *> Args,
4035 OverloadCandidateSet &CandidateSet,
bool SuppressUserConversions =
false,
4036 bool PartialOverloading =
false,
bool AllowExplicit =
true,
4041 ArrayRef<Expr *> Args, OverloadCandidateSet &CandidateSet,
4043 CXXRecordDecl *ActingContext =
nullptr, QualType ObjectType = QualType(),
4044 Expr::Classification ObjectClassification = {},
4047 CXXConversionDecl *Conversion, DeclAccessPair FoundDecl,
4048 CXXRecordDecl *ActingContext, Expr *From, QualType ToType,
4049 OverloadCandidateSet &CandidateSet,
bool AllowObjCConversionOnExplicit,
4050 bool AllowExplicit,
bool AllowResultConversion =
true);
4053 CXXRecordDecl *ActingContext, Expr *From, QualType ToType,
4054 OverloadCandidateSet &CandidateSet,
bool AllowObjCConversionOnExplicit,
4055 bool AllowExplicit,
bool AllowResultConversion =
true);
4057 DeclAccessPair FoundDecl,
4058 CXXRecordDecl *ActingContext,
4059 const FunctionProtoType *Proto,
4060 Expr *Object, ArrayRef<Expr *> Args,
4061 OverloadCandidateSet& CandidateSet);
4063 const UnresolvedSetImpl &Functions, ArrayRef<Expr *> Args,
4064 OverloadCandidateSet &CandidateSet,
4065 TemplateArgumentListInfo *ExplicitTemplateArgs =
nullptr);
4067 SourceLocation OpLoc, ArrayRef<Expr *> Args,
4068 OverloadCandidateSet &CandidateSet,
4071 OverloadCandidateSet& CandidateSet,
4072 bool IsAssignmentOperator =
false,
4073 unsigned NumContextualBoolArguments = 0);
4075 SourceLocation OpLoc, ArrayRef<Expr *> Args,
4076 OverloadCandidateSet& CandidateSet);
4079 ArrayRef<Expr *> Args,
4080 TemplateArgumentListInfo *ExplicitTemplateArgs,
4081 OverloadCandidateSet& CandidateSet,
4082 bool PartialOverloading =
false);
4086 const NamedDecl *Found,
const FunctionDecl *Fn,
4088 QualType DestType = QualType(),
bool TakingAddress =
false);
4093 bool TakingAddress =
false);
4097 EnableIfAttr *
CheckEnableIf(FunctionDecl *Function, SourceLocation CallLoc,
4098 ArrayRef<Expr *> Args,
4099 bool MissingImplicitThis =
false);
4113 const Expr *ThisArg,
4114 ArrayRef<const Expr *> Args,
4115 SourceLocation Loc);
4125 SourceLocation Loc);
4132 bool Complain =
false,
4133 SourceLocation Loc = SourceLocation());
4145 QualType TargetType,
4147 DeclAccessPair &Found,
4148 bool *pHadMultipleCandidates =
nullptr);
4154 ExprResult &SrcExpr,
bool DoFunctionPointerConversion =
false);
4157 OverloadExpr *ovl,
bool Complain =
false, DeclAccessPair *Found =
nullptr,
4158 TemplateSpecCandidateSet *FailedTSC =
nullptr);
4161 ExprResult &SrcExpr,
bool DoFunctionPointerConversion =
false,
4162 bool Complain =
false, SourceRange OpRangeForComplaining = SourceRange(),
4163 QualType DestTypeForComplaining = QualType(),
4164 unsigned DiagIDForComplaining = 0);
4167 DeclAccessPair FoundDecl,
4170 DeclAccessPair FoundDecl,
4174 ArrayRef<Expr *> Args,
4175 OverloadCandidateSet &CandidateSet,
4176 bool PartialOverloading =
false);
4178 LookupResult &R, TemplateArgumentListInfo *ExplicitTemplateArgs,
4179 ArrayRef<Expr *> Args, OverloadCandidateSet &CandidateSet);
4202 bool AllowTypoCorrection=
true,
4203 bool CalleesAddressIsTaken=
false);
4214 bool PerformADL =
true);
4219 Expr *input,
bool RequiresADL =
true);
4229 bool RequiresADL =
true,
4230 bool AllowRewrittenCandidates =
true,
4245 Expr *ExecConfig =
nullptr,
4246 bool IsExecConfig =
false,
4247 bool AllowRecovery =
false);
4255 bool *NoArrowOperatorFound =
nullptr);
4265 bool CheckParameterNames);