14#ifndef LLVM_CLANG_SEMA_SEMA_H
15#define LLVM_CLANG_SEMA_SEMA_H
68#include "llvm/ADT/APInt.h"
69#include "llvm/ADT/ArrayRef.h"
70#include "llvm/ADT/BitmaskEnum.h"
71#include "llvm/ADT/DenseMap.h"
72#include "llvm/ADT/DenseSet.h"
73#include "llvm/ADT/FloatingPointMode.h"
74#include "llvm/ADT/FoldingSet.h"
75#include "llvm/ADT/MapVector.h"
76#include "llvm/ADT/PointerIntPair.h"
77#include "llvm/ADT/PointerUnion.h"
78#include "llvm/ADT/STLExtras.h"
79#include "llvm/ADT/STLForwardCompat.h"
80#include "llvm/ADT/STLFunctionalExtras.h"
81#include "llvm/ADT/SetVector.h"
82#include "llvm/ADT/SmallBitVector.h"
83#include "llvm/ADT/SmallPtrSet.h"
84#include "llvm/ADT/SmallSet.h"
85#include "llvm/ADT/SmallVector.h"
86#include "llvm/ADT/StringExtras.h"
87#include "llvm/ADT/StringMap.h"
88#include "llvm/ADT/TinyPtrVector.h"
89#include "llvm/Support/Allocator.h"
90#include "llvm/Support/Compiler.h"
91#include "llvm/Support/Error.h"
92#include "llvm/Support/ErrorHandling.h"
104#include <type_traits>
109struct InlineAsmIdentifierInfo;
115struct ASTConstraintSatisfaction;
119class ASTMutationListener;
124class CXXFieldCollector;
125class CodeCompleteConsumer;
127class ConstraintSatisfaction;
130class DeducedTemplateArgument;
131struct DeductionFailureInfo;
132class DependentDiagnostic;
135class ImplicitConversionSequence;
137class InitializationKind;
138class InitializationSequence;
139class InitializedEntity;
141class LocalInstantiationScope;
143class MangleNumberingContext;
144typedef ArrayRef<std::pair<IdentifierInfo *, SourceLocation>>
ModuleIdPath;
146class MultiLevelTemplateArgumentList;
147struct NormalizedConstraint;
148class ObjCInterfaceDecl;
150struct OverloadCandidate;
153class OverloadCandidateSet;
159class SemaCodeCompletion;
173class SemaPseudoObject;
180class StandardConversionSequence;
181class TemplateArgument;
182class TemplateArgumentLoc;
183class TemplateInstantiationCallback;
184class TemplatePartialOrderingContext;
185class TemplateSpecCandidateSet;
188class TypoCorrectionConsumer;
189class UnresolvedSetImpl;
190class UnresolvedSetIterator;
191class VisibleDeclConsumer;
196class CapturedRegionScopeInfo;
197class CapturingScopeInfo;
198class CompoundScopeInfo;
199class DelayedDiagnostic;
200class DelayedDiagnosticPool;
201class FunctionScopeInfo;
202class LambdaScopeInfo;
203class SemaPPCallbacks;
204class TemplateDeductionInfo;
207namespace threadSafety {
214typedef std::pair<llvm::PointerUnion<const TemplateTypeParmType *, NamedDecl *>,
240 llvm::DenseMap<FileID, FileNullability> Map;
251 if (file ==
Cache.File)
252 return Cache.Nullability;
255 if (!
Cache.File.isInvalid()) {
261 Cache.Nullability = Map[file];
262 return Cache.Nullability;
290 llvm::function_ref<
QualType()> ComputeType);
308 if (!Enabled || Tok != ExpectedLoc)
313 return ComputeType();
325 llvm::function_ref<
QualType()> ComputeType;
587 llvm::function_ref<
void()> Fn);
608 const llvm::MapVector<FieldDecl *, DeleteLocs> &
690 unsigned OpenMPCaptureLevel = 0);
703 std::unique_ptr<sema::FunctionScopeInfo, PoppedFunctionScopeDeleter>;
715 const Decl *
D =
nullptr,
745 getCurLambda(
bool IgnoreNonLambdaCapturingScope =
false);
857 std::optional<FunctionEffectMode>
865 UnavailableAttr::ImplicitReason reason);
935 bool ForceComplain =
false,
936 bool (*IsPlausibleResult)(
QualType) =
nullptr);
972 S.ActOnStartOfCompoundStmt(IsStmtExpr);
1059 state.SavedPool = CurPool;
1068 CurPool = state.SavedPool;
1075 state.SavedPool = CurPool;
1082 assert(CurPool ==
nullptr);
1083 CurPool = state.SavedPool;
1085 } DelayedDiagnostics;
1120 assert(CodeCompletionPtr);
1121 return *CodeCompletionPtr;
1140 assert(LoongArchPtr);
1141 return *LoongArchPtr;
1180 assert(OpenMPPtr &&
"SemaOpenMP is dead");
1190 assert(PseudoObjectPtr);
1191 return *PseudoObjectPtr;
1235 std::optional<std::unique_ptr<DarwinSDKInfo>> CachedDarwinSDKInfo;
1236 bool WarnedDarwinSDKInfoMissing =
false;
1239 void operator=(
const Sema &) =
delete;
1254 std::unique_ptr<SemaAMDGPU> AMDGPUPtr;
1255 std::unique_ptr<SemaARM> ARMPtr;
1256 std::unique_ptr<SemaAVR> AVRPtr;
1257 std::unique_ptr<SemaBPF> BPFPtr;
1258 std::unique_ptr<SemaCodeCompletion> CodeCompletionPtr;
1259 std::unique_ptr<SemaCUDA> CUDAPtr;
1260 std::unique_ptr<SemaHLSL> HLSLPtr;
1261 std::unique_ptr<SemaHexagon> HexagonPtr;
1262 std::unique_ptr<SemaLoongArch> LoongArchPtr;
1263 std::unique_ptr<SemaM68k> M68kPtr;
1264 std::unique_ptr<SemaMIPS> MIPSPtr;
1265 std::unique_ptr<SemaMSP430> MSP430Ptr;
1266 std::unique_ptr<SemaNVPTX> NVPTXPtr;
1267 std::unique_ptr<SemaObjC> ObjCPtr;
1268 std::unique_ptr<SemaOpenACC> OpenACCPtr;
1269 std::unique_ptr<SemaOpenCL> OpenCLPtr;
1270 std::unique_ptr<SemaOpenMP> OpenMPPtr;
1271 std::unique_ptr<SemaPPC> PPCPtr;
1272 std::unique_ptr<SemaPseudoObject> PseudoObjectPtr;
1273 std::unique_ptr<SemaRISCV> RISCVPtr;
1274 std::unique_ptr<SemaSYCL> SYCLPtr;
1275 std::unique_ptr<SemaSwift> SwiftPtr;
1276 std::unique_ptr<SemaSystemZ> SystemZPtr;
1277 std::unique_ptr<SemaWasm> WasmPtr;
1278 std::unique_ptr<SemaX86> X86Ptr;
1344 bool IsCopyBindingRefToTemp =
false);
1392 unsigned DiagID,
bool ForceCheck =
false,
1393 bool ForceUnprivileged =
false);
1507 : PackAttr(
true), AlignMode(M), PackNumber(Num), XLStack(IsXL) {
1508 assert(Num == PackNumber &&
"The pack number has been truncated.");
1513 : PackAttr(
false), AlignMode(M),
1514 PackNumber(M ==
Packed ? 1 : UninitPackVal), XLStack(IsXL) {}
1524 std::uint32_t Encoding{};
1526 Encoding |= IsXLMask;
1528 Encoding |=
static_cast<uint32_t
>(Info.
getAlignMode()) << 1;
1531 Encoding |= PackAttrMask;
1533 Encoding |=
static_cast<uint32_t
>(Info.
getPackNumber()) << 4;
1539 bool IsXL =
static_cast<bool>(Encoding & IsXLMask);
1542 int PackNumber = (Encoding & PackNumMask) >> 4;
1544 if (Encoding & PackAttrMask)
1561 return PackNumber != UninitPackVal && PackNumber != 0;
1567 return std::tie(AlignMode, PackNumber, PackAttr, XLStack) ==
1568 std::tie(Info.AlignMode, Info.PackNumber, Info.PackAttr,
1573 return !(*
this == Info);
1585 unsigned char PackNumber;
1591 static constexpr unsigned char UninitPackVal = -1;
1594 static constexpr uint32_t IsXLMask{0x0000'0001};
1595 static constexpr uint32_t AlignModeMask{0x0000'0006};
1596 static constexpr uint32_t PackAttrMask{0x00000'0008};
1597 static constexpr uint32_t PackNumMask{0x0000'01F0};
1614 llvm::StringRef StackSlotLabel, ValueType
Value) {
1624 if (!StackSlotLabel.empty()) {
1626 auto I = llvm::find_if(llvm::reverse(
Stack), [&](
const Slot &x) {
1630 if (I !=
Stack.rend()) {
1633 Stack.erase(std::prev(I.base()),
Stack.end());
1635 }
else if (!
Stack.empty()) {
1664 "Can only push / pop #pragma stack sentinels!");
1736 StringRef SlotLabel;
1836 StringRef SlotLabel,
Expr *Alignment);
1892 bool UnifySection(StringRef SectionName,
int SectionFlags,
1894 bool UnifySection(StringRef SectionName,
int SectionFlags,
1900 llvm::StringRef StackSlotLabel,
1914 const SmallVector<std::tuple<IdentifierInfo *, SourceLocation>>
2037 bool SkipArgCountCheck =
false);
2039 bool SkipArgCountCheck =
false);
2065 bool ObjCPropertyAccess,
2066 bool AvoidPartialAvailabilityChecks =
false,
2188 unsigned ByteNo)
const;
2245 bool LayoutCompatible,
bool MustBeNull);
2258 LLVM_PREFERRED_TYPE(
bool)
2260 LLVM_PREFERRED_TYPE(
bool)
2314 bool CheckParameterNames);
2390 bool RangeIsError =
true);
2429 unsigned MaxArgCount);
2442 bool *ICContext =
nullptr,
2443 bool IsListInit =
false);
2446 bool CheckForFloatArgs =
true);
2450 void CheckArrayAccess(
const Expr *BaseExpr,
const Expr *IndexExpr,
2452 bool AllowOnePastEnd =
true,
bool IndexNegated =
false);
2453 void CheckArrayAccess(
const Expr *
E);
2480 bool CheckTSBuiltinFunctionCall(
const TargetInfo &TI,
unsigned BuiltinID,
2488 bool BuiltinVAStart(
unsigned BuiltinID,
CallExpr *TheCall);
2493 bool BuiltinUnorderedCompare(
CallExpr *TheCall,
unsigned BuiltinID);
2498 bool BuiltinFPClassification(
CallExpr *TheCall,
unsigned NumArgs,
2499 unsigned BuiltinID);
2502 bool BuiltinComplex(
CallExpr *TheCall);
2503 bool BuiltinOSLogFormat(
CallExpr *TheCall);
2508 bool BuiltinPrefetch(
CallExpr *TheCall);
2513 bool BuiltinAllocaWithAlign(
CallExpr *TheCall);
2516 bool BuiltinArithmeticFence(
CallExpr *TheCall);
2521 bool BuiltinAssume(
CallExpr *TheCall);
2525 bool BuiltinAssumeAligned(
CallExpr *TheCall);
2530 bool BuiltinLongjmp(
CallExpr *TheCall);
2534 bool BuiltinSetjmp(
CallExpr *TheCall);
2555 bool BuiltinElementwiseMath(
CallExpr *TheCall);
2556 bool PrepareBuiltinReduceMathOneArgCall(
CallExpr *TheCall);
2558 bool BuiltinNonDeterministicValue(
CallExpr *TheCall);
2570 bool CheckFormatArguments(
const FormatAttr *Format,
2574 llvm::SmallBitVector &CheckedVarArgs);
2580 llvm::SmallBitVector &CheckedVarArgs);
2597 void CheckMemaccessArguments(
const CallExpr *
Call,
unsigned BId,
2610 void CheckFreeArguments(
const CallExpr *
E);
2612 void CheckReturnValExpr(
Expr *RetValExp,
QualType lhsType,
2614 const AttrVec *Attrs =
nullptr,
2632 void CheckForIntOverflow(
const Expr *
E);
2633 void CheckUnsequencedOperations(
const Expr *
E);
2638 bool IsConstexpr =
false);
2644 std::unique_ptr<llvm::DenseMap<TypeTagMagicValue, TypeTagData>>
2645 TypeTagForDatatypeMagicValues;
2649 void CheckArgumentWithTypeTag(
const ArgumentWithTypeTagAttr *
Attr,
2655 void CheckAddressOfPackedMember(
Expr *rhs);
2659 struct MisalignedMember {
2665 MisalignedMember() :
E(), RD(), MD() {}
2666 MisalignedMember(Expr *
E, RecordDecl *RD, ValueDecl *MD,
2667 CharUnits Alignment)
2668 :
E(
E), RD(RD), MD(MD), Alignment(Alignment) {}
2669 explicit MisalignedMember(Expr *
E)
2670 : MisalignedMember(
E, nullptr, nullptr, CharUnits()) {}
2672 bool operator==(
const MisalignedMember &m) {
return this->E == m.E; }
2676 SmallVector<MisalignedMember, 4> MisalignedMembers;
2679 void AddPotentialMisalignedMembers(Expr *
E, RecordDecl *RD, ValueDecl *MD,
2680 CharUnits Alignment);
2708 Expr *Awaiter,
bool IsImplicit =
false);
2713 bool IsImplicit =
false);
2774 bool EnteringContext =
false);
2813 bool *CanCorrect =
nullptr);
2842 CCLoc(ColonColonLoc) {}
2884 bool ErrorRecoveryLookup,
2885 bool *IsCorrectedToColon =
nullptr,
2886 bool OnlyNamespace =
false);
2912 bool *IsCorrectedToColon =
nullptr,
2913 bool OnlyNamespace =
false);
2959 NestedNameSpecInfo &IdInfo,
2960 bool EnteringContext);
3029 unsigned SavedFunctionScopesStart;
3030 unsigned SavedInventedParameterInfosStart;
3034 : S(S), SavedContext(S.CurContext),
3036 SavedCXXThisTypeOverride(S.CXXThisTypeOverride),
3037 SavedFunctionScopesStart(S.FunctionScopesStart),
3038 SavedInventedParameterInfosStart(S.InventedParameterInfosStart) {
3039 assert(ContextToPush &&
"pushing null context");
3040 S.CurContext = ContextToPush;
3042 S.CXXThisTypeOverride =
QualType();
3044 S.FunctionScopesStart = S.FunctionScopes.size();
3045 S.InventedParameterInfosStart = S.InventedParameterInfos.size();
3051 S.CurContext = SavedContext;
3052 S.DelayedDiagnostics.popUndelayed(SavedContextState);
3053 S.CXXThisTypeOverride = SavedCXXThisTypeOverride;
3054 S.FunctionScopesStart = SavedFunctionScopesStart;
3055 S.InventedParameterInfosStart = SavedInventedParameterInfosStart;
3056 SavedContext =
nullptr;
3086 llvm::SmallDenseSet<WeakInfo, 2u, WeakInfo::DenseMapInfoByAliasOnly>>>
3123 return ModuleScopes.empty() ?
false
3124 : ModuleScopes.back().Module->isHeaderUnit();
3144 bool isClassName =
false,
bool HasTrailingDot =
false,
3146 bool IsCtorOrDtorName =
false,
3147 bool WantNontrivialTypeSourceInfo =
false,
3148 bool IsClassTemplateDeductionContext =
true,
3178 bool IsTemplateName =
false);
3186 bool IsTemplateTypeArg);
3259 Result.NonTypeDecl =
D;
3273 Result.Template = Name;
3279 Result.Template = Name;
3285 Result.Template = Name;
3291 Result.Template = Name;
3297 Result.Template = Name;
3304 assert(
Kind == NC_OverloadSet);
3309 assert(
Kind == NC_Type);
3314 assert(
Kind == NC_NonType);
3319 assert(
Kind == NC_TypeTemplate ||
Kind == NC_FunctionTemplate ||
3320 Kind == NC_VarTemplate ||
Kind == NC_Concept ||
3321 Kind == NC_UndeclaredTemplate);
3327 case NC_TypeTemplate:
3329 case NC_FunctionTemplate:
3331 case NC_VarTemplate:
3335 case NC_UndeclaredTemplate:
3338 llvm_unreachable(
"unsupported name classification.");
3365 const Token &NextToken,
3377 bool IsAddressOfOperand);
3383 const Token &NextToken);
3406 if (
auto *DRE = dyn_cast<DeclRefExpr>(
E.get()))
3407 return !DRE->hasExplicitTemplateArgs();
3408 if (
auto *ME = dyn_cast<MemberExpr>(
E.get()))
3409 return !ME->hasExplicitTemplateArgs();
3411 if (
auto *DSDRE = dyn_cast<DependentScopeDeclRefExpr>(
E.get()))
3412 return !DSDRE->hasExplicitTemplateArgs();
3413 if (
auto *DSME = dyn_cast<CXXDependentScopeMemberExpr>(
E.get()))
3414 return !DSME->hasExplicitTemplateArgs();
3431 unsigned FailedFoldDiagID);
3470 bool IsMemberSpecialization);
3578 bool IsMemberSpecialization,
bool DeclIsDefn);
3628 ParmVarDecl *
CheckParameter(DeclContext *DC, SourceLocation StartLoc,
3629 SourceLocation NameLoc,
3630 const IdentifierInfo *Name, QualType
T,
3673 unsigned NonTrivialKind);
3814 bool IsExplicitInstantiation,
3824 const PrintingPolicy &Policy);
3903 bool &OwnedDecl,
bool &IsDependent,
3905 bool ScopedEnumUsesClassTag,
TypeResult UnderlyingType,
3906 bool IsTypeSpecifier,
bool IsTemplateParamOrArg,
3970 bool IsFinalSpelledSealed,
3996 QualType EnumUnderlyingTy,
bool IsFixed,
4041 bool AllowInlineNamespace =
false)
const;
4094 bool MergeTypeWithOld,
bool NewDeclIsDefn);
4106 Scope *S,
bool MergeTypeWithOld);
4135 bool ConsiderLinkage,
bool AllowInlineNamespace);
4258 bool ConstexprSupported,
bool CLinkageMayDiffer);
4262 Expr *
Init,
unsigned DiagID = diag::err_init_element_not_constant);
4309 bool IsMsStruct,
Expr *BitWidth);
4315 bool AllowMask)
const;
4344 bool Final =
false);
4356 llvm::DenseMap<const NamedDecl *, const NamedDecl *> ShadowingDecls;
4370 static bool mightHaveNonExternalLinkage(
const DeclaratorDecl *FD);
4421 template <
typename AttrInfo>
4422 static std::enable_if_t<std::is_base_of_v<Attr, AttrInfo>,
SourceLocation>
4424 return AL.getLocation();
4433 template <
typename AttrInfo>
4436 bool StrictlyUnsigned =
false) {
4437 std::optional<llvm::APSInt> I = llvm::APSInt(32);
4450 if (!I->isIntN(32)) {
4452 <<
toString(*I, 10,
false) << 32 << 1;
4456 if (StrictlyUnsigned && I->isSigned() && I->isNegative()) {
4457 Diag(
getAttrLoc(AI), diag::err_attribute_requires_positive_integer)
4462 Val = (uint32_t)I->getZExtValue();
4489 const Expr *
E, StringRef &Str,
4521 bool Implicit, VersionTuple Introduced, VersionTuple Deprecated,
4522 VersionTuple Obsoleted,
bool IsUnavailable, StringRef Message,
4526 TypeVisibilityAttr *
4528 TypeVisibilityAttr::VisibilityType Vis);
4530 VisibilityAttr::VisibilityType Vis);
4556 Decl *
D,
bool &HasDefault,
bool &HasCommas,
bool &HasNotDefault,
4560 StringRef NewUserDiagnostic);
4567 bool IsPackExpansion);
4569 bool IsPackExpansion);
4587 bool InInstantiation =
false);
4596 const InternalLinkageAttr &AL);