14#ifndef LLVM_CLANG_SEMA_SEMA_H
15#define LLVM_CLANG_SEMA_SEMA_H
69#include "llvm/ADT/APInt.h"
70#include "llvm/ADT/ArrayRef.h"
71#include "llvm/ADT/BitmaskEnum.h"
72#include "llvm/ADT/DenseMap.h"
73#include "llvm/ADT/DenseSet.h"
74#include "llvm/ADT/FloatingPointMode.h"
75#include "llvm/ADT/FoldingSet.h"
76#include "llvm/ADT/MapVector.h"
77#include "llvm/ADT/PointerIntPair.h"
78#include "llvm/ADT/PointerUnion.h"
79#include "llvm/ADT/STLExtras.h"
80#include "llvm/ADT/STLForwardCompat.h"
81#include "llvm/ADT/STLFunctionalExtras.h"
82#include "llvm/ADT/SetVector.h"
83#include "llvm/ADT/SmallBitVector.h"
84#include "llvm/ADT/SmallPtrSet.h"
85#include "llvm/ADT/SmallSet.h"
86#include "llvm/ADT/SmallVector.h"
87#include "llvm/ADT/StringExtras.h"
88#include "llvm/ADT/StringMap.h"
89#include "llvm/ADT/TinyPtrVector.h"
90#include "llvm/Support/Allocator.h"
91#include "llvm/Support/Compiler.h"
92#include "llvm/Support/Error.h"
93#include "llvm/Support/ErrorHandling.h"
105#include <type_traits>
110struct InlineAsmIdentifierInfo;
116struct ASTConstraintSatisfaction;
120class ASTMutationListener;
125class CXXFieldCollector;
126class CodeCompleteConsumer;
128class ConstraintSatisfaction;
131class DeducedTemplateArgument;
132struct DeductionFailureInfo;
133class DependentDiagnostic;
136class ImplicitConversionSequence;
138class InitializationKind;
139class InitializationSequence;
140class InitializedEntity;
142class LocalInstantiationScope;
144class MangleNumberingContext;
145typedef ArrayRef<std::pair<IdentifierInfo *, SourceLocation>>
ModuleIdPath;
147class MultiLevelTemplateArgumentList;
148struct NormalizedConstraint;
149class ObjCInterfaceDecl;
151struct OverloadCandidate;
154class OverloadCandidateSet;
160class SemaCodeCompletion;
174class SemaPseudoObject;
181class StandardConversionSequence;
182class TemplateArgument;
183class TemplateArgumentLoc;
184class TemplateInstantiationCallback;
185class TemplatePartialOrderingContext;
186class TemplateSpecCandidateSet;
189class TypoCorrectionConsumer;
190class UnresolvedSetImpl;
191class UnresolvedSetIterator;
192class VisibleDeclConsumer;
197class CapturedRegionScopeInfo;
198class CapturingScopeInfo;
199class CompoundScopeInfo;
200class DelayedDiagnostic;
201class DelayedDiagnosticPool;
202class FunctionScopeInfo;
203class LambdaScopeInfo;
204class SemaPPCallbacks;
205class TemplateDeductionInfo;
222 DB << llvm::to_underlying(AA);
226namespace threadSafety {
233typedef std::pair<llvm::PointerUnion<const TemplateTypeParmType *, NamedDecl *>,
259 llvm::DenseMap<FileID, FileNullability> Map;
270 if (file ==
Cache.File)
271 return Cache.Nullability;
274 if (!
Cache.File.isInvalid()) {
280 Cache.Nullability = Map[file];
281 return Cache.Nullability;
309 llvm::function_ref<
QualType()> ComputeType);
327 if (!Enabled || Tok != ExpectedLoc)
332 return ComputeType();
344 llvm::function_ref<
QualType()> ComputeType;
555 llvm::function_ref<
void()> Fn);
576 const llvm::MapVector<FieldDecl *, DeleteLocs> &
658 unsigned OpenMPCaptureLevel = 0);
671 std::unique_ptr<sema::FunctionScopeInfo, PoppedFunctionScopeDeleter>;
683 const Decl *
D =
nullptr,
713 getCurLambda(
bool IgnoreNonLambdaCapturingScope =
false);
813 UnavailableAttr::ImplicitReason reason);
881 bool ForceComplain =
false,
882 bool (*IsPlausibleResult)(
QualType) =
nullptr);
918 S.ActOnStartOfCompoundStmt(IsStmtExpr);
1005 state.SavedPool = CurPool;
1014 CurPool = state.SavedPool;
1021 state.SavedPool = CurPool;
1028 assert(CurPool ==
nullptr);
1029 CurPool = state.SavedPool;
1031 } DelayedDiagnostics;
1066 assert(CodeCompletionPtr);
1067 return *CodeCompletionPtr;
1086 assert(LoongArchPtr);
1087 return *LoongArchPtr;
1126 assert(OpenMPPtr &&
"SemaOpenMP is dead");
1136 assert(PseudoObjectPtr);
1137 return *PseudoObjectPtr;
1181 std::optional<std::unique_ptr<DarwinSDKInfo>> CachedDarwinSDKInfo;
1182 bool WarnedDarwinSDKInfoMissing =
false;
1187 void operator=(
const Sema &) =
delete;
1202 std::unique_ptr<SemaAMDGPU> AMDGPUPtr;
1203 std::unique_ptr<SemaARM> ARMPtr;
1204 std::unique_ptr<SemaAVR> AVRPtr;
1205 std::unique_ptr<SemaBPF> BPFPtr;
1206 std::unique_ptr<SemaCodeCompletion> CodeCompletionPtr;
1207 std::unique_ptr<SemaCUDA> CUDAPtr;
1208 std::unique_ptr<SemaHLSL> HLSLPtr;
1209 std::unique_ptr<SemaHexagon> HexagonPtr;
1210 std::unique_ptr<SemaLoongArch> LoongArchPtr;
1211 std::unique_ptr<SemaM68k> M68kPtr;
1212 std::unique_ptr<SemaMIPS> MIPSPtr;
1213 std::unique_ptr<SemaMSP430> MSP430Ptr;
1214 std::unique_ptr<SemaNVPTX> NVPTXPtr;
1215 std::unique_ptr<SemaObjC> ObjCPtr;
1216 std::unique_ptr<SemaOpenACC> OpenACCPtr;
1217 std::unique_ptr<SemaOpenCL> OpenCLPtr;
1218 std::unique_ptr<SemaOpenMP> OpenMPPtr;
1219 std::unique_ptr<SemaPPC> PPCPtr;
1220 std::unique_ptr<SemaPseudoObject> PseudoObjectPtr;
1221 std::unique_ptr<SemaRISCV> RISCVPtr;
1222 std::unique_ptr<SemaSYCL> SYCLPtr;
1223 std::unique_ptr<SemaSwift> SwiftPtr;
1224 std::unique_ptr<SemaSystemZ> SystemZPtr;
1225 std::unique_ptr<SemaWasm> WasmPtr;
1226 std::unique_ptr<SemaX86> X86Ptr;
1292 bool IsCopyBindingRefToTemp =
false);
1340 unsigned DiagID,
bool ForceCheck =
false,
1341 bool ForceUnprivileged =
false);
1455 : PackAttr(
true), AlignMode(M), PackNumber(
Num), XLStack(IsXL) {
1456 assert(
Num == PackNumber &&
"The pack number has been truncated.");
1461 : PackAttr(
false), AlignMode(M),
1462 PackNumber(M ==
Packed ? 1 : UninitPackVal), XLStack(IsXL) {}
1472 std::uint32_t Encoding{};
1474 Encoding |= IsXLMask;
1476 Encoding |=
static_cast<uint32_t
>(Info.
getAlignMode()) << 1;
1479 Encoding |= PackAttrMask;
1481 Encoding |=
static_cast<uint32_t
>(Info.
getPackNumber()) << 4;
1487 bool IsXL =
static_cast<bool>(Encoding & IsXLMask);
1490 int PackNumber = (Encoding & PackNumMask) >> 4;
1492 if (Encoding & PackAttrMask)
1509 return PackNumber != UninitPackVal && PackNumber != 0;
1515 return std::tie(AlignMode, PackNumber, PackAttr, XLStack) ==
1516 std::tie(Info.AlignMode, Info.PackNumber, Info.PackAttr,
1521 return !(*
this == Info);
1533 unsigned char PackNumber;
1539 static constexpr unsigned char UninitPackVal = -1;
1542 static constexpr uint32_t IsXLMask{0x0000'0001};
1543 static constexpr uint32_t AlignModeMask{0x0000'0006};
1544 static constexpr uint32_t PackAttrMask{0x00000'0008};
1545 static constexpr uint32_t PackNumMask{0x0000'01F0};
1562 llvm::StringRef StackSlotLabel, ValueType
Value) {
1572 if (!StackSlotLabel.empty()) {
1574 auto I = llvm::find_if(llvm::reverse(
Stack), [&](
const Slot &x) {
1578 if (I !=
Stack.rend()) {
1581 Stack.erase(std::prev(I.base()),
Stack.end());
1583 }
else if (!
Stack.empty()) {
1612 "Can only push / pop #pragma stack sentinels!");
1684 StringRef SlotLabel;
1767 StringRef ParamName);
1798 StringRef SlotLabel,
Expr *Alignment);
1854 bool UnifySection(StringRef SectionName,
int SectionFlags,
1856 bool UnifySection(StringRef SectionName,
int SectionFlags,
1862 llvm::StringRef StackSlotLabel,
1876 const SmallVector<std::tuple<IdentifierInfo *, SourceLocation>>
1999 bool SkipArgCountCheck =
false);
2001 bool SkipArgCountCheck =
false);
2027 bool ObjCPropertyAccess,
2028 bool AvoidPartialAvailabilityChecks =
false,
2150 unsigned ByteNo)
const;
2207 bool LayoutCompatible,
bool MustBeNull);
2220 LLVM_PREFERRED_TYPE(
bool)
2222 LLVM_PREFERRED_TYPE(
bool)
2276 bool CheckParameterNames);
2356 bool RangeIsError =
true);
2395 unsigned MaxArgCount);
2408 bool *ICContext =
nullptr,
2409 bool IsListInit =
false);
2412 bool CheckForFloatArgs =
true);
2416 void CheckArrayAccess(
const Expr *BaseExpr,
const Expr *IndexExpr,
2418 bool AllowOnePastEnd =
true,
bool IndexNegated =
false);
2419 void CheckArrayAccess(
const Expr *
E);
2446 bool CheckTSBuiltinFunctionCall(
const TargetInfo &TI,
unsigned BuiltinID,
2454 bool BuiltinVAStart(
unsigned BuiltinID,
CallExpr *TheCall);
2459 bool BuiltinUnorderedCompare(
CallExpr *TheCall,
unsigned BuiltinID);
2464 bool BuiltinFPClassification(
CallExpr *TheCall,
unsigned NumArgs,
2465 unsigned BuiltinID);
2468 bool BuiltinComplex(
CallExpr *TheCall);
2469 bool BuiltinOSLogFormat(
CallExpr *TheCall);
2474 bool BuiltinPrefetch(
CallExpr *TheCall);
2479 bool BuiltinAllocaWithAlign(
CallExpr *TheCall);
2482 bool BuiltinArithmeticFence(
CallExpr *TheCall);
2487 bool BuiltinAssume(
CallExpr *TheCall);
2491 bool BuiltinAssumeAligned(
CallExpr *TheCall);
2496 bool BuiltinLongjmp(
CallExpr *TheCall);
2500 bool BuiltinSetjmp(
CallExpr *TheCall);
2522 bool BuiltinElementwiseMath(
CallExpr *TheCall,
bool FPOnly =
false);
2523 bool PrepareBuiltinReduceMathOneArgCall(
CallExpr *TheCall);
2525 bool BuiltinNonDeterministicValue(
CallExpr *TheCall);
2527 enum BuiltinCountedByRefKind {
2536 bool CheckInvalidBuiltinCountedByRef(
const Expr *
E,
2537 BuiltinCountedByRefKind K);
2538 bool BuiltinCountedByRef(CallExpr *TheCall);
2542 ExprResult BuiltinMatrixColumnMajorLoad(CallExpr *TheCall,
2544 ExprResult BuiltinMatrixColumnMajorStore(CallExpr *TheCall,
2550 bool CheckFormatArguments(
const FormatAttr *Format,
2551 ArrayRef<const Expr *> Args,
bool IsCXXMember,
2554 llvm::SmallBitVector &CheckedVarArgs);
2555 bool CheckFormatArguments(ArrayRef<const Expr *> Args,
2560 llvm::SmallBitVector &CheckedVarArgs);
2562 void CheckInfNaNFunction(
const CallExpr *
Call,
const FunctionDecl *FDecl);
2565 void CheckAbsoluteValueFunction(
const CallExpr *
Call,
2566 const FunctionDecl *FDecl);
2568 void CheckMaxUnsignedZero(
const CallExpr *
Call,
const FunctionDecl *FDecl);
2577 void CheckMemaccessArguments(
const CallExpr *
Call,
unsigned BId,
2578 IdentifierInfo *FnName);
2582 void CheckStrlcpycatArguments(
const CallExpr *
Call, IdentifierInfo *FnName);
2587 void CheckStrncatArguments(
const CallExpr *
Call, IdentifierInfo *FnName);
2590 void CheckFreeArguments(
const CallExpr *
E);
2592 void CheckReturnValExpr(Expr *RetValExp, QualType lhsType,
2593 SourceLocation ReturnLoc,
bool isObjCMethod =
false,
2594 const AttrVec *Attrs =
nullptr,
2595 const FunctionDecl *FD =
nullptr);
2604 void CheckImplicitConversions(Expr *
E, SourceLocation CC = SourceLocation());
2608 void CheckBoolLikeConversion(Expr *
E, SourceLocation CC);
2612 void CheckForIntOverflow(
const Expr *
E);
2613 void CheckUnsequencedOperations(
const Expr *
E);
2617 void CheckCompletedExpr(Expr *
E, SourceLocation CheckLoc = SourceLocation(),
2618 bool IsConstexpr =
false);
2620 void CheckBitFieldInitialization(SourceLocation InitLoc, FieldDecl *Field,
2624 std::unique_ptr<llvm::DenseMap<TypeTagMagicValue, TypeTagData>>
2625 TypeTagForDatatypeMagicValues;
2629 void CheckArgumentWithTypeTag(
const ArgumentWithTypeTagAttr *Attr,
2630 const ArrayRef<const Expr *> ExprArgs,
2631 SourceLocation CallSiteLoc);
2635 void CheckAddressOfPackedMember(Expr *rhs);
2639 struct MisalignedMember {
2643 CharUnits Alignment;
2645 MisalignedMember() :
E(), RD(), MD() {}
2646 MisalignedMember(Expr *
E, RecordDecl *RD, ValueDecl *MD,
2647 CharUnits Alignment)
2648 :
E(
E), RD(RD), MD(MD), Alignment(Alignment) {}
2649 explicit MisalignedMember(Expr *
E)
2650 : MisalignedMember(
E, nullptr, nullptr, CharUnits()) {}
2652 bool operator==(
const MisalignedMember &m) {
return this->E == m.E; }
2656 SmallVector<MisalignedMember, 4> MisalignedMembers;
2659 void AddPotentialMisalignedMembers(Expr *
E, RecordDecl *RD, ValueDecl *MD,
2660 CharUnits Alignment);
2688 Expr *Awaiter,
bool IsImplicit =
false);
2693 bool IsImplicit =
false);
2754 bool EnteringContext =
false);
2793 bool *CanCorrect =
nullptr);
2822 CCLoc(ColonColonLoc) {}
2864 bool ErrorRecoveryLookup,
2865 bool *IsCorrectedToColon =
nullptr,
2866 bool OnlyNamespace =
false);
2892 bool *IsCorrectedToColon =
nullptr,
2893 bool OnlyNamespace =
false);
2939 NestedNameSpecInfo &IdInfo,
2940 bool EnteringContext);
3009 unsigned SavedFunctionScopesStart;
3010 unsigned SavedInventedParameterInfosStart;
3014 : S(S), SavedContext(S.CurContext),
3016 SavedCXXThisTypeOverride(S.CXXThisTypeOverride),
3017 SavedFunctionScopesStart(S.FunctionScopesStart),
3018 SavedInventedParameterInfosStart(S.InventedParameterInfosStart) {
3019 assert(ContextToPush &&
"pushing null context");
3020 S.CurContext = ContextToPush;
3022 S.CXXThisTypeOverride =
QualType();
3024 S.FunctionScopesStart = S.FunctionScopes.size();
3025 S.InventedParameterInfosStart = S.InventedParameterInfos.size();
3031 S.CurContext = SavedContext;
3032 S.DelayedDiagnostics.popUndelayed(SavedContextState);
3033 S.CXXThisTypeOverride = SavedCXXThisTypeOverride;
3034 S.FunctionScopesStart = SavedFunctionScopesStart;
3035 S.InventedParameterInfosStart = SavedInventedParameterInfosStart;
3036 SavedContext =
nullptr;
3066 llvm::SmallDenseSet<WeakInfo, 2u, WeakInfo::DenseMapInfoByAliasOnly>>>
3103 return ModuleScopes.empty() ?
false
3104 : ModuleScopes.back().Module->isHeaderUnit();
3124 bool isClassName =
false,
bool HasTrailingDot =
false,
3126 bool IsCtorOrDtorName =
false,
3127 bool WantNontrivialTypeSourceInfo =
false,
3128 bool IsClassTemplateDeductionContext =
true,
3158 bool IsTemplateName =
false);
3166 bool IsTemplateTypeArg);
3239 Result.NonTypeDecl =
D;
3253 Result.Template = Name;
3259 Result.Template = Name;
3265 Result.Template = Name;
3271 Result.Template = Name;
3277 Result.Template = Name;
3284 assert(
Kind == NC_OverloadSet);
3289 assert(
Kind == NC_Type);
3294 assert(
Kind == NC_NonType);
3299 assert(
Kind == NC_TypeTemplate ||
Kind == NC_FunctionTemplate ||
3300 Kind == NC_VarTemplate ||
Kind == NC_Concept ||
3301 Kind == NC_UndeclaredTemplate);
3307 case NC_TypeTemplate:
3309 case NC_FunctionTemplate:
3311 case NC_VarTemplate:
3315 case NC_UndeclaredTemplate:
3318 llvm_unreachable(
"unsupported name classification.");
3345 const Token &NextToken,
3357 bool IsAddressOfOperand);
3363 const Token &NextToken);
3386 if (
auto *DRE = dyn_cast<DeclRefExpr>(
E.get()))
3387 return !DRE->hasExplicitTemplateArgs();
3388 if (
auto *ME = dyn_cast<MemberExpr>(
E.get()))
3389 return !ME->hasExplicitTemplateArgs();
3391 if (
auto *DSDRE = dyn_cast<DependentScopeDeclRefExpr>(
E.get()))
3392 return !DSDRE->hasExplicitTemplateArgs();
3393 if (
auto *DSME = dyn_cast<CXXDependentScopeMemberExpr>(
E.get()))
3394 return !DSME->hasExplicitTemplateArgs();
3411 unsigned FailedFoldDiagID);
3450 bool IsMemberSpecialization);
3532 TypeSourceInfo *TInfo,
3560 bool IsMemberSpecialization,
bool DeclIsDefn);
3581 QualType NewT, QualType OldT);
3582 void CheckMain(FunctionDecl *FD,
const DeclSpec &
D);
3604 SourceLocation ExplicitThisLoc = {});
3610 ParmVarDecl *
CheckParameter(DeclContext *DC, SourceLocation StartLoc,
3611 SourceLocation NameLoc,
3612 const IdentifierInfo *Name, QualType
T,
3655 unsigned NonTrivialKind);
3796 bool IsExplicitInstantiation,
3806 const PrintingPolicy &Policy);
3885 bool &OwnedDecl,
bool &IsDependent,
3887 bool ScopedEnumUsesClassTag,
TypeResult UnderlyingType,
3888 bool IsTypeSpecifier,
bool IsTemplateParamOrArg,
3952 bool IsFinalSpelledSealed,
3978 QualType EnumUnderlyingTy,
bool IsFixed,
4023 bool AllowInlineNamespace =
false)
const;
4076 bool MergeTypeWithOld,
bool NewDeclIsDefn);
4088 Scope *S,
bool MergeTypeWithOld);
4117 bool ConsiderLinkage,
bool AllowInlineNamespace);
4240 bool ConstexprSupported,
bool CLinkageMayDiffer);
4244 Expr *
Init,
unsigned DiagID = diag::err_init_element_not_constant);
4291 bool IsMsStruct,
Expr *BitWidth);
4297 bool AllowMask)
const;
4326 bool Final =
false);
4338 llvm::DenseMap<const NamedDecl *, const NamedDecl *> ShadowingDecls;
4352 static bool mightHaveNonExternalLinkage(
const DeclaratorDecl *FD);
4403 template <
typename AttrInfo>
4404 static std::enable_if_t<std::is_base_of_v<Attr, AttrInfo>,
SourceLocation>
4406 return AL.getLocation();
4415 template <
typename AttrInfo>
4418 bool StrictlyUnsigned =
false) {
4419 std::optional<llvm::APSInt> I = llvm::APSInt(32);
4432 if (!I->isIntN(32)) {
4434 <<
toString(*I, 10,
false) << 32 << 1;
4438 if (StrictlyUnsigned && I->isSigned() && I->isNegative()) {
4439 Diag(
getAttrLoc(AI), diag::err_attribute_requires_positive_integer)
4444 Val = (uint32_t)I->getZExtValue();
4471 const Expr *
E, StringRef &Str,
4504 bool Implicit, VersionTuple Introduced, VersionTuple Deprecated,
4505 VersionTuple Obsoleted,
bool IsUnavailable, StringRef Message,
4509 TypeVisibilityAttr *
4511 TypeVisibilityAttr::VisibilityType Vis);
4513 VisibilityAttr::VisibilityType Vis);
4539 Decl *
D,
bool &HasDefault,
bool &HasCommas,
bool &HasNotDefault,
4543 StringRef NewUserDiagnostic);
4550 bool IsPackExpansion);
4552 bool IsPackExpansion);
4571 bool InInstantiation =
false);
4580 const InternalLinkageAttr &AL);
4607 StringRef UuidAsWritten,
MSGuidDecl *GuidDecl);
4620 const EnforceTCBLeafAttr &AL);
4630 : IncludeCXX11Attributes(
true), IgnoreTypeAttributes(
false) {}
4634 Result.IncludeCXX11Attributes = Val;
4640 Result.IgnoreTypeAttributes = Val;