File indexing completed on 2026-05-10 08:37:04
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef LLVM_CLANG_SEMA_SEMA_H
0015 #define LLVM_CLANG_SEMA_SEMA_H
0016
0017 #include "clang/APINotes/APINotesManager.h"
0018 #include "clang/AST/ASTFwd.h"
0019 #include "clang/AST/ASTLambda.h"
0020 #include "clang/AST/Attr.h"
0021 #include "clang/AST/AttrIterator.h"
0022 #include "clang/AST/CharUnits.h"
0023 #include "clang/AST/DeclBase.h"
0024 #include "clang/AST/DeclCXX.h"
0025 #include "clang/AST/DeclTemplate.h"
0026 #include "clang/AST/DeclarationName.h"
0027 #include "clang/AST/Expr.h"
0028 #include "clang/AST/ExprCXX.h"
0029 #include "clang/AST/ExprConcepts.h"
0030 #include "clang/AST/ExternalASTSource.h"
0031 #include "clang/AST/NestedNameSpecifier.h"
0032 #include "clang/AST/OperationKinds.h"
0033 #include "clang/AST/StmtCXX.h"
0034 #include "clang/AST/Type.h"
0035 #include "clang/AST/TypeLoc.h"
0036 #include "clang/Basic/AttrSubjectMatchRules.h"
0037 #include "clang/Basic/Builtins.h"
0038 #include "clang/Basic/CapturedStmt.h"
0039 #include "clang/Basic/Cuda.h"
0040 #include "clang/Basic/DiagnosticSema.h"
0041 #include "clang/Basic/ExceptionSpecificationType.h"
0042 #include "clang/Basic/ExpressionTraits.h"
0043 #include "clang/Basic/LLVM.h"
0044 #include "clang/Basic/Lambda.h"
0045 #include "clang/Basic/LangOptions.h"
0046 #include "clang/Basic/Module.h"
0047 #include "clang/Basic/OpenCLOptions.h"
0048 #include "clang/Basic/OperatorKinds.h"
0049 #include "clang/Basic/PartialDiagnostic.h"
0050 #include "clang/Basic/PragmaKinds.h"
0051 #include "clang/Basic/SourceLocation.h"
0052 #include "clang/Basic/Specifiers.h"
0053 #include "clang/Basic/StackExhaustionHandler.h"
0054 #include "clang/Basic/TemplateKinds.h"
0055 #include "clang/Basic/TokenKinds.h"
0056 #include "clang/Basic/TypeTraits.h"
0057 #include "clang/Sema/AnalysisBasedWarnings.h"
0058 #include "clang/Sema/Attr.h"
0059 #include "clang/Sema/CleanupInfo.h"
0060 #include "clang/Sema/DeclSpec.h"
0061 #include "clang/Sema/ExternalSemaSource.h"
0062 #include "clang/Sema/IdentifierResolver.h"
0063 #include "clang/Sema/Ownership.h"
0064 #include "clang/Sema/ParsedAttr.h"
0065 #include "clang/Sema/Redeclaration.h"
0066 #include "clang/Sema/Scope.h"
0067 #include "clang/Sema/SemaBase.h"
0068 #include "clang/Sema/TypoCorrection.h"
0069 #include "clang/Sema/Weak.h"
0070 #include "llvm/ADT/APInt.h"
0071 #include "llvm/ADT/ArrayRef.h"
0072 #include "llvm/ADT/BitmaskEnum.h"
0073 #include "llvm/ADT/DenseMap.h"
0074 #include "llvm/ADT/DenseSet.h"
0075 #include "llvm/ADT/FloatingPointMode.h"
0076 #include "llvm/ADT/FoldingSet.h"
0077 #include "llvm/ADT/MapVector.h"
0078 #include "llvm/ADT/PointerIntPair.h"
0079 #include "llvm/ADT/PointerUnion.h"
0080 #include "llvm/ADT/STLExtras.h"
0081 #include "llvm/ADT/STLForwardCompat.h"
0082 #include "llvm/ADT/STLFunctionalExtras.h"
0083 #include "llvm/ADT/SetVector.h"
0084 #include "llvm/ADT/SmallBitVector.h"
0085 #include "llvm/ADT/SmallPtrSet.h"
0086 #include "llvm/ADT/SmallSet.h"
0087 #include "llvm/ADT/SmallVector.h"
0088 #include "llvm/ADT/StringExtras.h"
0089 #include "llvm/ADT/StringMap.h"
0090 #include "llvm/ADT/TinyPtrVector.h"
0091 #include "llvm/Support/Allocator.h"
0092 #include "llvm/Support/Compiler.h"
0093 #include "llvm/Support/Error.h"
0094 #include "llvm/Support/ErrorHandling.h"
0095 #include <cassert>
0096 #include <climits>
0097 #include <cstddef>
0098 #include <cstdint>
0099 #include <deque>
0100 #include <functional>
0101 #include <iterator>
0102 #include <memory>
0103 #include <optional>
0104 #include <string>
0105 #include <tuple>
0106 #include <type_traits>
0107 #include <utility>
0108 #include <vector>
0109
0110 namespace llvm {
0111 struct InlineAsmIdentifierInfo;
0112 }
0113
0114 namespace clang {
0115 class ADLResult;
0116 class APValue;
0117 struct ASTConstraintSatisfaction;
0118 class ASTConsumer;
0119 class ASTContext;
0120 class ASTDeclReader;
0121 class ASTMutationListener;
0122 class ASTReader;
0123 class ASTWriter;
0124 class CXXBasePath;
0125 class CXXBasePaths;
0126 class CXXFieldCollector;
0127 class CodeCompleteConsumer;
0128 enum class ComparisonCategoryType : unsigned char;
0129 class ConstraintSatisfaction;
0130 class DarwinSDKInfo;
0131 class DeclGroupRef;
0132 class DeducedTemplateArgument;
0133 struct DeductionFailureInfo;
0134 class DependentDiagnostic;
0135 class Designation;
0136 class IdentifierInfo;
0137 class ImplicitConversionSequence;
0138 typedef MutableArrayRef<ImplicitConversionSequence> ConversionSequenceList;
0139 class InitializationKind;
0140 class InitializationSequence;
0141 class InitializedEntity;
0142 enum class LangAS : unsigned int;
0143 class LocalInstantiationScope;
0144 class LookupResult;
0145 class MangleNumberingContext;
0146 typedef ArrayRef<std::pair<IdentifierInfo *, SourceLocation>> ModuleIdPath;
0147 class ModuleLoader;
0148 class MultiLevelTemplateArgumentList;
0149 struct NormalizedConstraint;
0150 class ObjCInterfaceDecl;
0151 class ObjCMethodDecl;
0152 struct OverloadCandidate;
0153 enum class OverloadCandidateParamOrder : char;
0154 enum OverloadCandidateRewriteKind : unsigned;
0155 class OverloadCandidateSet;
0156 class Preprocessor;
0157 class SemaAMDGPU;
0158 class SemaARM;
0159 class SemaAVR;
0160 class SemaBPF;
0161 class SemaCodeCompletion;
0162 class SemaCUDA;
0163 class SemaHLSL;
0164 class SemaHexagon;
0165 class SemaLoongArch;
0166 class SemaM68k;
0167 class SemaMIPS;
0168 class SemaMSP430;
0169 class SemaNVPTX;
0170 class SemaObjC;
0171 class SemaOpenACC;
0172 class SemaOpenCL;
0173 class SemaOpenMP;
0174 class SemaPPC;
0175 class SemaPseudoObject;
0176 class SemaRISCV;
0177 class SemaSPIRV;
0178 class SemaSYCL;
0179 class SemaSwift;
0180 class SemaSystemZ;
0181 class SemaWasm;
0182 class SemaX86;
0183 class StandardConversionSequence;
0184 class TemplateArgument;
0185 class TemplateArgumentLoc;
0186 class TemplateInstantiationCallback;
0187 class TemplatePartialOrderingContext;
0188 class TemplateSpecCandidateSet;
0189 class Token;
0190 class TypeConstraint;
0191 class TypoCorrectionConsumer;
0192 class UnresolvedSetImpl;
0193 class UnresolvedSetIterator;
0194 class VisibleDeclConsumer;
0195
0196 namespace sema {
0197 class BlockScopeInfo;
0198 class Capture;
0199 class CapturedRegionScopeInfo;
0200 class CapturingScopeInfo;
0201 class CompoundScopeInfo;
0202 class DelayedDiagnostic;
0203 class DelayedDiagnosticPool;
0204 class FunctionScopeInfo;
0205 class LambdaScopeInfo;
0206 class SemaPPCallbacks;
0207 class TemplateDeductionInfo;
0208 }
0209
0210
0211
0212 enum class AssignmentAction {
0213 Assigning,
0214 Passing,
0215 Returning,
0216 Converting,
0217 Initializing,
0218 Sending,
0219 Casting,
0220 Passing_CFAudited
0221 };
0222 inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
0223 const AssignmentAction &AA) {
0224 DB << llvm::to_underlying(AA);
0225 return DB;
0226 }
0227
0228 namespace threadSafety {
0229 class BeforeSet;
0230 void threadSafetyCleanup(BeforeSet *Cache);
0231 }
0232
0233
0234
0235 typedef std::pair<llvm::PointerUnion<const TemplateTypeParmType *, NamedDecl *>,
0236 SourceLocation>
0237 UnexpandedParameterPack;
0238
0239
0240
0241 struct FileNullability {
0242
0243
0244 SourceLocation PointerLoc;
0245
0246
0247
0248 SourceLocation PointerEndLoc;
0249
0250
0251 uint8_t PointerKind;
0252
0253
0254 bool SawTypeNullability = false;
0255 };
0256
0257
0258
0259 class FileNullabilityMap {
0260
0261 llvm::DenseMap<FileID, FileNullability> Map;
0262
0263
0264 struct {
0265 FileID File;
0266 FileNullability Nullability;
0267 } Cache;
0268
0269 public:
0270 FileNullability &operator[](FileID file) {
0271
0272 if (file == Cache.File)
0273 return Cache.Nullability;
0274
0275
0276 if (!Cache.File.isInvalid()) {
0277 Map[Cache.File] = Cache.Nullability;
0278 }
0279
0280
0281 Cache.File = file;
0282 Cache.Nullability = Map[file];
0283 return Cache.Nullability;
0284 }
0285 };
0286
0287
0288
0289
0290
0291 class PreferredTypeBuilder {
0292 public:
0293 PreferredTypeBuilder(bool Enabled) : Enabled(Enabled) {}
0294
0295 void enterCondition(Sema &S, SourceLocation Tok);
0296 void enterReturn(Sema &S, SourceLocation Tok);
0297 void enterVariableInit(SourceLocation Tok, Decl *D);
0298
0299 void enterDesignatedInitializer(SourceLocation Tok, QualType BaseType,
0300 const Designation &D);
0301
0302
0303
0304
0305
0306
0307
0308
0309
0310 void enterFunctionArgument(SourceLocation Tok,
0311 llvm::function_ref<QualType()> ComputeType);
0312
0313 void enterParenExpr(SourceLocation Tok, SourceLocation LParLoc);
0314 void enterUnary(Sema &S, SourceLocation Tok, tok::TokenKind OpKind,
0315 SourceLocation OpLoc);
0316 void enterBinary(Sema &S, SourceLocation Tok, Expr *LHS, tok::TokenKind Op);
0317 void enterMemAccess(Sema &S, SourceLocation Tok, Expr *Base);
0318 void enterSubscript(Sema &S, SourceLocation Tok, Expr *LHS);
0319
0320 void enterTypeCast(SourceLocation Tok, QualType CastType);
0321
0322
0323
0324
0325
0326
0327
0328 QualType get(SourceLocation Tok) const {
0329 if (!Enabled || Tok != ExpectedLoc)
0330 return QualType();
0331 if (!Type.isNull())
0332 return Type;
0333 if (ComputeType)
0334 return ComputeType();
0335 return QualType();
0336 }
0337
0338 private:
0339 bool Enabled;
0340
0341 SourceLocation ExpectedLoc;
0342
0343 QualType Type;
0344
0345
0346 llvm::function_ref<QualType()> ComputeType;
0347 };
0348
0349 struct SkipBodyInfo {
0350 SkipBodyInfo() = default;
0351 bool ShouldSkip = false;
0352 bool CheckSameAsPrevious = false;
0353 NamedDecl *Previous = nullptr;
0354 NamedDecl *New = nullptr;
0355 };
0356
0357
0358
0359
0360
0361
0362
0363
0364
0365
0366 enum class TemplateDeductionResult {
0367
0368 Success = 0,
0369
0370 Invalid,
0371
0372
0373 InstantiationDepth,
0374
0375
0376 Incomplete,
0377
0378
0379 IncompletePack,
0380
0381
0382 Inconsistent,
0383
0384
0385
0386
0387 Underqualified,
0388
0389
0390 SubstitutionFailure,
0391
0392
0393 DeducedMismatch,
0394
0395
0396
0397 DeducedMismatchNested,
0398
0399
0400 NonDeducedMismatch,
0401
0402
0403 TooManyArguments,
0404
0405
0406 TooFewArguments,
0407
0408
0409 InvalidExplicitArguments,
0410
0411 NonDependentConversionFailure,
0412
0413
0414 ConstraintsNotSatisfied,
0415
0416 MiscellaneousDeductionFailure,
0417
0418 CUDATargetMismatch,
0419
0420 AlreadyDiagnosed
0421 };
0422
0423
0424 enum class CXXSpecialMemberKind {
0425 DefaultConstructor,
0426 CopyConstructor,
0427 MoveConstructor,
0428 CopyAssignment,
0429 MoveAssignment,
0430 Destructor,
0431 Invalid
0432 };
0433
0434
0435 enum class CheckedConversionKind {
0436
0437 Implicit,
0438
0439 CStyleCast,
0440
0441 FunctionalCast,
0442
0443 OtherCast,
0444
0445 ForBuiltinOverloadedOp
0446 };
0447
0448 enum class TagUseKind {
0449 Reference,
0450 Declaration,
0451 Definition,
0452 Friend
0453 };
0454
0455
0456 enum class FunctionEffectMode : uint8_t {
0457 None,
0458 False,
0459 True,
0460 Dependent
0461 };
0462
0463
0464
0465 class Sema final : public SemaBase {
0466
0467
0468
0469
0470
0471
0472
0473
0474
0475
0476
0477
0478
0479
0480
0481
0482
0483
0484
0485
0486
0487
0488
0489
0490
0491
0492
0493
0494
0495
0496
0497
0498
0499
0500
0501
0502
0503
0504
0505
0506
0507
0508
0509 public:
0510 Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer,
0511 TranslationUnitKind TUKind = TU_Complete,
0512 CodeCompleteConsumer *CompletionConsumer = nullptr);
0513 ~Sema();
0514
0515
0516
0517 void Initialize();
0518
0519
0520
0521
0522
0523
0524 virtual void anchor();
0525
0526 const LangOptions &getLangOpts() const { return LangOpts; }
0527 OpenCLOptions &getOpenCLOptions() { return OpenCLFeatures; }
0528 FPOptions &getCurFPFeatures() { return CurFPFeatures; }
0529
0530 DiagnosticsEngine &getDiagnostics() const { return Diags; }
0531 SourceManager &getSourceManager() const { return SourceMgr; }
0532 Preprocessor &getPreprocessor() const { return PP; }
0533 ASTContext &getASTContext() const { return Context; }
0534 ASTConsumer &getASTConsumer() const { return Consumer; }
0535 ASTMutationListener *getASTMutationListener() const;
0536 ExternalSemaSource *getExternalSource() const { return ExternalSource.get(); }
0537
0538 DarwinSDKInfo *getDarwinSDKInfoForAvailabilityChecking(SourceLocation Loc,
0539 StringRef Platform);
0540 DarwinSDKInfo *getDarwinSDKInfoForAvailabilityChecking();
0541
0542
0543
0544
0545
0546
0547 void addExternalSource(ExternalSemaSource *E);
0548
0549
0550 void PrintStats() const;
0551
0552
0553
0554
0555
0556 void runWithSufficientStackSpace(SourceLocation Loc,
0557 llvm::function_ref<void()> Fn);
0558
0559
0560 LangAS getDefaultCXXMethodAddrSpace() const;
0561
0562
0563 void LoadExternalWeakUndeclaredIdentifiers();
0564
0565
0566
0567
0568 bool isExternalWithNoLinkageType(const ValueDecl *VD) const;
0569
0570
0571 void getUndefinedButUsed(
0572 SmallVectorImpl<std::pair<NamedDecl *, SourceLocation>> &Undefined);
0573
0574 typedef std::pair<SourceLocation, bool> DeleteExprLoc;
0575 typedef llvm::SmallVector<DeleteExprLoc, 4> DeleteLocs;
0576
0577
0578 const llvm::MapVector<FieldDecl *, DeleteLocs> &
0579 getMismatchingDeleteExpressions() const;
0580
0581
0582
0583
0584 void EmitDiagnostic(unsigned DiagID, const DiagnosticBuilder &DB);
0585
0586 void addImplicitTypedef(StringRef Name, QualType T);
0587
0588
0589
0590 bool hasUncompilableErrorOccurred() const;
0591
0592
0593
0594
0595
0596 bool findMacroSpelling(SourceLocation &loc, StringRef name);
0597
0598
0599 SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset = 0);
0600
0601
0602 ModuleLoader &getModuleLoader() const;
0603
0604
0605 IdentifierInfo *
0606 InventAbbreviatedTemplateParameterTypeName(const IdentifierInfo *ParamName,
0607 unsigned Index);
0608
0609 void emitAndClearUnusedLocalTypedefWarnings();
0610
0611
0612 void emitDeferredDiags();
0613
0614 enum TUFragmentKind {
0615
0616 Global,
0617
0618
0619
0620 Normal,
0621
0622
0623 Private
0624 };
0625
0626
0627
0628
0629 void ActOnStartOfTranslationUnit();
0630
0631
0632
0633 void ActOnEndOfTranslationUnit();
0634 void ActOnEndOfTranslationUnitFragment(TUFragmentKind Kind);
0635
0636
0637
0638
0639
0640
0641
0642
0643
0644
0645
0646
0647 Scope *getScopeForContext(DeclContext *Ctx);
0648
0649 void PushFunctionScope();
0650 void PushBlockScope(Scope *BlockScope, BlockDecl *Block);
0651 sema::LambdaScopeInfo *PushLambdaScope();
0652
0653
0654
0655
0656 void RecordParsingTemplateParameterDepth(unsigned Depth);
0657
0658 void PushCapturedRegionScope(Scope *RegionScope, CapturedDecl *CD,
0659 RecordDecl *RD, CapturedRegionKind K,
0660 unsigned OpenMPCaptureLevel = 0);
0661
0662
0663
0664 class PoppedFunctionScopeDeleter {
0665 Sema *Self;
0666
0667 public:
0668 explicit PoppedFunctionScopeDeleter(Sema *Self) : Self(Self) {}
0669 void operator()(sema::FunctionScopeInfo *Scope) const;
0670 };
0671
0672 using PoppedFunctionScopePtr =
0673 std::unique_ptr<sema::FunctionScopeInfo, PoppedFunctionScopeDeleter>;
0674
0675
0676
0677
0678
0679
0680
0681
0682
0683 PoppedFunctionScopePtr
0684 PopFunctionScopeInfo(const sema::AnalysisBasedWarnings::Policy *WP = nullptr,
0685 const Decl *D = nullptr,
0686 QualType BlockType = QualType());
0687
0688 sema::FunctionScopeInfo *getEnclosingFunction() const;
0689
0690 void setFunctionHasBranchIntoScope();
0691 void setFunctionHasBranchProtectedScope();
0692 void setFunctionHasIndirectGoto();
0693 void setFunctionHasMustTail();
0694
0695 void PushCompoundScope(bool IsStmtExpr);
0696 void PopCompoundScope();
0697
0698
0699
0700 bool hasAnyUnrecoverableErrorsInThisFunction() const;
0701
0702
0703 sema::BlockScopeInfo *getCurBlock();
0704
0705
0706
0707
0708 sema::CapturingScopeInfo *getEnclosingLambdaOrBlock() const;
0709
0710
0711
0712
0713
0714 sema::LambdaScopeInfo *
0715 getCurLambda(bool IgnoreNonLambdaCapturingScope = false);
0716
0717
0718 sema::LambdaScopeInfo *getCurGenericLambda();
0719
0720
0721 sema::CapturedRegionScopeInfo *getCurCapturedRegion();
0722
0723 void ActOnComment(SourceRange Comment);
0724
0725
0726
0727
0728
0729
0730
0731
0732
0733 Scope *getCurScope() const { return CurScope; }
0734
0735 IdentifierInfo *getSuperIdentifier() const;
0736
0737 DeclContext *getCurLexicalContext() const {
0738 return OriginalLexicalContext ? OriginalLexicalContext : CurContext;
0739 }
0740
0741 SemaDiagnosticBuilder targetDiag(SourceLocation Loc, unsigned DiagID,
0742 const FunctionDecl *FD = nullptr);
0743 SemaDiagnosticBuilder targetDiag(SourceLocation Loc,
0744 const PartialDiagnostic &PD,
0745 const FunctionDecl *FD = nullptr) {
0746 return targetDiag(Loc, PD.getDiagID(), FD) << PD;
0747 }
0748
0749
0750 void checkTypeSupport(QualType Ty, SourceLocation Loc,
0751 ValueDecl *D = nullptr);
0752
0753
0754
0755
0756
0757
0758
0759
0760
0761
0762
0763
0764
0765
0766
0767
0768
0769
0770 ExprResult ImpCastExprToType(
0771 Expr *E, QualType Type, CastKind CK, ExprValueKind VK = VK_PRValue,
0772 const CXXCastPath *BasePath = nullptr,
0773 CheckedConversionKind CCK = CheckedConversionKind::Implicit);
0774
0775
0776
0777 static CastKind ScalarTypeToBooleanCastKind(QualType ScalarTy);
0778
0779
0780 DeclContext *getFunctionLevelDeclContext(bool AllowLambda = false) const;
0781
0782
0783
0784
0785
0786 FunctionDecl *getCurFunctionDecl(bool AllowLambda = false) const;
0787
0788
0789
0790
0791 ObjCMethodDecl *getCurMethodDecl();
0792
0793
0794
0795
0796 NamedDecl *getCurFunctionOrMethodDecl() const;
0797
0798
0799
0800 void diagnoseNullableToNonnullConversion(QualType DstType, QualType SrcType,
0801 SourceLocation Loc);
0802
0803
0804 void diagnoseZeroToNullptrConversion(CastKind Kind, const Expr *E);
0805
0806
0807 void diagnoseFunctionEffectConversion(QualType DstType, QualType SrcType,
0808 SourceLocation Loc);
0809
0810
0811
0812
0813
0814 bool makeUnavailableInSystemHeader(SourceLocation loc,
0815 UnavailableAttr::ImplicitReason reason);
0816
0817
0818 PrintingPolicy getPrintingPolicy() const {
0819 return getPrintingPolicy(Context, PP);
0820 }
0821
0822
0823 static PrintingPolicy getPrintingPolicy(const ASTContext &Ctx,
0824 const Preprocessor &PP);
0825
0826
0827 void ActOnTranslationUnitScope(Scope *S);
0828
0829
0830
0831 bool isDeclaratorFunctionLike(Declarator &D);
0832
0833
0834
0835
0836
0837
0838
0839
0840 static const unsigned MaxAlignmentExponent = 32;
0841 static const uint64_t MaximumAlignment = 1ull << MaxAlignmentExponent;
0842
0843
0844 bool CollectStats;
0845
0846 std::unique_ptr<sema::FunctionScopeInfo> CachedFunctionScope;
0847
0848
0849
0850 SmallVector<sema::FunctionScopeInfo *, 4> FunctionScopes;
0851
0852
0853
0854 unsigned FunctionScopesStart = 0;
0855
0856
0857 unsigned CapturingFunctionScopes = 0;
0858
0859 llvm::BumpPtrAllocator BumpAlloc;
0860
0861
0862
0863
0864
0865
0866
0867
0868 const TranslationUnitKind TUKind;
0869
0870
0871
0872
0873 Scope *TUScope;
0874
0875 void incrementMSManglingNumber() const {
0876 return CurScope->incrementMSManglingNumber();
0877 }
0878
0879
0880
0881
0882 bool tryToRecoverWithCall(ExprResult &E, const PartialDiagnostic &PD,
0883 bool ForceComplain = false,
0884 bool (*IsPlausibleResult)(QualType) = nullptr);
0885
0886
0887
0888
0889
0890
0891
0892
0893
0894
0895
0896
0897
0898 bool tryExprAsCall(Expr &E, QualType &ZeroArgCallReturnTy,
0899 UnresolvedSetImpl &NonTemplateOverloads);
0900
0901 typedef OpaquePtr<DeclGroupRef> DeclGroupPtrTy;
0902 typedef OpaquePtr<TemplateName> TemplateTy;
0903 typedef OpaquePtr<QualType> TypeTy;
0904
0905 OpenCLOptions OpenCLFeatures;
0906 FPOptions CurFPFeatures;
0907
0908 const LangOptions &LangOpts;
0909 Preprocessor &PP;
0910 ASTContext &Context;
0911 ASTConsumer &Consumer;
0912 DiagnosticsEngine &Diags;
0913 SourceManager &SourceMgr;
0914 api_notes::APINotesManager APINotes;
0915
0916
0917 class CompoundScopeRAII {
0918 public:
0919 CompoundScopeRAII(Sema &S, bool IsStmtExpr = false) : S(S) {
0920 S.ActOnStartOfCompoundStmt(IsStmtExpr);
0921 }
0922
0923 ~CompoundScopeRAII() { S.ActOnFinishOfCompoundStmt(); }
0924
0925 private:
0926 Sema &S;
0927 };
0928
0929
0930 struct FunctionScopeRAII {
0931 Sema &S;
0932 bool Active;
0933 FunctionScopeRAII(Sema &S) : S(S), Active(true) {}
0934 ~FunctionScopeRAII() {
0935 if (Active)
0936 S.PopFunctionScopeInfo();
0937 }
0938 void disable() { Active = false; }
0939 };
0940
0941 sema::FunctionScopeInfo *getCurFunction() const {
0942 return FunctionScopes.empty() ? nullptr : FunctionScopes.back();
0943 }
0944
0945
0946 sema::AnalysisBasedWarnings AnalysisWarnings;
0947 threadSafety::BeforeSet *ThreadSafetyDeclCache;
0948
0949
0950 typedef void LateTemplateParserCB(void *P, LateParsedTemplate &LPT);
0951 typedef void LateTemplateParserCleanupCB(void *P);
0952 LateTemplateParserCB *LateTemplateParser;
0953 LateTemplateParserCleanupCB *LateTemplateParserCleanup;
0954 void *OpaqueParser;
0955
0956 void SetLateTemplateParser(LateTemplateParserCB *LTP,
0957 LateTemplateParserCleanupCB *LTPCleanup, void *P) {
0958 LateTemplateParser = LTP;
0959 LateTemplateParserCleanup = LTPCleanup;
0960 OpaqueParser = P;
0961 }
0962
0963
0964 std::function<TypeResult(StringRef, StringRef, SourceLocation)>
0965 ParseTypeFromStringCallback;
0966
0967
0968
0969 DeclarationName VAListTagName;
0970
0971
0972
0973 bool IsLastErrorImmediate = true;
0974
0975 class DelayedDiagnostics;
0976
0977 class DelayedDiagnosticsState {
0978 sema::DelayedDiagnosticPool *SavedPool = nullptr;
0979 friend class Sema::DelayedDiagnostics;
0980 };
0981 typedef DelayedDiagnosticsState ParsingDeclState;
0982 typedef DelayedDiagnosticsState ProcessingContextState;
0983
0984
0985
0986 class DelayedDiagnostics {
0987
0988
0989 sema::DelayedDiagnosticPool *CurPool = nullptr;
0990
0991 public:
0992 DelayedDiagnostics() = default;
0993
0994
0995 void add(const sema::DelayedDiagnostic &diag);
0996
0997
0998 bool shouldDelayDiagnostics() { return CurPool != nullptr; }
0999
1000
1001 sema::DelayedDiagnosticPool *getCurrentPool() const { return CurPool; }
1002
1003
1004
1005 DelayedDiagnosticsState push(sema::DelayedDiagnosticPool &pool) {
1006 DelayedDiagnosticsState state;
1007 state.SavedPool = CurPool;
1008 CurPool = &pool;
1009 return state;
1010 }
1011
1012
1013
1014
1015 void popWithoutEmitting(DelayedDiagnosticsState state) {
1016 CurPool = state.SavedPool;
1017 }
1018
1019
1020
1021 DelayedDiagnosticsState pushUndelayed() {
1022 DelayedDiagnosticsState state;
1023 state.SavedPool = CurPool;
1024 CurPool = nullptr;
1025 return state;
1026 }
1027
1028
1029 void popUndelayed(DelayedDiagnosticsState state) {
1030 assert(CurPool == nullptr);
1031 CurPool = state.SavedPool;
1032 }
1033 } DelayedDiagnostics;
1034
1035 ParsingDeclState PushParsingDeclaration(sema::DelayedDiagnosticPool &pool) {
1036 return DelayedDiagnostics.push(pool);
1037 }
1038
1039
1040
1041
1042 SemaDiagnosticBuilder::DeferredDiagnosticsType DeviceDeferredDiags;
1043
1044
1045 DeclContext *CurContext;
1046
1047 SemaAMDGPU &AMDGPU() {
1048 assert(AMDGPUPtr);
1049 return *AMDGPUPtr;
1050 }
1051
1052 SemaARM &ARM() {
1053 assert(ARMPtr);
1054 return *ARMPtr;
1055 }
1056
1057 SemaAVR &AVR() {
1058 assert(AVRPtr);
1059 return *AVRPtr;
1060 }
1061
1062 SemaBPF &BPF() {
1063 assert(BPFPtr);
1064 return *BPFPtr;
1065 }
1066
1067 SemaCodeCompletion &CodeCompletion() {
1068 assert(CodeCompletionPtr);
1069 return *CodeCompletionPtr;
1070 }
1071
1072 SemaCUDA &CUDA() {
1073 assert(CUDAPtr);
1074 return *CUDAPtr;
1075 }
1076
1077 SemaHLSL &HLSL() {
1078 assert(HLSLPtr);
1079 return *HLSLPtr;
1080 }
1081
1082 SemaHexagon &Hexagon() {
1083 assert(HexagonPtr);
1084 return *HexagonPtr;
1085 }
1086
1087 SemaLoongArch &LoongArch() {
1088 assert(LoongArchPtr);
1089 return *LoongArchPtr;
1090 }
1091
1092 SemaM68k &M68k() {
1093 assert(M68kPtr);
1094 return *M68kPtr;
1095 }
1096
1097 SemaMIPS &MIPS() {
1098 assert(MIPSPtr);
1099 return *MIPSPtr;
1100 }
1101
1102 SemaMSP430 &MSP430() {
1103 assert(MSP430Ptr);
1104 return *MSP430Ptr;
1105 }
1106
1107 SemaNVPTX &NVPTX() {
1108 assert(NVPTXPtr);
1109 return *NVPTXPtr;
1110 }
1111
1112 SemaObjC &ObjC() {
1113 assert(ObjCPtr);
1114 return *ObjCPtr;
1115 }
1116
1117 SemaOpenACC &OpenACC() {
1118 assert(OpenACCPtr);
1119 return *OpenACCPtr;
1120 }
1121
1122 SemaOpenCL &OpenCL() {
1123 assert(OpenCLPtr);
1124 return *OpenCLPtr;
1125 }
1126
1127 SemaOpenMP &OpenMP() {
1128 assert(OpenMPPtr && "SemaOpenMP is dead");
1129 return *OpenMPPtr;
1130 }
1131
1132 SemaPPC &PPC() {
1133 assert(PPCPtr);
1134 return *PPCPtr;
1135 }
1136
1137 SemaPseudoObject &PseudoObject() {
1138 assert(PseudoObjectPtr);
1139 return *PseudoObjectPtr;
1140 }
1141
1142 SemaRISCV &RISCV() {
1143 assert(RISCVPtr);
1144 return *RISCVPtr;
1145 }
1146
1147 SemaSPIRV &SPIRV() {
1148 assert(SPIRVPtr);
1149 return *SPIRVPtr;
1150 }
1151
1152 SemaSYCL &SYCL() {
1153 assert(SYCLPtr);
1154 return *SYCLPtr;
1155 }
1156
1157 SemaSwift &Swift() {
1158 assert(SwiftPtr);
1159 return *SwiftPtr;
1160 }
1161
1162 SemaSystemZ &SystemZ() {
1163 assert(SystemZPtr);
1164 return *SystemZPtr;
1165 }
1166
1167 SemaWasm &Wasm() {
1168 assert(WasmPtr);
1169 return *WasmPtr;
1170 }
1171
1172 SemaX86 &X86() {
1173 assert(X86Ptr);
1174 return *X86Ptr;
1175 }
1176
1177
1178 IntrusiveRefCntPtr<ExternalSemaSource> ExternalSource;
1179
1180 protected:
1181 friend class Parser;
1182 friend class InitializationSequence;
1183 friend class ASTReader;
1184 friend class ASTDeclReader;
1185 friend class ASTWriter;
1186
1187 private:
1188 std::optional<std::unique_ptr<DarwinSDKInfo>> CachedDarwinSDKInfo;
1189 bool WarnedDarwinSDKInfoMissing = false;
1190
1191 StackExhaustionHandler StackHandler;
1192
1193 Sema(const Sema &) = delete;
1194 void operator=(const Sema &) = delete;
1195
1196
1197
1198
1199
1200 sema::SemaPPCallbacks *SemaPPCallbackHandler;
1201
1202
1203
1204
1205 Scope *CurScope;
1206
1207 mutable IdentifierInfo *Ident_super;
1208
1209 std::unique_ptr<SemaAMDGPU> AMDGPUPtr;
1210 std::unique_ptr<SemaARM> ARMPtr;
1211 std::unique_ptr<SemaAVR> AVRPtr;
1212 std::unique_ptr<SemaBPF> BPFPtr;
1213 std::unique_ptr<SemaCodeCompletion> CodeCompletionPtr;
1214 std::unique_ptr<SemaCUDA> CUDAPtr;
1215 std::unique_ptr<SemaHLSL> HLSLPtr;
1216 std::unique_ptr<SemaHexagon> HexagonPtr;
1217 std::unique_ptr<SemaLoongArch> LoongArchPtr;
1218 std::unique_ptr<SemaM68k> M68kPtr;
1219 std::unique_ptr<SemaMIPS> MIPSPtr;
1220 std::unique_ptr<SemaMSP430> MSP430Ptr;
1221 std::unique_ptr<SemaNVPTX> NVPTXPtr;
1222 std::unique_ptr<SemaObjC> ObjCPtr;
1223 std::unique_ptr<SemaOpenACC> OpenACCPtr;
1224 std::unique_ptr<SemaOpenCL> OpenCLPtr;
1225 std::unique_ptr<SemaOpenMP> OpenMPPtr;
1226 std::unique_ptr<SemaPPC> PPCPtr;
1227 std::unique_ptr<SemaPseudoObject> PseudoObjectPtr;
1228 std::unique_ptr<SemaRISCV> RISCVPtr;
1229 std::unique_ptr<SemaSPIRV> SPIRVPtr;
1230 std::unique_ptr<SemaSYCL> SYCLPtr;
1231 std::unique_ptr<SemaSwift> SwiftPtr;
1232 std::unique_ptr<SemaSystemZ> SystemZPtr;
1233 std::unique_ptr<SemaWasm> WasmPtr;
1234 std::unique_ptr<SemaX86> X86Ptr;
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248 public:
1249
1250
1251
1252
1253 void ProcessAPINotes(Decl *D);
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267 public:
1268 enum AccessResult {
1269 AR_accessible,
1270 AR_inaccessible,
1271 AR_dependent,
1272 AR_delayed
1273 };
1274
1275
1276
1277
1278 bool SetMemberAccessSpecifier(NamedDecl *MemberDecl,
1279 NamedDecl *PrevMemberDecl,
1280 AccessSpecifier LexicalAS);
1281
1282
1283
1284 AccessResult CheckUnresolvedMemberAccess(UnresolvedMemberExpr *E,
1285 DeclAccessPair FoundDecl);
1286 AccessResult CheckUnresolvedLookupAccess(UnresolvedLookupExpr *E,
1287 DeclAccessPair FoundDecl);
1288
1289
1290 AccessResult CheckAllocationAccess(SourceLocation OperatorLoc,
1291 SourceRange PlacementRange,
1292 CXXRecordDecl *NamingClass,
1293 DeclAccessPair FoundDecl,
1294 bool Diagnose = true);
1295
1296
1297 AccessResult CheckConstructorAccess(SourceLocation Loc, CXXConstructorDecl *D,
1298 DeclAccessPair FoundDecl,
1299 const InitializedEntity &Entity,
1300 bool IsCopyBindingRefToTemp = false);
1301
1302
1303 AccessResult CheckConstructorAccess(SourceLocation Loc, CXXConstructorDecl *D,
1304 DeclAccessPair FoundDecl,
1305 const InitializedEntity &Entity,
1306 const PartialDiagnostic &PDiag);
1307 AccessResult CheckDestructorAccess(SourceLocation Loc,
1308 CXXDestructorDecl *Dtor,
1309 const PartialDiagnostic &PDiag,
1310 QualType objectType = QualType());
1311
1312
1313 AccessResult CheckFriendAccess(NamedDecl *D);
1314
1315
1316 AccessResult CheckMemberAccess(SourceLocation UseLoc,
1317 CXXRecordDecl *NamingClass,
1318 DeclAccessPair Found);
1319
1320
1321 AccessResult
1322 CheckStructuredBindingMemberAccess(SourceLocation UseLoc,
1323 CXXRecordDecl *DecomposedClass,
1324 DeclAccessPair Field);
1325 AccessResult CheckMemberOperatorAccess(SourceLocation Loc, Expr *ObjectExpr,
1326 const SourceRange &,
1327 DeclAccessPair FoundDecl);
1328
1329
1330
1331 AccessResult CheckMemberOperatorAccess(SourceLocation Loc, Expr *ObjectExpr,
1332 Expr *ArgExpr,
1333 DeclAccessPair FoundDecl);
1334 AccessResult CheckMemberOperatorAccess(SourceLocation Loc, Expr *ObjectExpr,
1335 ArrayRef<Expr *> ArgExprs,
1336 DeclAccessPair FoundDecl);
1337 AccessResult CheckAddressOfMemberAccess(Expr *OvlExpr,
1338 DeclAccessPair FoundDecl);
1339
1340
1341
1342
1343
1344
1345
1346 AccessResult CheckBaseClassAccess(SourceLocation AccessLoc, QualType Base,
1347 QualType Derived, const CXXBasePath &Path,
1348 unsigned DiagID, bool ForceCheck = false,
1349 bool ForceUnprivileged = false);
1350
1351
1352 void CheckLookupAccess(const LookupResult &R);
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371 bool IsSimplyAccessible(NamedDecl *Decl, CXXRecordDecl *NamingClass,
1372 QualType BaseType);
1373
1374
1375
1376 bool isMemberAccessibleForDeletion(CXXRecordDecl *NamingClass,
1377 DeclAccessPair Found, QualType ObjectType,
1378 SourceLocation Loc,
1379 const PartialDiagnostic &Diag);
1380 bool isMemberAccessibleForDeletion(CXXRecordDecl *NamingClass,
1381 DeclAccessPair Found,
1382 QualType ObjectType) {
1383 return isMemberAccessibleForDeletion(NamingClass, Found, ObjectType,
1384 SourceLocation(), PDiag());
1385 }
1386
1387 void HandleDependentAccessCheck(
1388 const DependentDiagnostic &DD,
1389 const MultiLevelTemplateArgumentList &TemplateArgs);
1390 void HandleDelayedAccessCheck(sema::DelayedDiagnostic &DD, Decl *Ctx);
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404 public:
1405
1406 LangOptions::PragmaMSPointersToMembersKind
1407 MSPointerToMemberRepresentationMethod;
1408
1409 bool MSStructPragmaOn;
1410
1411
1412 SourceLocation ImplicitMSInheritanceAttrLoc;
1413
1414
1415 enum PragmaClangSectionKind {
1416 PCSK_Invalid = 0,
1417 PCSK_BSS = 1,
1418 PCSK_Data = 2,
1419 PCSK_Rodata = 3,
1420 PCSK_Text = 4,
1421 PCSK_Relro = 5
1422 };
1423
1424 enum PragmaClangSectionAction { PCSA_Set = 0, PCSA_Clear = 1 };
1425
1426 struct PragmaClangSection {
1427 std::string SectionName;
1428 bool Valid = false;
1429 SourceLocation PragmaLocation;
1430 };
1431
1432 PragmaClangSection PragmaClangBSSSection;
1433 PragmaClangSection PragmaClangDataSection;
1434 PragmaClangSection PragmaClangRodataSection;
1435 PragmaClangSection PragmaClangRelroSection;
1436 PragmaClangSection PragmaClangTextSection;
1437
1438 enum PragmaMsStackAction {
1439 PSK_Reset = 0x0,
1440 PSK_Set = 0x1,
1441 PSK_Push = 0x2,
1442 PSK_Pop = 0x4,
1443 PSK_Show = 0x8,
1444 PSK_Push_Set = PSK_Push | PSK_Set,
1445 PSK_Pop_Set = PSK_Pop | PSK_Set,
1446 };
1447
1448 struct PragmaPackInfo {
1449 PragmaMsStackAction Action;
1450 StringRef SlotLabel;
1451 Token Alignment;
1452 };
1453
1454
1455 class AlignPackInfo {
1456 public:
1457
1458
1459 enum Mode : unsigned char { Native, Natural, Packed, Mac68k };
1460
1461
1462 AlignPackInfo(AlignPackInfo::Mode M, unsigned Num, bool IsXL)
1463 : PackAttr(true), AlignMode(M), PackNumber(Num), XLStack(IsXL) {
1464 assert(Num == PackNumber && "The pack number has been truncated.");
1465 }
1466
1467
1468 AlignPackInfo(AlignPackInfo::Mode M, bool IsXL)
1469 : PackAttr(false), AlignMode(M),
1470 PackNumber(M == Packed ? 1 : UninitPackVal), XLStack(IsXL) {}
1471
1472 explicit AlignPackInfo(bool IsXL) : AlignPackInfo(Native, IsXL) {}
1473
1474 AlignPackInfo() : AlignPackInfo(Native, false) {}
1475
1476
1477
1478
1479 static uint32_t getRawEncoding(const AlignPackInfo &Info) {
1480 std::uint32_t Encoding{};
1481 if (Info.IsXLStack())
1482 Encoding |= IsXLMask;
1483
1484 Encoding |= static_cast<uint32_t>(Info.getAlignMode()) << 1;
1485
1486 if (Info.IsPackAttr())
1487 Encoding |= PackAttrMask;
1488
1489 Encoding |= static_cast<uint32_t>(Info.getPackNumber()) << 4;
1490
1491 return Encoding;
1492 }
1493
1494 static AlignPackInfo getFromRawEncoding(unsigned Encoding) {
1495 bool IsXL = static_cast<bool>(Encoding & IsXLMask);
1496 AlignPackInfo::Mode M =
1497 static_cast<AlignPackInfo::Mode>((Encoding & AlignModeMask) >> 1);
1498 int PackNumber = (Encoding & PackNumMask) >> 4;
1499
1500 if (Encoding & PackAttrMask)
1501 return AlignPackInfo(M, PackNumber, IsXL);
1502
1503 return AlignPackInfo(M, IsXL);
1504 }
1505
1506 bool IsPackAttr() const { return PackAttr; }
1507
1508 bool IsAlignAttr() const { return !PackAttr; }
1509
1510 Mode getAlignMode() const { return AlignMode; }
1511
1512 unsigned getPackNumber() const { return PackNumber; }
1513
1514 bool IsPackSet() const {
1515
1516
1517 return PackNumber != UninitPackVal && PackNumber != 0;
1518 }
1519
1520 bool IsXLStack() const { return XLStack; }
1521
1522 bool operator==(const AlignPackInfo &Info) const {
1523 return std::tie(AlignMode, PackNumber, PackAttr, XLStack) ==
1524 std::tie(Info.AlignMode, Info.PackNumber, Info.PackAttr,
1525 Info.XLStack);
1526 }
1527
1528 bool operator!=(const AlignPackInfo &Info) const {
1529 return !(*this == Info);
1530 }
1531
1532 private:
1533
1534
1535 bool PackAttr;
1536
1537
1538 Mode AlignMode;
1539
1540
1541 unsigned char PackNumber;
1542
1543
1544 bool XLStack;
1545
1546
1547 static constexpr unsigned char UninitPackVal = -1;
1548
1549
1550 static constexpr uint32_t IsXLMask{0x0000'0001};
1551 static constexpr uint32_t AlignModeMask{0x0000'0006};
1552 static constexpr uint32_t PackAttrMask{0x00000'0008};
1553 static constexpr uint32_t PackNumMask{0x0000'01F0};
1554 };
1555
1556 template <typename ValueType> struct PragmaStack {
1557 struct Slot {
1558 llvm::StringRef StackSlotLabel;
1559 ValueType Value;
1560 SourceLocation PragmaLocation;
1561 SourceLocation PragmaPushLocation;
1562 Slot(llvm::StringRef StackSlotLabel, ValueType Value,
1563 SourceLocation PragmaLocation, SourceLocation PragmaPushLocation)
1564 : StackSlotLabel(StackSlotLabel), Value(Value),
1565 PragmaLocation(PragmaLocation),
1566 PragmaPushLocation(PragmaPushLocation) {}
1567 };
1568
1569 void Act(SourceLocation PragmaLocation, PragmaMsStackAction Action,
1570 llvm::StringRef StackSlotLabel, ValueType Value) {
1571 if (Action == PSK_Reset) {
1572 CurrentValue = DefaultValue;
1573 CurrentPragmaLocation = PragmaLocation;
1574 return;
1575 }
1576 if (Action & PSK_Push)
1577 Stack.emplace_back(StackSlotLabel, CurrentValue, CurrentPragmaLocation,
1578 PragmaLocation);
1579 else if (Action & PSK_Pop) {
1580 if (!StackSlotLabel.empty()) {
1581
1582 auto I = llvm::find_if(llvm::reverse(Stack), [&](const Slot &x) {
1583 return x.StackSlotLabel == StackSlotLabel;
1584 });
1585
1586 if (I != Stack.rend()) {
1587 CurrentValue = I->Value;
1588 CurrentPragmaLocation = I->PragmaLocation;
1589 Stack.erase(std::prev(I.base()), Stack.end());
1590 }
1591 } else if (!Stack.empty()) {
1592
1593 CurrentValue = Stack.back().Value;
1594 CurrentPragmaLocation = Stack.back().PragmaLocation;
1595 Stack.pop_back();
1596 }
1597 }
1598 if (Action & PSK_Set) {
1599 CurrentValue = Value;
1600 CurrentPragmaLocation = PragmaLocation;
1601 }
1602 }
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618 void SentinelAction(PragmaMsStackAction Action, StringRef Label) {
1619 assert((Action == PSK_Push || Action == PSK_Pop) &&
1620 "Can only push / pop #pragma stack sentinels!");
1621 Act(CurrentPragmaLocation, Action, Label, CurrentValue);
1622 }
1623
1624
1625 explicit PragmaStack(const ValueType &Default)
1626 : DefaultValue(Default), CurrentValue(Default) {}
1627
1628 bool hasValue() const { return CurrentValue != DefaultValue; }
1629
1630 SmallVector<Slot, 2> Stack;
1631 ValueType DefaultValue;
1632 ValueType CurrentValue;
1633 SourceLocation CurrentPragmaLocation;
1634 };
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646 PragmaStack<MSVtorDispMode> VtorDispStack;
1647 PragmaStack<AlignPackInfo> AlignPackStack;
1648
1649 struct AlignPackIncludeState {
1650 AlignPackInfo CurrentValue;
1651 SourceLocation CurrentPragmaLocation;
1652 bool HasNonDefaultValue, ShouldWarnOnInclude;
1653 };
1654 SmallVector<AlignPackIncludeState, 8> AlignPackIncludeStack;
1655
1656 PragmaStack<StringLiteral *> DataSegStack;
1657 PragmaStack<StringLiteral *> BSSSegStack;
1658 PragmaStack<StringLiteral *> ConstSegStack;
1659 PragmaStack<StringLiteral *> CodeSegStack;
1660
1661
1662 PragmaStack<bool> StrictGuardStackCheckStack;
1663
1664
1665 PragmaStack<FPOptionsOverride> FpPragmaStack;
1666 FPOptionsOverride CurFPFeatureOverrides() {
1667 FPOptionsOverride result;
1668 if (!FpPragmaStack.hasValue()) {
1669 result = FPOptionsOverride();
1670 } else {
1671 result = FpPragmaStack.CurrentValue;
1672 }
1673 return result;
1674 }
1675
1676 enum PragmaSectionKind {
1677 PSK_DataSeg,
1678 PSK_BSSSeg,
1679 PSK_ConstSeg,
1680 PSK_CodeSeg,
1681 };
1682
1683
1684
1685 class PragmaStackSentinelRAII {
1686 public:
1687 PragmaStackSentinelRAII(Sema &S, StringRef SlotLabel, bool ShouldAct);
1688 ~PragmaStackSentinelRAII();
1689
1690 private:
1691 Sema &S;
1692 StringRef SlotLabel;
1693 bool ShouldAct;
1694 };
1695
1696
1697 StringLiteral *CurInitSeg;
1698 SourceLocation CurInitSegLoc;
1699
1700
1701 llvm::StringMap<std::tuple<StringRef, SourceLocation>> FunctionToSectionMap;
1702
1703
1704 void *VisContext;
1705
1706
1707 struct PragmaAttributeEntry {
1708 SourceLocation Loc;
1709 ParsedAttr *Attribute;
1710 SmallVector<attr::SubjectMatchRule, 4> MatchRules;
1711 bool IsUsed;
1712 };
1713
1714
1715 struct PragmaAttributeGroup {
1716
1717 SourceLocation Loc;
1718
1719 const IdentifierInfo *Namespace;
1720 SmallVector<PragmaAttributeEntry, 2> Entries;
1721 };
1722
1723 SmallVector<PragmaAttributeGroup, 2> PragmaAttributeStack;
1724
1725
1726
1727 const Decl *PragmaAttributeCurrentTargetDecl;
1728
1729
1730
1731
1732 SourceLocation OptimizeOffPragmaLocation;
1733
1734
1735
1736 SourceLocation getOptimizeOffPragmaLocation() const {
1737 return OptimizeOffPragmaLocation;
1738 }
1739
1740
1741
1742
1743
1744
1745 bool MSPragmaOptimizeIsOn = true;
1746
1747
1748 llvm::SmallSetVector<StringRef, 4> MSFunctionNoBuiltins;
1749
1750
1751
1752 void AddAlignmentAttributesForRecord(RecordDecl *RD);
1753
1754
1755 void AddMsStructLayoutForRecord(RecordDecl *RD);
1756
1757
1758
1759
1760 void inferGslPointerAttribute(NamedDecl *ND, CXXRecordDecl *UnderlyingRecord);
1761
1762
1763 void inferGslOwnerPointerAttribute(CXXRecordDecl *Record);
1764
1765
1766 void inferLifetimeBoundAttribute(FunctionDecl *FD);
1767
1768
1769 void inferLifetimeCaptureByAttribute(FunctionDecl *FD);
1770
1771
1772 void inferGslPointerAttribute(TypedefNameDecl *TD);
1773
1774 LifetimeCaptureByAttr *ParseLifetimeCaptureByAttr(const ParsedAttr &AL,
1775 StringRef ParamName);
1776
1777
1778
1779
1780 void LazyProcessLifetimeCaptureByParams(FunctionDecl *FD);
1781
1782
1783 void inferNullableClassAttribute(CXXRecordDecl *CRD);
1784
1785 enum PragmaOptionsAlignKind {
1786 POAK_Native,
1787 POAK_Natural,
1788 POAK_Packed,
1789 POAK_Power,
1790 POAK_Mac68k,
1791 POAK_Reset
1792 };
1793
1794
1795 void ActOnPragmaClangSection(SourceLocation PragmaLoc,
1796 PragmaClangSectionAction Action,
1797 PragmaClangSectionKind SecKind,
1798 StringRef SecName);
1799
1800
1801 void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind,
1802 SourceLocation PragmaLoc);
1803
1804
1805 void ActOnPragmaPack(SourceLocation PragmaLoc, PragmaMsStackAction Action,
1806 StringRef SlotLabel, Expr *Alignment);
1807
1808
1809
1810
1811
1812 bool ConstantFoldAttrArgs(const AttributeCommonInfo &CI,
1813 MutableArrayRef<Expr *> Args);
1814
1815 enum class PragmaAlignPackDiagnoseKind {
1816 NonDefaultStateAtInclude,
1817 ChangedStateAtExit
1818 };
1819
1820 void DiagnoseNonDefaultPragmaAlignPack(PragmaAlignPackDiagnoseKind Kind,
1821 SourceLocation IncludeLoc);
1822 void DiagnoseUnterminatedPragmaAlignPack();
1823
1824
1825 void ActOnPragmaMSStruct(PragmaMSStructKind Kind);
1826
1827
1828
1829 void ActOnPragmaMSComment(SourceLocation CommentLoc, PragmaMSCommentKind Kind,
1830 StringRef Arg);
1831
1832
1833 void ActOnPragmaDetectMismatch(SourceLocation Loc, StringRef Name,
1834 StringRef Value);
1835
1836
1837 bool isPreciseFPEnabled() {
1838 return !CurFPFeatures.getAllowFPReassociate() &&
1839 !CurFPFeatures.getNoSignedZero() &&
1840 !CurFPFeatures.getAllowReciprocal() &&
1841 !CurFPFeatures.getAllowApproxFunc();
1842 }
1843
1844 void ActOnPragmaFPEvalMethod(SourceLocation Loc,
1845 LangOptions::FPEvalMethodKind Value);
1846
1847
1848 void ActOnPragmaFloatControl(SourceLocation Loc, PragmaMsStackAction Action,
1849 PragmaFloatControlKind Value);
1850
1851
1852
1853
1854 void ActOnPragmaMSPointersToMembers(
1855 LangOptions::PragmaMSPointersToMembersKind Kind,
1856 SourceLocation PragmaLoc);
1857
1858
1859 void ActOnPragmaMSVtorDisp(PragmaMsStackAction Action,
1860 SourceLocation PragmaLoc, MSVtorDispMode Value);
1861
1862 bool UnifySection(StringRef SectionName, int SectionFlags,
1863 NamedDecl *TheDecl);
1864 bool UnifySection(StringRef SectionName, int SectionFlags,
1865 SourceLocation PragmaSectionLocation);
1866
1867
1868 void ActOnPragmaMSSeg(SourceLocation PragmaLocation,
1869 PragmaMsStackAction Action,
1870 llvm::StringRef StackSlotLabel,
1871 StringLiteral *SegmentName, llvm::StringRef PragmaName);
1872
1873
1874 void ActOnPragmaMSSection(SourceLocation PragmaLocation, int SectionFlags,
1875 StringLiteral *SegmentName);
1876
1877
1878 void ActOnPragmaMSInitSeg(SourceLocation PragmaLocation,
1879 StringLiteral *SegmentName);
1880
1881
1882 void ActOnPragmaMSAllocText(
1883 SourceLocation PragmaLocation, StringRef Section,
1884 const SmallVector<std::tuple<IdentifierInfo *, SourceLocation>>
1885 &Functions);
1886
1887
1888
1889 void ActOnPragmaMSStrictGuardStackCheck(SourceLocation PragmaLocation,
1890 PragmaMsStackAction Action,
1891 bool Value);
1892
1893
1894 void ActOnPragmaUnused(const Token &Identifier, Scope *curScope,
1895 SourceLocation PragmaLoc);
1896
1897 void ActOnPragmaAttributeAttribute(ParsedAttr &Attribute,
1898 SourceLocation PragmaLoc,
1899 attr::ParsedSubjectMatchRuleSet Rules);
1900 void ActOnPragmaAttributeEmptyPush(SourceLocation PragmaLoc,
1901 const IdentifierInfo *Namespace);
1902
1903
1904 void ActOnPragmaAttributePop(SourceLocation PragmaLoc,
1905 const IdentifierInfo *Namespace);
1906
1907
1908
1909 void AddPragmaAttributes(Scope *S, Decl *D);
1910
1911 void PrintPragmaAttributeInstantiationPoint();
1912
1913 void DiagnoseUnterminatedPragmaAttribute();
1914
1915
1916 void ActOnPragmaOptimize(bool On, SourceLocation PragmaLoc);
1917
1918
1919 void ActOnPragmaMSOptimize(SourceLocation Loc, bool IsOn);
1920
1921
1922 void
1923 ActOnPragmaMSFunction(SourceLocation Loc,
1924 const llvm::SmallVectorImpl<StringRef> &NoBuiltins);
1925
1926
1927
1928
1929 void AddRangeBasedOptnone(FunctionDecl *FD);
1930
1931
1932
1933
1934 void AddSectionMSAllocText(FunctionDecl *FD);
1935
1936
1937
1938
1939 void AddOptnoneAttributeIfNoConflicts(FunctionDecl *FD, SourceLocation Loc);
1940
1941
1942
1943
1944 void ModifyFnAttributesMSPragmaOptimize(FunctionDecl *FD);
1945
1946
1947
1948
1949 void AddImplicitMSFunctionNoBuiltinAttr(FunctionDecl *FD);
1950
1951
1952
1953 void AddPushedVisibilityAttribute(Decl *RD);
1954
1955
1956 void FreeVisContext();
1957
1958
1959 void ActOnPragmaVisibility(const IdentifierInfo *VisType,
1960 SourceLocation PragmaLoc);
1961
1962
1963
1964
1965 void ActOnPragmaFPContract(SourceLocation Loc, LangOptions::FPModeKind FPC);
1966
1967
1968
1969
1970
1971 void ActOnPragmaFPValueChangingOption(SourceLocation Loc, PragmaFPKind Kind,
1972 bool IsEnabled);
1973
1974
1975
1976 void ActOnPragmaFEnvAccess(SourceLocation Loc, bool IsEnabled);
1977
1978
1979
1980 void ActOnPragmaCXLimitedRange(SourceLocation Loc,
1981 LangOptions::ComplexRangeKind Range);
1982
1983
1984 void ActOnPragmaFPExceptions(SourceLocation Loc,
1985 LangOptions::FPExceptionModeKind);
1986
1987
1988 void ActOnPragmaFEnvRound(SourceLocation Loc, llvm::RoundingMode);
1989
1990
1991 void setExceptionMode(SourceLocation Loc, LangOptions::FPExceptionModeKind);
1992
1993
1994
1995 void PushNamespaceVisibilityAttr(const VisibilityAttr *Attr,
1996 SourceLocation Loc);
1997
1998
1999
2000 void PopPragmaVisibility(bool IsNamespaceEnd, SourceLocation EndLoc);
2001
2002
2003
2004
2005
2006 bool checkCommonAttributeFeatures(const Decl *D, const ParsedAttr &A,
2007 bool SkipArgCountCheck = false);
2008 bool checkCommonAttributeFeatures(const Stmt *S, const ParsedAttr &A,
2009 bool SkipArgCountCheck = false);
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023 public:
2024
2025 void DiagnoseUnguardedAvailabilityViolations(Decl *FD);
2026
2027 void handleDelayedAvailabilityCheck(sema::DelayedDiagnostic &DD, Decl *Ctx);
2028
2029
2030
2031 sema::FunctionScopeInfo *getCurFunctionAvailabilityContext();
2032
2033 void DiagnoseAvailabilityOfDecl(NamedDecl *D, ArrayRef<SourceLocation> Locs,
2034 const ObjCInterfaceDecl *UnknownObjCClass,
2035 bool ObjCPropertyAccess,
2036 bool AvoidPartialAvailabilityChecks = false,
2037 ObjCInterfaceDecl *ClassReceiver = nullptr);
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050 public:
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069 bool CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes,
2070 bool OrNull);
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084 public:
2085 static bool isCast(CheckedConversionKind CCK) {
2086 return CCK == CheckedConversionKind::CStyleCast ||
2087 CCK == CheckedConversionKind::FunctionalCast ||
2088 CCK == CheckedConversionKind::OtherCast;
2089 }
2090
2091
2092
2093 ExprResult ActOnCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind,
2094 SourceLocation LAngleBracketLoc, Declarator &D,
2095 SourceLocation RAngleBracketLoc,
2096 SourceLocation LParenLoc, Expr *E,
2097 SourceLocation RParenLoc);
2098
2099 ExprResult BuildCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind,
2100 TypeSourceInfo *Ty, Expr *E,
2101 SourceRange AngleBrackets, SourceRange Parens);
2102
2103 ExprResult ActOnBuiltinBitCastExpr(SourceLocation KWLoc, Declarator &Dcl,
2104 ExprResult Operand,
2105 SourceLocation RParenLoc);
2106
2107 ExprResult BuildBuiltinBitCastExpr(SourceLocation KWLoc, TypeSourceInfo *TSI,
2108 Expr *Operand, SourceLocation RParenLoc);
2109
2110
2111 void CheckCompatibleReinterpretCast(QualType SrcType, QualType DestType,
2112 bool IsDereference, SourceRange Range);
2113
2114
2115
2116
2117
2118 bool ShouldSplatAltivecScalarInCast(const VectorType *VecTy);
2119
2120
2121
2122
2123
2124 bool CheckAltivecInitFromScalar(SourceRange R, QualType VecTy,
2125 QualType SrcTy);
2126
2127 ExprResult BuildCStyleCastExpr(SourceLocation LParenLoc, TypeSourceInfo *Ty,
2128 SourceLocation RParenLoc, Expr *Op);
2129
2130 ExprResult BuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, QualType Type,
2131 SourceLocation LParenLoc,
2132 Expr *CastExpr,
2133 SourceLocation RParenLoc);
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147 public:
2148
2149
2150 bool isConstantEvaluatedOverride = false;
2151
2152 bool isConstantEvaluatedContext() const {
2153 return currentEvaluationContext().isConstantEvaluated() ||
2154 isConstantEvaluatedOverride;
2155 }
2156
2157 SourceLocation getLocationOfStringLiteralByte(const StringLiteral *SL,
2158 unsigned ByteNo) const;
2159
2160 enum FormatArgumentPassingKind {
2161 FAPK_Fixed,
2162 FAPK_Variadic,
2163 FAPK_VAList,
2164 };
2165
2166
2167
2168 struct FormatStringInfo {
2169 unsigned FormatIdx;
2170 unsigned FirstDataArg;
2171 FormatArgumentPassingKind ArgPassingKind;
2172 };
2173
2174
2175
2176
2177
2178 static bool getFormatStringInfo(const FormatAttr *Format, bool IsCXXMember,
2179 bool IsVariadic, FormatStringInfo *FSI);
2180
2181
2182 ExprResult BuiltinShuffleVector(CallExpr *TheCall);
2183
2184
2185 ExprResult ConvertVectorExpr(Expr *E, TypeSourceInfo *TInfo,
2186 SourceLocation BuiltinLoc,
2187 SourceLocation RParenLoc);
2188
2189 enum FormatStringType {
2190 FST_Scanf,
2191 FST_Printf,
2192 FST_NSString,
2193 FST_Strftime,
2194 FST_Strfmon,
2195 FST_Kprintf,
2196 FST_FreeBSDKPrintf,
2197 FST_OSTrace,
2198 FST_OSLog,
2199 FST_Syslog,
2200 FST_Unknown
2201 };
2202 static FormatStringType GetFormatStringType(const FormatAttr *Format);
2203
2204 bool FormatStringHasSArg(const StringLiteral *FExpr);
2205
2206
2207
2208
2209 void CheckFloatComparison(SourceLocation Loc, Expr *LHS, Expr *RHS,
2210 BinaryOperatorKind Opcode);
2211
2212
2213 void RegisterTypeTagForDatatype(const IdentifierInfo *ArgumentKind,
2214 uint64_t MagicValue, QualType Type,
2215 bool LayoutCompatible, bool MustBeNull);
2216
2217 struct TypeTagData {
2218 TypeTagData() {}
2219
2220 TypeTagData(QualType Type, bool LayoutCompatible, bool MustBeNull)
2221 : Type(Type), LayoutCompatible(LayoutCompatible),
2222 MustBeNull(MustBeNull) {}
2223
2224 QualType Type;
2225
2226
2227
2228 LLVM_PREFERRED_TYPE(bool)
2229 unsigned LayoutCompatible : 1;
2230 LLVM_PREFERRED_TYPE(bool)
2231 unsigned MustBeNull : 1;
2232 };
2233
2234
2235
2236 typedef std::pair<const IdentifierInfo *, uint64_t> TypeTagMagicValue;
2237
2238
2239
2240
2241 void DiagnoseMisalignedMembers();
2242
2243
2244
2245
2246
2247
2248 void DiscardMisalignedMemberAddress(const Type *T, Expr *E);
2249
2250
2251
2252
2253 void RefersToMemberWithReducedAlignment(
2254 Expr *E,
2255 llvm::function_ref<void(Expr *, RecordDecl *, FieldDecl *, CharUnits)>
2256 Action);
2257
2258 enum class AtomicArgumentOrder { API, AST };
2259 ExprResult
2260 BuildAtomicExpr(SourceRange CallRange, SourceRange ExprRange,
2261 SourceLocation RParenLoc, MultiExprArg Args,
2262 AtomicExpr::AtomicOp Op,
2263 AtomicArgumentOrder ArgOrder = AtomicArgumentOrder::API);
2264
2265
2266 bool hasCStrMethod(const Expr *E);
2267
2268
2269
2270
2271
2272
2273
2274 void DiagnoseAlwaysNonNullPointer(Expr *E,
2275 Expr::NullPointerConstantKind NullType,
2276 bool IsEqual, SourceRange Range);
2277
2278
2279
2280
2281
2282
2283 bool CheckParmsForFunctionDef(ArrayRef<ParmVarDecl *> Parameters,
2284 bool CheckParameterNames);
2285
2286
2287
2288 void CheckCastAlign(Expr *Op, QualType T, SourceRange TRange);
2289
2290
2291
2292 bool checkUnsafeAssigns(SourceLocation Loc, QualType LHS, Expr *RHS);
2293
2294
2295
2296 void checkUnsafeExprAssigns(SourceLocation Loc, Expr *LHS, Expr *RHS);
2297
2298
2299
2300
2301
2302
2303
2304 void DiagnoseEmptyStmtBody(SourceLocation StmtLoc, const Stmt *Body,
2305 unsigned DiagID);
2306
2307
2308
2309 void DiagnoseEmptyLoopBody(const Stmt *S, const Stmt *PossibleBody);
2310
2311
2312 void DiagnoseSelfMove(const Expr *LHSExpr, const Expr *RHSExpr,
2313 SourceLocation OpLoc);
2314
2315
2316 enum VariadicCallType {
2317 VariadicFunction,
2318 VariadicBlock,
2319 VariadicMethod,
2320 VariadicConstructor,
2321 VariadicDoesNotApply
2322 };
2323
2324 bool IsLayoutCompatible(QualType T1, QualType T2) const;
2325 bool IsPointerInterconvertibleBaseOf(const TypeSourceInfo *Base,
2326 const TypeSourceInfo *Derived);
2327
2328
2329
2330 bool CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall,
2331 const FunctionProtoType *Proto);
2332
2333
2334 bool BuiltinVectorMath(CallExpr *TheCall, QualType &Res, bool FPOnly = false);
2335 bool BuiltinVectorToScalarMath(CallExpr *TheCall);
2336
2337 void checkLifetimeCaptureBy(FunctionDecl *FDecl, bool IsMemberFunction,
2338 const Expr *ThisArg, ArrayRef<const Expr *> Args);
2339
2340
2341
2342
2343 void checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto,
2344 const Expr *ThisArg, ArrayRef<const Expr *> Args,
2345 bool IsMemberFunction, SourceLocation Loc, SourceRange Range,
2346 VariadicCallType CallType);
2347
2348
2349
2350
2351
2352 void CheckTCBEnforcement(const SourceLocation CallExprLoc,
2353 const NamedDecl *Callee);
2354
2355 void CheckConstrainedAuto(const AutoType *AutoT, SourceLocation Loc);
2356
2357
2358
2359 bool BuiltinConstantArg(CallExpr *TheCall, int ArgNum, llvm::APSInt &Result);
2360
2361
2362
2363 bool BuiltinConstantArgRange(CallExpr *TheCall, int ArgNum, int Low, int High,
2364 bool RangeIsError = true);
2365
2366
2367
2368 bool BuiltinConstantArgMultiple(CallExpr *TheCall, int ArgNum,
2369 unsigned Multiple);
2370
2371
2372
2373 bool BuiltinConstantArgPower2(CallExpr *TheCall, int ArgNum);
2374
2375
2376
2377
2378 bool BuiltinConstantArgShiftedByte(CallExpr *TheCall, int ArgNum,
2379 unsigned ArgBits);
2380
2381
2382
2383
2384
2385
2386 bool BuiltinConstantArgShiftedByteOrXXFF(CallExpr *TheCall, int ArgNum,
2387 unsigned ArgBits);
2388
2389
2390
2391
2392 bool checkArgCountAtLeast(CallExpr *Call, unsigned MinArgCount);
2393
2394
2395
2396
2397 bool checkArgCountAtMost(CallExpr *Call, unsigned MaxArgCount);
2398
2399
2400
2401
2402 bool checkArgCountRange(CallExpr *Call, unsigned MinArgCount,
2403 unsigned MaxArgCount);
2404
2405
2406
2407 bool checkArgCount(CallExpr *Call, unsigned DesiredArgCount);
2408
2409
2410
2411
2412
2413 bool ValueIsRunOfOnes(CallExpr *TheCall, unsigned ArgNum);
2414
2415 void CheckImplicitConversion(Expr *E, QualType T, SourceLocation CC,
2416 bool *ICContext = nullptr,
2417 bool IsListInit = false);
2418
2419 bool BuiltinElementwiseTernaryMath(CallExpr *TheCall,
2420 bool CheckForFloatArgs = true);
2421 bool PrepareBuiltinElementwiseMathOneArgCall(CallExpr *TheCall);
2422
2423 private:
2424 void CheckArrayAccess(const Expr *BaseExpr, const Expr *IndexExpr,
2425 const ArraySubscriptExpr *ASE = nullptr,
2426 bool AllowOnePastEnd = true, bool IndexNegated = false);
2427 void CheckArrayAccess(const Expr *E);
2428
2429 bool CheckPointerCall(NamedDecl *NDecl, CallExpr *TheCall,
2430 const FunctionProtoType *Proto);
2431
2432
2433
2434 bool CheckOtherCall(CallExpr *TheCall, const FunctionProtoType *Proto);
2435
2436
2437
2438 void CheckConstructorCall(FunctionDecl *FDecl, QualType ThisType,
2439 ArrayRef<const Expr *> Args,
2440 const FunctionProtoType *Proto, SourceLocation Loc);
2441
2442
2443
2444
2445
2446 void CheckArgAlignment(SourceLocation Loc, NamedDecl *FDecl,
2447 StringRef ParamName, QualType ArgTy, QualType ParamTy);
2448
2449 ExprResult CheckOSLogFormatStringArg(Expr *Arg);
2450
2451 ExprResult CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
2452 CallExpr *TheCall);
2453
2454 bool CheckTSBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID,
2455 CallExpr *TheCall);
2456
2457 void checkFortifiedBuiltinMemoryFunction(FunctionDecl *FD, CallExpr *TheCall);
2458
2459
2460
2461
2462 bool BuiltinVAStart(unsigned BuiltinID, CallExpr *TheCall);
2463 bool BuiltinVAStartARMMicrosoft(CallExpr *Call);
2464
2465
2466
2467 bool BuiltinUnorderedCompare(CallExpr *TheCall, unsigned BuiltinID);
2468
2469
2470
2471
2472 bool BuiltinFPClassification(CallExpr *TheCall, unsigned NumArgs,
2473 unsigned BuiltinID);
2474
2475
2476 bool BuiltinComplex(CallExpr *TheCall);
2477 bool BuiltinOSLogFormat(CallExpr *TheCall);
2478
2479
2480
2481
2482 bool BuiltinPrefetch(CallExpr *TheCall);
2483
2484
2485
2486
2487 bool BuiltinAllocaWithAlign(CallExpr *TheCall);
2488
2489
2490 bool BuiltinArithmeticFence(CallExpr *TheCall);
2491
2492
2493
2494
2495 bool BuiltinAssume(CallExpr *TheCall);
2496
2497
2498
2499 bool BuiltinAssumeAligned(CallExpr *TheCall);
2500
2501
2502
2503
2504 bool BuiltinLongjmp(CallExpr *TheCall);
2505
2506
2507
2508 bool BuiltinSetjmp(CallExpr *TheCall);
2509
2510
2511
2512
2513
2514
2515
2516
2517 ExprResult BuiltinAtomicOverloaded(ExprResult TheCallResult);
2518
2519
2520
2521
2522
2523
2524
2525 ExprResult BuiltinNontemporalOverloaded(ExprResult TheCallResult);
2526 ExprResult AtomicOpsOverloaded(ExprResult TheCallResult,
2527 AtomicExpr::AtomicOp Op);
2528
2529
2530 bool BuiltinElementwiseMath(CallExpr *TheCall, bool FPOnly = false);
2531 bool PrepareBuiltinReduceMathOneArgCall(CallExpr *TheCall);
2532
2533 bool BuiltinNonDeterministicValue(CallExpr *TheCall);
2534
2535 enum BuiltinCountedByRefKind {
2536 AssignmentKind,
2537 InitializerKind,
2538 FunctionArgKind,
2539 ReturnArgKind,
2540 ArraySubscriptKind,
2541 BinaryExprKind,
2542 };
2543
2544 bool CheckInvalidBuiltinCountedByRef(const Expr *E,
2545 BuiltinCountedByRefKind K);
2546 bool BuiltinCountedByRef(CallExpr *TheCall);
2547
2548
2549 ExprResult BuiltinMatrixTranspose(CallExpr *TheCall, ExprResult CallResult);
2550 ExprResult BuiltinMatrixColumnMajorLoad(CallExpr *TheCall,
2551 ExprResult CallResult);
2552 ExprResult BuiltinMatrixColumnMajorStore(CallExpr *TheCall,
2553 ExprResult CallResult);
2554
2555
2556
2557
2558 bool CheckFormatArguments(const FormatAttr *Format,
2559 ArrayRef<const Expr *> Args, bool IsCXXMember,
2560 VariadicCallType CallType, SourceLocation Loc,
2561 SourceRange Range,
2562 llvm::SmallBitVector &CheckedVarArgs);
2563 bool CheckFormatArguments(ArrayRef<const Expr *> Args,
2564 FormatArgumentPassingKind FAPK, unsigned format_idx,
2565 unsigned firstDataArg, FormatStringType Type,
2566 VariadicCallType CallType, SourceLocation Loc,
2567 SourceRange range,
2568 llvm::SmallBitVector &CheckedVarArgs);
2569
2570 void CheckInfNaNFunction(const CallExpr *Call, const FunctionDecl *FDecl);
2571
2572
2573 void CheckAbsoluteValueFunction(const CallExpr *Call,
2574 const FunctionDecl *FDecl);
2575
2576 void CheckMaxUnsignedZero(const CallExpr *Call, const FunctionDecl *FDecl);
2577
2578
2579
2580
2581
2582
2583
2584
2585 void CheckMemaccessArguments(const CallExpr *Call, unsigned BId,
2586 IdentifierInfo *FnName);
2587
2588
2589
2590 void CheckStrlcpycatArguments(const CallExpr *Call, IdentifierInfo *FnName);
2591
2592
2593
2594
2595 void CheckStrncatArguments(const CallExpr *Call, IdentifierInfo *FnName);
2596
2597
2598 void CheckFreeArguments(const CallExpr *E);
2599
2600 void CheckReturnValExpr(Expr *RetValExp, QualType lhsType,
2601 SourceLocation ReturnLoc, bool isObjCMethod = false,
2602 const AttrVec *Attrs = nullptr,
2603 const FunctionDecl *FD = nullptr);
2604
2605
2606
2607
2608
2609
2610
2611
2612 void CheckImplicitConversions(Expr *E, SourceLocation CC = SourceLocation());
2613
2614
2615
2616 void CheckBoolLikeConversion(Expr *E, SourceLocation CC);
2617
2618
2619
2620 void CheckForIntOverflow(const Expr *E);
2621 void CheckUnsequencedOperations(const Expr *E);
2622
2623
2624
2625 void CheckCompletedExpr(Expr *E, SourceLocation CheckLoc = SourceLocation(),
2626 bool IsConstexpr = false);
2627
2628 void CheckBitFieldInitialization(SourceLocation InitLoc, FieldDecl *Field,
2629 Expr *Init);
2630
2631
2632 std::unique_ptr<llvm::DenseMap<TypeTagMagicValue, TypeTagData>>
2633 TypeTagForDatatypeMagicValues;
2634
2635
2636
2637 void CheckArgumentWithTypeTag(const ArgumentWithTypeTagAttr *Attr,
2638 const ArrayRef<const Expr *> ExprArgs,
2639 SourceLocation CallSiteLoc);
2640
2641
2642
2643 void CheckAddressOfPackedMember(Expr *rhs);
2644
2645
2646
2647 struct MisalignedMember {
2648 Expr *E;
2649 RecordDecl *RD;
2650 ValueDecl *MD;
2651 CharUnits Alignment;
2652
2653 MisalignedMember() : E(), RD(), MD() {}
2654 MisalignedMember(Expr *E, RecordDecl *RD, ValueDecl *MD,
2655 CharUnits Alignment)
2656 : E(E), RD(RD), MD(MD), Alignment(Alignment) {}
2657 explicit MisalignedMember(Expr *E)
2658 : MisalignedMember(E, nullptr, nullptr, CharUnits()) {}
2659
2660 bool operator==(const MisalignedMember &m) { return this->E == m.E; }
2661 };
2662
2663
2664 SmallVector<MisalignedMember, 4> MisalignedMembers;
2665
2666
2667 void AddPotentialMisalignedMembers(Expr *E, RecordDecl *RD, ValueDecl *MD,
2668 CharUnits Alignment);
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681 public:
2682
2683
2684 ClassTemplateDecl *StdCoroutineTraitsCache;
2685
2686 bool ActOnCoroutineBodyStart(Scope *S, SourceLocation KwLoc,
2687 StringRef Keyword);
2688 ExprResult ActOnCoawaitExpr(Scope *S, SourceLocation KwLoc, Expr *E);
2689 ExprResult ActOnCoyieldExpr(Scope *S, SourceLocation KwLoc, Expr *E);
2690 StmtResult ActOnCoreturnStmt(Scope *S, SourceLocation KwLoc, Expr *E);
2691
2692 ExprResult BuildOperatorCoawaitLookupExpr(Scope *S, SourceLocation Loc);
2693 ExprResult BuildOperatorCoawaitCall(SourceLocation Loc, Expr *E,
2694 UnresolvedLookupExpr *Lookup);
2695 ExprResult BuildResolvedCoawaitExpr(SourceLocation KwLoc, Expr *Operand,
2696 Expr *Awaiter, bool IsImplicit = false);
2697 ExprResult BuildUnresolvedCoawaitExpr(SourceLocation KwLoc, Expr *Operand,
2698 UnresolvedLookupExpr *Lookup);
2699 ExprResult BuildCoyieldExpr(SourceLocation KwLoc, Expr *E);
2700 StmtResult BuildCoreturnStmt(SourceLocation KwLoc, Expr *E,
2701 bool IsImplicit = false);
2702 StmtResult BuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs);
2703 bool buildCoroutineParameterMoves(SourceLocation Loc);
2704 VarDecl *buildCoroutinePromise(SourceLocation Loc);
2705 void CheckCompletedCoroutineBody(FunctionDecl *FD, Stmt *&Body);
2706
2707
2708
2709
2710
2711 void CheckCoroutineWrapper(FunctionDecl *FD);
2712
2713
2714 ClassTemplateDecl *lookupCoroutineTraits(SourceLocation KwLoc,
2715 SourceLocation FuncLoc);
2716
2717
2718 bool checkFinalSuspendNoThrow(const Stmt *FinalSuspend);
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732 public:
2733
2734 bool RequireCompleteDeclContext(CXXScopeSpec &SS, DeclContext *DC);
2735
2736 bool RequireCompleteEnumDecl(EnumDecl *D, SourceLocation L,
2737 CXXScopeSpec *SS = nullptr);
2738
2739
2740
2741
2742
2743
2744
2745
2746 DeclContext *computeDeclContext(QualType T);
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761 DeclContext *computeDeclContext(const CXXScopeSpec &SS,
2762 bool EnteringContext = false);
2763 bool isDependentScopeSpecifier(const CXXScopeSpec &SS);
2764
2765
2766
2767
2768
2769
2770 CXXRecordDecl *getCurrentInstantiationOf(NestedNameSpecifier *NNS);
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780 bool ActOnCXXGlobalScopeSpecifier(SourceLocation CCLoc, CXXScopeSpec &SS);
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792 bool ActOnSuperScopeSpecifier(SourceLocation SuperLoc,
2793 SourceLocation ColonColonLoc, CXXScopeSpec &SS);
2794
2795
2796
2797
2798
2799
2800 bool isAcceptableNestedNameSpecifier(const NamedDecl *SD,
2801 bool *CanCorrect = nullptr);
2802
2803
2804
2805
2806
2807 NamedDecl *FindFirstQualifierInScope(Scope *S, NestedNameSpecifier *NNS);
2808
2809
2810
2811 struct NestedNameSpecInfo {
2812
2813
2814 ParsedType ObjectType;
2815
2816
2817 IdentifierInfo *Identifier;
2818
2819
2820 SourceLocation IdentifierLoc;
2821
2822
2823 SourceLocation CCLoc;
2824
2825
2826 NestedNameSpecInfo(IdentifierInfo *II, SourceLocation IdLoc,
2827 SourceLocation ColonColonLoc,
2828 ParsedType ObjectType = ParsedType())
2829 : ObjectType(ObjectType), Identifier(II), IdentifierLoc(IdLoc),
2830 CCLoc(ColonColonLoc) {}
2831
2832 NestedNameSpecInfo(IdentifierInfo *II, SourceLocation IdLoc,
2833 SourceLocation ColonColonLoc, QualType ObjectType)
2834 : ObjectType(ParsedType::make(ObjectType)), Identifier(II),
2835 IdentifierLoc(IdLoc), CCLoc(ColonColonLoc) {}
2836 };
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869 bool BuildCXXNestedNameSpecifier(Scope *S, NestedNameSpecInfo &IdInfo,
2870 bool EnteringContext, CXXScopeSpec &SS,
2871 NamedDecl *ScopeLookupResult,
2872 bool ErrorRecoveryLookup,
2873 bool *IsCorrectedToColon = nullptr,
2874 bool OnlyNamespace = false);
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898 bool ActOnCXXNestedNameSpecifier(Scope *S, NestedNameSpecInfo &IdInfo,
2899 bool EnteringContext, CXXScopeSpec &SS,
2900 bool *IsCorrectedToColon = nullptr,
2901 bool OnlyNamespace = false);
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926 bool ActOnCXXNestedNameSpecifier(
2927 Scope *S, CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
2928 TemplateTy TemplateName, SourceLocation TemplateNameLoc,
2929 SourceLocation LAngleLoc, ASTTemplateArgsPtr TemplateArgs,
2930 SourceLocation RAngleLoc, SourceLocation CCLoc, bool EnteringContext);
2931
2932 bool ActOnCXXNestedNameSpecifierDecltype(CXXScopeSpec &SS, const DeclSpec &DS,
2933 SourceLocation ColonColonLoc);
2934
2935 bool ActOnCXXNestedNameSpecifierIndexedPack(CXXScopeSpec &SS,
2936 const DeclSpec &DS,
2937 SourceLocation ColonColonLoc,
2938 QualType Type);
2939
2940
2941
2942
2943
2944
2945
2946 bool IsInvalidUnlessNestedName(Scope *S, CXXScopeSpec &SS,
2947 NestedNameSpecInfo &IdInfo,
2948 bool EnteringContext);
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958 void *SaveNestedNameSpecifierAnnotation(CXXScopeSpec &SS);
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970 void RestoreNestedNameSpecifierAnnotation(void *Annotation,
2971 SourceRange AnnotationRange,
2972 CXXScopeSpec &SS);
2973
2974 bool ShouldEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
2975
2976
2977
2978
2979
2980
2981
2982 bool ActOnCXXEnterDeclaratorScope(Scope *S, CXXScopeSpec &SS);
2983
2984
2985
2986
2987
2988
2989 void ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003 public:
3004 IdentifierResolver IdResolver;
3005
3006
3007
3008 unsigned InventedParameterInfosStart = 0;
3009
3010
3011 class ContextRAII {
3012 private:
3013 Sema &S;
3014 DeclContext *SavedContext;
3015 ProcessingContextState SavedContextState;
3016 QualType SavedCXXThisTypeOverride;
3017 unsigned SavedFunctionScopesStart;
3018 unsigned SavedInventedParameterInfosStart;
3019
3020 public:
3021 ContextRAII(Sema &S, DeclContext *ContextToPush, bool NewThisContext = true)
3022 : S(S), SavedContext(S.CurContext),
3023 SavedContextState(S.DelayedDiagnostics.pushUndelayed()),
3024 SavedCXXThisTypeOverride(S.CXXThisTypeOverride),
3025 SavedFunctionScopesStart(S.FunctionScopesStart),
3026 SavedInventedParameterInfosStart(S.InventedParameterInfosStart) {
3027 assert(ContextToPush && "pushing null context");
3028 S.CurContext = ContextToPush;
3029 if (NewThisContext)
3030 S.CXXThisTypeOverride = QualType();
3031
3032 S.FunctionScopesStart = S.FunctionScopes.size();
3033 S.InventedParameterInfosStart = S.InventedParameterInfos.size();
3034 }
3035
3036 void pop() {
3037 if (!SavedContext)
3038 return;
3039 S.CurContext = SavedContext;
3040 S.DelayedDiagnostics.popUndelayed(SavedContextState);
3041 S.CXXThisTypeOverride = SavedCXXThisTypeOverride;
3042 S.FunctionScopesStart = SavedFunctionScopesStart;
3043 S.InventedParameterInfosStart = SavedInventedParameterInfosStart;
3044 SavedContext = nullptr;
3045 }
3046
3047 ~ContextRAII() { pop(); }
3048 };
3049
3050 void DiagnoseInvalidJumps(Stmt *Body);
3051
3052
3053
3054
3055
3056 llvm::SmallPtrSet<const NamedDecl *, 4> TypoCorrectedFunctionDefinitions;
3057
3058
3059
3060 mutable llvm::DenseMap<const EnumDecl *, llvm::APInt> FlagBitsCache;
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070 llvm::MapVector<
3071 IdentifierInfo *,
3072 llvm::SetVector<
3073 WeakInfo, llvm::SmallVector<WeakInfo, 1u>,
3074 llvm::SmallDenseSet<WeakInfo, 2u, WeakInfo::DenseMapInfoByAliasOnly>>>
3075 WeakUndeclaredIdentifiers;
3076
3077
3078
3079
3080
3081 llvm::DenseMap<IdentifierInfo *, AsmLabelAttr *> ExtnameUndeclaredIdentifiers;
3082
3083
3084 llvm::SmallSetVector<const TypedefNameDecl *, 4>
3085 UnusedLocalTypedefNameCandidates;
3086
3087 typedef LazyVector<const DeclaratorDecl *, ExternalSemaSource,
3088 &ExternalSemaSource::ReadUnusedFileScopedDecls, 2, 2>
3089 UnusedFileScopedDeclsType;
3090
3091
3092
3093 UnusedFileScopedDeclsType UnusedFileScopedDecls;
3094
3095 typedef LazyVector<VarDecl *, ExternalSemaSource,
3096 &ExternalSemaSource::ReadTentativeDefinitions, 2, 2>
3097 TentativeDefinitionsType;
3098
3099
3100 TentativeDefinitionsType TentativeDefinitions;
3101
3102
3103 SmallVector<DeclaratorDecl *, 4> ExternalDeclarations;
3104
3105
3106
3107 DeclContext *OriginalLexicalContext;
3108
3109
3110 bool currentModuleIsHeaderUnit() const {
3111 return ModuleScopes.empty() ? false
3112 : ModuleScopes.back().Module->isHeaderUnit();
3113 }
3114
3115
3116 Module *getOwningModule(const Decl *Entity) {
3117 return Entity->getOwningModule();
3118 }
3119
3120 DeclGroupPtrTy ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType = nullptr);
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130 ParsedType getTypeName(const IdentifierInfo &II, SourceLocation NameLoc,
3131 Scope *S, CXXScopeSpec *SS = nullptr,
3132 bool isClassName = false, bool HasTrailingDot = false,
3133 ParsedType ObjectType = nullptr,
3134 bool IsCtorOrDtorName = false,
3135 bool WantNontrivialTypeSourceInfo = false,
3136 bool IsClassTemplateDeductionContext = true,
3137 ImplicitTypenameContext AllowImplicitTypename =
3138 ImplicitTypenameContext::No,
3139 IdentifierInfo **CorrectedII = nullptr);
3140
3141
3142
3143
3144
3145
3146 TypeSpecifierType isTagName(IdentifierInfo &II, Scope *S);
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162 bool isMicrosoftMissingTypename(const CXXScopeSpec *SS, Scope *S);
3163 void DiagnoseUnknownTypeName(IdentifierInfo *&II, SourceLocation IILoc,
3164 Scope *S, CXXScopeSpec *SS,
3165 ParsedType &SuggestedType,
3166 bool IsTemplateName = false);
3167
3168
3169
3170
3171
3172 ParsedType ActOnMSVCUnknownTypeName(const IdentifierInfo &II,
3173 SourceLocation NameLoc,
3174 bool IsTemplateTypeArg);
3175
3176
3177
3178 enum NameClassificationKind {
3179
3180
3181 NC_Unknown,
3182
3183 NC_Error,
3184
3185 NC_Keyword,
3186
3187 NC_Type,
3188
3189
3190
3191 NC_NonType,
3192
3193
3194
3195 NC_UndeclaredNonType,
3196
3197
3198
3199 NC_DependentNonType,
3200
3201
3202
3203
3204 NC_OverloadSet,
3205
3206 NC_TypeTemplate,
3207
3208 NC_VarTemplate,
3209
3210 NC_FunctionTemplate,
3211
3212 NC_UndeclaredTemplate,
3213
3214 NC_Concept,
3215 };
3216
3217 class NameClassification {
3218 NameClassificationKind Kind;
3219 union {
3220 ExprResult Expr;
3221 NamedDecl *NonTypeDecl;
3222 TemplateName Template;
3223 ParsedType Type;
3224 };
3225
3226 explicit NameClassification(NameClassificationKind Kind) : Kind(Kind) {}
3227
3228 public:
3229 NameClassification(ParsedType Type) : Kind(NC_Type), Type(Type) {}
3230
3231 NameClassification(const IdentifierInfo *Keyword) : Kind(NC_Keyword) {}
3232
3233 static NameClassification Error() { return NameClassification(NC_Error); }
3234
3235 static NameClassification Unknown() {
3236 return NameClassification(NC_Unknown);
3237 }
3238
3239 static NameClassification OverloadSet(ExprResult E) {
3240 NameClassification Result(NC_OverloadSet);
3241 Result.Expr = E;
3242 return Result;
3243 }
3244
3245 static NameClassification NonType(NamedDecl *D) {
3246 NameClassification Result(NC_NonType);
3247 Result.NonTypeDecl = D;
3248 return Result;
3249 }
3250
3251 static NameClassification UndeclaredNonType() {
3252 return NameClassification(NC_UndeclaredNonType);
3253 }
3254
3255 static NameClassification DependentNonType() {
3256 return NameClassification(NC_DependentNonType);
3257 }
3258
3259 static NameClassification TypeTemplate(TemplateName Name) {
3260 NameClassification Result(NC_TypeTemplate);
3261 Result.Template = Name;
3262 return Result;
3263 }
3264
3265 static NameClassification VarTemplate(TemplateName Name) {
3266 NameClassification Result(NC_VarTemplate);
3267 Result.Template = Name;
3268 return Result;
3269 }
3270
3271 static NameClassification FunctionTemplate(TemplateName Name) {
3272 NameClassification Result(NC_FunctionTemplate);
3273 Result.Template = Name;
3274 return Result;
3275 }
3276
3277 static NameClassification Concept(TemplateName Name) {
3278 NameClassification Result(NC_Concept);
3279 Result.Template = Name;
3280 return Result;
3281 }
3282
3283 static NameClassification UndeclaredTemplate(TemplateName Name) {
3284 NameClassification Result(NC_UndeclaredTemplate);
3285 Result.Template = Name;
3286 return Result;
3287 }
3288
3289 NameClassificationKind getKind() const { return Kind; }
3290
3291 ExprResult getExpression() const {
3292 assert(Kind == NC_OverloadSet);
3293 return Expr;
3294 }
3295
3296 ParsedType getType() const {
3297 assert(Kind == NC_Type);
3298 return Type;
3299 }
3300
3301 NamedDecl *getNonTypeDecl() const {
3302 assert(Kind == NC_NonType);
3303 return NonTypeDecl;
3304 }
3305
3306 TemplateName getTemplateName() const {
3307 assert(Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate ||
3308 Kind == NC_VarTemplate || Kind == NC_Concept ||
3309 Kind == NC_UndeclaredTemplate);
3310 return Template;
3311 }
3312
3313 TemplateNameKind getTemplateNameKind() const {
3314 switch (Kind) {
3315 case NC_TypeTemplate:
3316 return TNK_Type_template;
3317 case NC_FunctionTemplate:
3318 return TNK_Function_template;
3319 case NC_VarTemplate:
3320 return TNK_Var_template;
3321 case NC_Concept:
3322 return TNK_Concept_template;
3323 case NC_UndeclaredTemplate:
3324 return TNK_Undeclared_template;
3325 default:
3326 llvm_unreachable("unsupported name classification.");
3327 }
3328 }
3329 };
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351 NameClassification ClassifyName(Scope *S, CXXScopeSpec &SS,
3352 IdentifierInfo *&Name, SourceLocation NameLoc,
3353 const Token &NextToken,
3354 CorrectionCandidateCallback *CCC = nullptr);
3355
3356
3357
3358 ExprResult ActOnNameClassifiedAsUndeclaredNonType(IdentifierInfo *Name,
3359 SourceLocation NameLoc);
3360
3361
3362 ExprResult ActOnNameClassifiedAsDependentNonType(const CXXScopeSpec &SS,
3363 IdentifierInfo *Name,
3364 SourceLocation NameLoc,
3365 bool IsAddressOfOperand);
3366
3367
3368 ExprResult ActOnNameClassifiedAsNonType(Scope *S, const CXXScopeSpec &SS,
3369 NamedDecl *Found,
3370 SourceLocation NameLoc,
3371 const Token &NextToken);
3372
3373 ExprResult ActOnNameClassifiedAsOverloadSet(Scope *S, Expr *OverloadSet);
3374
3375
3376 enum class TemplateNameKindForDiagnostics {
3377 ClassTemplate,
3378 FunctionTemplate,
3379 VarTemplate,
3380 AliasTemplate,
3381 TemplateTemplateParam,
3382 Concept,
3383 DependentTemplate
3384 };
3385 TemplateNameKindForDiagnostics
3386 getTemplateNameKindForDiagnostics(TemplateName Name);
3387
3388
3389
3390 bool mightBeIntendedToBeTemplateName(ExprResult E, bool &Dependent) {
3391 if (!getLangOpts().CPlusPlus || E.isInvalid())
3392 return false;
3393 Dependent = false;
3394 if (auto *DRE = dyn_cast<DeclRefExpr>(E.get()))
3395 return !DRE->hasExplicitTemplateArgs();
3396 if (auto *ME = dyn_cast<MemberExpr>(E.get()))
3397 return !ME->hasExplicitTemplateArgs();
3398 Dependent = true;
3399 if (auto *DSDRE = dyn_cast<DependentScopeDeclRefExpr>(E.get()))
3400 return !DSDRE->hasExplicitTemplateArgs();
3401 if (auto *DSME = dyn_cast<CXXDependentScopeMemberExpr>(E.get()))
3402 return !DSME->hasExplicitTemplateArgs();
3403
3404
3405 return false;
3406 }
3407
3408 void warnOnReservedIdentifier(const NamedDecl *D);
3409
3410 Decl *ActOnDeclarator(Scope *S, Declarator &D);
3411
3412 NamedDecl *HandleDeclarator(Scope *S, Declarator &D,
3413 MultiTemplateParamsArg TemplateParameterLists);
3414
3415
3416
3417 bool tryToFixVariablyModifiedVarType(TypeSourceInfo *&TInfo, QualType &T,
3418 SourceLocation Loc,
3419 unsigned FailedFoldDiagID);
3420
3421
3422
3423
3424
3425 void RegisterLocallyScopedExternCDecl(NamedDecl *ND, Scope *S);
3426
3427
3428
3429
3430
3431
3432
3433
3434 bool DiagnoseClassNameShadow(DeclContext *DC, DeclarationNameInfo Info);
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455 bool diagnoseQualifiedDeclaration(CXXScopeSpec &SS, DeclContext *DC,
3456 DeclarationName Name, SourceLocation Loc,
3457 TemplateIdAnnotation *TemplateId,
3458 bool IsMemberSpecialization);
3459
3460 bool checkPointerAuthEnabled(SourceLocation Loc, SourceRange Range);
3461
3462 bool checkConstantPointerAuthKey(Expr *keyExpr, unsigned &key);
3463
3464
3465
3466 void DiagnoseFunctionSpecifiers(const DeclSpec &DS);
3467
3468
3469
3470 NamedDecl *getShadowedDeclaration(const TypedefNameDecl *D,
3471 const LookupResult &R);
3472
3473
3474
3475 NamedDecl *getShadowedDeclaration(const VarDecl *D, const LookupResult &R);
3476
3477
3478
3479 NamedDecl *getShadowedDeclaration(const BindingDecl *D,
3480 const LookupResult &R);
3481
3482
3483
3484
3485
3486
3487
3488
3489 void CheckShadow(NamedDecl *D, NamedDecl *ShadowedDecl,
3490 const LookupResult &R);
3491
3492
3493 void CheckShadow(Scope *S, VarDecl *D);
3494
3495
3496
3497 void CheckShadowingDeclModification(Expr *E, SourceLocation Loc);
3498
3499
3500
3501 void DiagnoseShadowingLambdaDecls(const sema::LambdaScopeInfo *LSI);
3502
3503 void handleTagNumbering(const TagDecl *Tag, Scope *TagScope);
3504 void setTagNameForLinkagePurposes(TagDecl *TagFromDeclSpec,
3505 TypedefNameDecl *NewTD);
3506 void CheckTypedefForVariablyModifiedType(Scope *S, TypedefNameDecl *D);
3507 NamedDecl *ActOnTypedefDeclarator(Scope *S, Declarator &D, DeclContext *DC,
3508 TypeSourceInfo *TInfo,
3509 LookupResult &Previous);
3510
3511
3512
3513
3514 NamedDecl *ActOnTypedefNameDecl(Scope *S, DeclContext *DC, TypedefNameDecl *D,
3515 LookupResult &Previous, bool &Redeclaration);
3516 NamedDecl *ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC,
3517 TypeSourceInfo *TInfo,
3518 LookupResult &Previous,
3519 MultiTemplateParamsArg TemplateParamLists,
3520 bool &AddToScope,
3521 ArrayRef<BindingDecl *> Bindings = {});
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535 bool CheckVariableDeclaration(VarDecl *NewVD, LookupResult &Previous);
3536 void CheckVariableDeclarationType(VarDecl *NewVD);
3537 void CheckCompleteVariableDeclaration(VarDecl *VD);
3538
3539 NamedDecl *ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
3540 TypeSourceInfo *TInfo,
3541 LookupResult &Previous,
3542 MultiTemplateParamsArg TemplateParamLists,
3543 bool &AddToScope);
3544
3545
3546
3547 bool AddOverriddenMethods(CXXRecordDecl *DC, CXXMethodDecl *MD);
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566 bool CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD,
3567 LookupResult &Previous,
3568 bool IsMemberSpecialization, bool DeclIsDefn);
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578 bool shouldLinkDependentDeclWithPrevious(Decl *D, Decl *OldDecl);
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588 bool canFullyTypeCheckRedeclaration(ValueDecl *NewD, ValueDecl *OldD,
3589 QualType NewT, QualType OldT);
3590 void CheckMain(FunctionDecl *FD, const DeclSpec &D);
3591 void CheckMSVCRTEntryPoint(FunctionDecl *FD);
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602 Attr *getImplicitCodeSegOrSectionAttrForFunction(const FunctionDecl *FD,
3603 bool IsDefinition);
3604
3605
3606
3607 void CheckFunctionOrTemplateParamDeclarator(Scope *S, Declarator &D);
3608
3609
3610
3611 Decl *ActOnParamDeclarator(Scope *S, Declarator &D,
3612 SourceLocation ExplicitThisLoc = {});
3613
3614
3615
3616 ParmVarDecl *BuildParmVarDeclForTypedef(DeclContext *DC, SourceLocation Loc,
3617 QualType T);
3618 ParmVarDecl *CheckParameter(DeclContext *DC, SourceLocation StartLoc,
3619 SourceLocation NameLoc,
3620 const IdentifierInfo *Name, QualType T,
3621 TypeSourceInfo *TSInfo, StorageClass SC);
3622
3623
3624
3625 enum NonTrivialCUnionContext {
3626
3627 NTCUC_FunctionParam,
3628
3629 NTCUC_FunctionReturn,
3630
3631 NTCUC_DefaultInitializedObject,
3632
3633 NTCUC_AutoVar,
3634
3635 NTCUC_CopyInit,
3636
3637 NTCUC_Assignment,
3638
3639 NTCUC_CompoundLiteral,
3640
3641 NTCUC_BlockCapture,
3642
3643 NTCUC_LValueToRValueVolatile,
3644 };
3645
3646
3647
3648
3649
3650 void checkNonTrivialCUnionInInitializer(const Expr *Init, SourceLocation Loc);
3651
3652
3653 enum NonTrivialCUnionKind {
3654 NTCUK_Init = 0x1,
3655 NTCUK_Destruct = 0x2,
3656 NTCUK_Copy = 0x4,
3657 };
3658
3659
3660
3661 void checkNonTrivialCUnion(QualType QT, SourceLocation Loc,
3662 NonTrivialCUnionContext UseContext,
3663 unsigned NonTrivialKind);
3664
3665
3666
3667
3668 void AddInitializerToDecl(Decl *dcl, Expr *init, bool DirectInit);
3669 void ActOnUninitializedDecl(Decl *dcl);
3670
3671
3672
3673
3674
3675 void ActOnInitializerError(Decl *Dcl);
3676
3677 void ActOnCXXForRangeDecl(Decl *D);
3678 StmtResult ActOnCXXForRangeIdentifier(Scope *S, SourceLocation IdentLoc,
3679 IdentifierInfo *Ident,
3680 ParsedAttributes &Attrs);
3681
3682
3683
3684 void CheckStaticLocalForDllExport(VarDecl *VD);
3685 void CheckThreadLocalForLargeAlignment(VarDecl *VD);
3686
3687
3688
3689 void FinalizeDeclaration(Decl *D);
3690 DeclGroupPtrTy FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS,
3691 ArrayRef<Decl *> Group);
3692
3693
3694
3695 DeclGroupPtrTy BuildDeclaratorGroup(MutableArrayRef<Decl *> Group);
3696
3697
3698
3699 void ActOnDocumentableDecl(Decl *D);
3700 void ActOnDocumentableDecls(ArrayRef<Decl *> Group);
3701
3702 enum class FnBodyKind {
3703
3704
3705
3706
3707 Other,
3708
3709 Default,
3710
3711
3712
3713
3714
3715 Delete
3716 };
3717
3718 void ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D,
3719 SourceLocation LocAfterDecls);
3720 void CheckForFunctionRedefinition(
3721 FunctionDecl *FD, const FunctionDecl *EffectiveDefinition = nullptr,
3722 SkipBodyInfo *SkipBody = nullptr);
3723 Decl *ActOnStartOfFunctionDef(Scope *S, Declarator &D,
3724 MultiTemplateParamsArg TemplateParamLists,
3725 SkipBodyInfo *SkipBody = nullptr,
3726 FnBodyKind BodyKind = FnBodyKind::Other);
3727 Decl *ActOnStartOfFunctionDef(Scope *S, Decl *D,
3728 SkipBodyInfo *SkipBody = nullptr,
3729 FnBodyKind BodyKind = FnBodyKind::Other);
3730 void applyFunctionAttributesBeforeParsingBody(Decl *FD);
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740 bool canDelayFunctionBody(const Declarator &D);
3741
3742
3743
3744
3745
3746
3747
3748
3749 bool canSkipFunctionBody(Decl *D);
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763 void computeNRVO(Stmt *Body, sema::FunctionScopeInfo *Scope);
3764 Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body);
3765 Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body, bool IsInstantiation);
3766 Decl *ActOnSkippedFunctionBody(Decl *Decl);
3767 void ActOnFinishInlineFunctionDef(FunctionDecl *D);
3768
3769
3770
3771 void ActOnFinishDelayedAttribute(Scope *S, Decl *D, ParsedAttributes &Attrs);
3772
3773
3774
3775 void DiagnoseUnusedParameters(ArrayRef<ParmVarDecl *> Parameters);
3776
3777
3778
3779
3780 void
3781 DiagnoseSizeOfParametersAndReturnValue(ArrayRef<ParmVarDecl *> Parameters,
3782 QualType ReturnTy, NamedDecl *D);
3783
3784 Decl *ActOnFileScopeAsmDecl(Expr *expr, SourceLocation AsmLoc,
3785 SourceLocation RParenLoc);
3786
3787 TopLevelStmtDecl *ActOnStartTopLevelStmtDecl(Scope *S);
3788 void ActOnFinishTopLevelStmtDecl(TopLevelStmtDecl *D, Stmt *Statement);
3789
3790 void ActOnPopScope(SourceLocation Loc, Scope *S);
3791
3792
3793
3794 Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, DeclSpec &DS,
3795 const ParsedAttributesView &DeclAttrs,
3796 RecordDecl *&AnonRecord);
3797
3798
3799
3800
3801 Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, DeclSpec &DS,
3802 const ParsedAttributesView &DeclAttrs,
3803 MultiTemplateParamsArg TemplateParams,
3804 bool IsExplicitInstantiation,
3805 RecordDecl *&AnonRecord,
3806 SourceLocation EllipsisLoc = {});
3807
3808
3809
3810
3811
3812 Decl *BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, AccessSpecifier AS,
3813 RecordDecl *Record,
3814 const PrintingPolicy &Policy);
3815
3816
3817
3818 void ActOnDefinedDeclarationSpecifier(Decl *D);
3819
3820
3821
3822
3823
3824 void DiagPlaceholderFieldDeclDefinitions(RecordDecl *Record);
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838 Decl *BuildMicrosoftCAnonymousStruct(Scope *S, DeclSpec &DS,
3839 RecordDecl *Record);
3840
3841
3842
3843 enum NonTagKind {
3844 NTK_NonStruct,
3845 NTK_NonClass,
3846 NTK_NonUnion,
3847 NTK_NonEnum,
3848 NTK_Typedef,
3849 NTK_TypeAlias,
3850 NTK_Template,
3851 NTK_TypeAliasTemplate,
3852 NTK_TemplateTemplateArgument,
3853 };
3854
3855
3856
3857 NonTagKind getNonTagTypeDeclKind(const Decl *D, TagTypeKind TTK);
3858
3859
3860
3861
3862
3863 bool isAcceptableTagRedeclaration(const TagDecl *Previous, TagTypeKind NewTag,
3864 bool isDefinition, SourceLocation NewTagLoc,
3865 const IdentifierInfo *Name);
3866
3867 enum OffsetOfKind {
3868
3869 OOK_Outside,
3870
3871 OOK_Builtin,
3872
3873
3874 OOK_Macro,
3875 };
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887 DeclResult ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK,
3888 SourceLocation KWLoc, CXXScopeSpec &SS,
3889 IdentifierInfo *Name, SourceLocation NameLoc,
3890 const ParsedAttributesView &Attr, AccessSpecifier AS,
3891 SourceLocation ModulePrivateLoc,
3892 MultiTemplateParamsArg TemplateParameterLists,
3893 bool &OwnedDecl, bool &IsDependent,
3894 SourceLocation ScopedEnumKWLoc,
3895 bool ScopedEnumUsesClassTag, TypeResult UnderlyingType,
3896 bool IsTypeSpecifier, bool IsTemplateParamOrArg,
3897 OffsetOfKind OOK, SkipBodyInfo *SkipBody = nullptr);
3898
3899
3900
3901 Decl *ActOnField(Scope *S, Decl *TagD, SourceLocation DeclStart,
3902 Declarator &D, Expr *BitfieldWidth);
3903
3904
3905 FieldDecl *HandleField(Scope *S, RecordDecl *TagD, SourceLocation DeclStart,
3906 Declarator &D, Expr *BitfieldWidth,
3907 InClassInitStyle InitStyle, AccessSpecifier AS);
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919 FieldDecl *CheckFieldDecl(DeclarationName Name, QualType T,
3920 TypeSourceInfo *TInfo, RecordDecl *Record,
3921 SourceLocation Loc, bool Mutable,
3922 Expr *BitfieldWidth, InClassInitStyle InitStyle,
3923 SourceLocation TSSL, AccessSpecifier AS,
3924 NamedDecl *PrevDecl, Declarator *D = nullptr);
3925
3926 bool CheckNontrivialField(FieldDecl *FD);
3927
3928
3929
3930
3931
3932 void ActOnLastBitfield(SourceLocation DeclStart,
3933 SmallVectorImpl<Decl *> &AllIvarDecls);
3934
3935
3936 void ActOnFields(Scope *S, SourceLocation RecLoc, Decl *TagDecl,
3937 ArrayRef<Decl *> Fields, SourceLocation LBrac,
3938 SourceLocation RBrac, const ParsedAttributesView &AttrList);
3939
3940
3941
3942
3943 void ActOnTagStartDefinition(Scope *S, Decl *TagDecl);
3944
3945
3946
3947
3948 bool ActOnDuplicateDefinition(Decl *Prev, SkipBodyInfo &SkipBody);
3949
3950 typedef void *SkippedDefinitionContext;
3951
3952
3953 SkippedDefinitionContext ActOnTagStartSkippedDefinition(Scope *S, Decl *TD);
3954
3955
3956
3957
3958 void ActOnStartCXXMemberDeclarations(Scope *S, Decl *TagDecl,
3959 SourceLocation FinalLoc,
3960 bool IsFinalSpelledSealed,
3961 bool IsAbstract,
3962 SourceLocation LBraceLoc);
3963
3964
3965
3966 void ActOnTagFinishDefinition(Scope *S, Decl *TagDecl,
3967 SourceRange BraceRange);
3968
3969 void ActOnTagFinishSkippedDefinition(SkippedDefinitionContext Context);
3970
3971
3972
3973 void ActOnTagDefinitionError(Scope *S, Decl *TagDecl);
3974
3975 EnumConstantDecl *CheckEnumConstant(EnumDecl *Enum,
3976 EnumConstantDecl *LastEnumConst,
3977 SourceLocation IdLoc, IdentifierInfo *Id,
3978 Expr *val);
3979
3980
3981 bool CheckEnumUnderlyingType(TypeSourceInfo *TI);
3982
3983
3984
3985 bool CheckEnumRedeclaration(SourceLocation EnumLoc, bool IsScoped,
3986 QualType EnumUnderlyingTy, bool IsFixed,
3987 const EnumDecl *Prev);
3988
3989
3990
3991 SkipBodyInfo shouldSkipAnonEnumBody(Scope *S, IdentifierInfo *II,
3992 SourceLocation IILoc);
3993
3994 Decl *ActOnEnumConstant(Scope *S, Decl *EnumDecl, Decl *LastEnumConstant,
3995 SourceLocation IdLoc, IdentifierInfo *Id,
3996 const ParsedAttributesView &Attrs,
3997 SourceLocation EqualLoc, Expr *Val);
3998 void ActOnEnumBody(SourceLocation EnumLoc, SourceRange BraceRange,
3999 Decl *EnumDecl, ArrayRef<Decl *> Elements, Scope *S,
4000 const ParsedAttributesView &Attr);
4001
4002
4003 void PushDeclContext(Scope *S, DeclContext *DC);
4004 void PopDeclContext();
4005
4006
4007
4008 void EnterDeclaratorContext(Scope *S, DeclContext *DC);
4009 void ExitDeclaratorContext(Scope *S);
4010
4011
4012
4013
4014 void EnterTemplatedContext(Scope *S, DeclContext *DC);
4015
4016
4017 void ActOnReenterFunctionContext(Scope *S, Decl *D);
4018 void ActOnExitFunctionContext();
4019
4020
4021 void PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext = true);
4022
4023
4024
4025
4026
4027
4028
4029
4030 bool isDeclInScope(NamedDecl *D, DeclContext *Ctx, Scope *S = nullptr,
4031 bool AllowInlineNamespace = false) const;
4032
4033
4034
4035 static Scope *getScopeForDeclContext(Scope *S, DeclContext *DC);
4036
4037
4038 TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T,
4039 TypeSourceInfo *TInfo);
4040 bool isIncompatibleTypedef(const TypeDecl *Old, TypedefNameDecl *New);
4041
4042
4043
4044 enum AvailabilityMergeKind {
4045
4046 AMK_None,
4047
4048
4049 AMK_Redeclaration,
4050
4051
4052 AMK_Override,
4053
4054
4055 AMK_ProtocolImplementation,
4056
4057
4058 AMK_OptionalProtocolImplementation
4059 };
4060
4061
4062 void mergeDeclAttributes(NamedDecl *New, Decl *Old,
4063 AvailabilityMergeKind AMK = AMK_Redeclaration);
4064
4065
4066
4067
4068
4069 void MergeTypedefNameDecl(Scope *S, TypedefNameDecl *New,
4070 LookupResult &OldDecls);
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083 bool MergeFunctionDecl(FunctionDecl *New, NamedDecl *&Old, Scope *S,
4084 bool MergeTypeWithOld, bool NewDeclIsDefn);
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095 bool MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old,
4096 Scope *S, bool MergeTypeWithOld);
4097 void mergeObjCMethodDecls(ObjCMethodDecl *New, ObjCMethodDecl *Old);
4098
4099
4100
4101
4102
4103
4104
4105
4106 void MergeVarDecl(VarDecl *New, LookupResult &Previous);
4107
4108
4109
4110
4111
4112
4113
4114
4115 void MergeVarDeclTypes(VarDecl *New, VarDecl *Old, bool MergeTypeWithOld);
4116
4117
4118
4119 bool checkVarDeclRedefinition(VarDecl *OldDefn, VarDecl *NewDefn);
4120 void notePreviousDefinition(const NamedDecl *Old, SourceLocation New);
4121
4122
4123
4124 void FilterLookupForScope(LookupResult &R, DeclContext *Ctx, Scope *S,
4125 bool ConsiderLinkage, bool AllowInlineNamespace);
4126
4127
4128
4129 bool CheckRedeclarationModuleOwnership(NamedDecl *New, NamedDecl *Old);
4130
4131
4132
4133
4134 bool CheckRedeclarationExported(NamedDecl *New, NamedDecl *Old);
4135
4136
4137
4138 bool CheckRedeclarationInModule(NamedDecl *New, NamedDecl *Old);
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156 bool IsRedefinitionInModule(const NamedDecl *New, const NamedDecl *Old) const;
4157
4158 bool ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) const;
4159
4160
4161
4162 void MarkUnusedFileScopedDecl(const DeclaratorDecl *D);
4163
4164 typedef llvm::function_ref<void(SourceLocation Loc, PartialDiagnostic PD)>
4165 DiagReceiverTy;
4166
4167 void DiagnoseUnusedNestedTypedefs(const RecordDecl *D);
4168 void DiagnoseUnusedNestedTypedefs(const RecordDecl *D,
4169 DiagReceiverTy DiagReceiver);
4170 void DiagnoseUnusedDecl(const NamedDecl *ND);
4171
4172
4173
4174 void DiagnoseUnusedDecl(const NamedDecl *ND, DiagReceiverTy DiagReceiver);
4175
4176
4177
4178 void DiagnoseUnusedButSetDecl(const VarDecl *VD, DiagReceiverTy DiagReceiver);
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203 Scope *getNonFieldDeclScope(Scope *S);
4204
4205 FunctionDecl *CreateBuiltin(IdentifierInfo *II, QualType Type, unsigned ID,
4206 SourceLocation Loc);
4207
4208
4209
4210
4211
4212 NamedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, Scope *S,
4213 bool ForRedeclaration, SourceLocation Loc);
4214
4215
4216
4217 const AttributedType *getCallingConvAttributedType(QualType T) const;
4218
4219
4220
4221 DeclarationNameInfo GetNameForDeclarator(Declarator &D);
4222
4223
4224 DeclarationNameInfo GetNameFromUnqualifiedId(const UnqualifiedId &Name);
4225
4226
4227
4228 llvm::SmallPtrSet<const Decl *, 4> ParsingInitForAutoVars;
4229
4230
4231 NamedDecl *findLocallyScopedExternCDecl(DeclarationName Name);
4232
4233 void deduceOpenCLAddressSpace(ValueDecl *decl);
4234
4235
4236
4237 static bool adjustContextForLocalExternDecl(DeclContext *&DC);
4238
4239 void MarkTypoCorrectedFunctionDefinition(const NamedDecl *F);
4240
4241
4242 bool areMultiversionVariantFunctionsCompatible(
4243 const FunctionDecl *OldFD, const FunctionDecl *NewFD,
4244 const PartialDiagnostic &NoProtoDiagID,
4245 const PartialDiagnosticAt &NoteCausedDiagIDAt,
4246 const PartialDiagnosticAt &NoSupportDiagIDAt,
4247 const PartialDiagnosticAt &DiffDiagIDAt, bool TemplatesSupported,
4248 bool ConstexprSupported, bool CLinkageMayDiffer);
4249
4250
4251 bool CheckForConstantInitializer(
4252 Expr *Init, unsigned DiagID = diag::err_init_element_not_constant);
4253
4254 QualType deduceVarTypeFromInitializer(VarDecl *VDecl, DeclarationName Name,
4255 QualType Type, TypeSourceInfo *TSI,
4256 SourceRange Range, bool DirectInit,
4257 Expr *Init);
4258
4259 bool DeduceVariableDeclarationType(VarDecl *VDecl, bool DirectInit,
4260 Expr *Init);
4261
4262 sema::LambdaScopeInfo *RebuildLambdaScopeInfo(CXXMethodDecl *CallOperator);
4263
4264
4265
4266 static bool CanBeGetReturnObject(const FunctionDecl *FD);
4267 static bool CanBeGetReturnTypeOnAllocFailure(const FunctionDecl *FD);
4268
4269
4270
4271 NamedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,
4272 Scope *S);
4273
4274
4275
4276
4277
4278
4279
4280 void AddKnownFunctionAttributesForReplaceableGlobalAllocationFunction(
4281 FunctionDecl *FD);
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292 void AddKnownFunctionAttributes(FunctionDecl *FD);
4293
4294
4295
4296
4297 ExprResult VerifyBitField(SourceLocation FieldLoc,
4298 const IdentifierInfo *FieldName, QualType FieldTy,
4299 bool IsMsStruct, Expr *BitWidth);
4300
4301
4302
4303
4304 bool IsValueInFlagEnum(const EnumDecl *ED, const llvm::APInt &Val,
4305 bool AllowMask) const;
4306
4307
4308 void ActOnPragmaWeakID(IdentifierInfo *WeakName, SourceLocation PragmaLoc,
4309 SourceLocation WeakNameLoc);
4310
4311
4312
4313 void ActOnPragmaRedefineExtname(IdentifierInfo *WeakName,
4314 IdentifierInfo *AliasName,
4315 SourceLocation PragmaLoc,
4316 SourceLocation WeakNameLoc,
4317 SourceLocation AliasNameLoc);
4318
4319
4320 void ActOnPragmaWeakAlias(IdentifierInfo *WeakName, IdentifierInfo *AliasName,
4321 SourceLocation PragmaLoc,
4322 SourceLocation WeakNameLoc,
4323 SourceLocation AliasNameLoc);
4324
4325
4326 enum class FunctionEmissionStatus {
4327 Emitted,
4328 CUDADiscarded,
4329 OMPDiscarded,
4330 TemplateDiscarded,
4331 Unknown,
4332 };
4333 FunctionEmissionStatus getEmissionStatus(const FunctionDecl *Decl,
4334 bool Final = false);
4335
4336
4337 bool shouldIgnoreInHostDeviceCheck(FunctionDecl *Callee);
4338
4339
4340
4341 llvm::SmallSetVector<Decl *, 4> DeclsToCheckForDeferredDiags;
4342
4343 private:
4344
4345
4346 llvm::DenseMap<const NamedDecl *, const NamedDecl *> ShadowingDecls;
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360 static bool mightHaveNonExternalLinkage(const DeclaratorDecl *FD);
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374 public:
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387 enum AvailabilityPriority : int {
4388
4389
4390 AP_Explicit = 0,
4391
4392
4393 AP_PragmaClangAttribute = 1,
4394
4395
4396
4397 AP_InferredFromOtherPlatform = 2
4398 };
4399
4400
4401
4402 enum class CallingConventionIgnoredReason {
4403 ForThisTarget = 0,
4404 VariadicFunction,
4405 ConstructorDestructor,
4406 BuiltinFunction
4407 };
4408
4409
4410
4411 template <typename AttrInfo>
4412 static std::enable_if_t<std::is_base_of_v<Attr, AttrInfo>, SourceLocation>
4413 getAttrLoc(const AttrInfo &AL) {
4414 return AL.getLocation();
4415 }
4416 SourceLocation getAttrLoc(const ParsedAttr &AL);
4417
4418
4419
4420
4421
4422
4423 template <typename AttrInfo>
4424 bool checkUInt32Argument(const AttrInfo &AI, const Expr *Expr, uint32_t &Val,
4425 unsigned Idx = UINT_MAX,
4426 bool StrictlyUnsigned = false) {
4427 std::optional<llvm::APSInt> I = llvm::APSInt(32);
4428 if (Expr->isTypeDependent() ||
4429 !(I = Expr->getIntegerConstantExpr(Context))) {
4430 if (Idx != UINT_MAX)
4431 Diag(getAttrLoc(AI), diag::err_attribute_argument_n_type)
4432 << &AI << Idx << AANT_ArgumentIntegerConstant
4433 << Expr->getSourceRange();
4434 else
4435 Diag(getAttrLoc(AI), diag::err_attribute_argument_type)
4436 << &AI << AANT_ArgumentIntegerConstant << Expr->getSourceRange();
4437 return false;
4438 }
4439
4440 if (!I->isIntN(32)) {
4441 Diag(Expr->getExprLoc(), diag::err_ice_too_large)
4442 << toString(*I, 10, false) << 32 << 1;
4443 return false;
4444 }
4445
4446 if (StrictlyUnsigned && I->isSigned() && I->isNegative()) {
4447 Diag(getAttrLoc(AI), diag::err_attribute_requires_positive_integer)
4448 << &AI << 1;
4449 return false;
4450 }
4451
4452 Val = (uint32_t)I->getZExtValue();
4453 return true;
4454 }
4455
4456
4457
4458
4459
4460
4461 SmallVector<Decl *, 2> WeakTopLevelDecl;
4462
4463
4464 SmallVectorImpl<Decl *> &WeakTopLevelDecls() { return WeakTopLevelDecl; }
4465
4466 typedef LazyVector<TypedefNameDecl *, ExternalSemaSource,
4467 &ExternalSemaSource::ReadExtVectorDecls, 2, 2>
4468 ExtVectorDeclsType;
4469
4470
4471
4472
4473 ExtVectorDeclsType ExtVectorDecls;
4474
4475
4476
4477
4478 bool checkStringLiteralArgumentAttr(const AttributeCommonInfo &CI,
4479 const Expr *E, StringRef &Str,
4480 SourceLocation *ArgLocation = nullptr);
4481
4482
4483
4484
4485
4486 bool checkStringLiteralArgumentAttr(const ParsedAttr &Attr, unsigned ArgNum,
4487 StringRef &Str,
4488 SourceLocation *ArgLocation = nullptr);
4489
4490
4491
4492
4493
4494
4495 bool isValidPointerAttrType(QualType T, bool RefOkay = false);
4496
4497
4498
4499 void AddAssumeAlignedAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E,
4500 Expr *OE);
4501
4502
4503
4504 void AddAllocAlignAttr(Decl *D, const AttributeCommonInfo &CI,
4505 Expr *ParamExpr);
4506
4507 bool CheckAttrTarget(const ParsedAttr &CurrAttr);
4508 bool CheckAttrNoArgs(const ParsedAttr &CurrAttr);
4509
4510 AvailabilityAttr *mergeAvailabilityAttr(
4511 NamedDecl *D, const AttributeCommonInfo &CI, IdentifierInfo *Platform,
4512 bool Implicit, VersionTuple Introduced, VersionTuple Deprecated,
4513 VersionTuple Obsoleted, bool IsUnavailable, StringRef Message,
4514 bool IsStrict, StringRef Replacement, AvailabilityMergeKind AMK,
4515 int Priority, IdentifierInfo *IIEnvironment);
4516
4517 TypeVisibilityAttr *
4518 mergeTypeVisibilityAttr(Decl *D, const AttributeCommonInfo &CI,
4519 TypeVisibilityAttr::VisibilityType Vis);
4520 VisibilityAttr *mergeVisibilityAttr(Decl *D, const AttributeCommonInfo &CI,
4521 VisibilityAttr::VisibilityType Vis);
4522 SectionAttr *mergeSectionAttr(Decl *D, const AttributeCommonInfo &CI,
4523 StringRef Name);
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534 llvm::Error isValidSectionSpecifier(StringRef Str);
4535 bool checkSectionName(SourceLocation LiteralLoc, StringRef Str);
4536 CodeSegAttr *mergeCodeSegAttr(Decl *D, const AttributeCommonInfo &CI,
4537 StringRef Name);
4538
4539
4540
4541 bool checkTargetAttr(SourceLocation LiteralLoc, StringRef Str);
4542
4543
4544 bool checkTargetVersionAttr(SourceLocation Loc, Decl *D, StringRef Str);
4545 bool checkTargetClonesAttrString(
4546 SourceLocation LiteralLoc, StringRef Str, const StringLiteral *Literal,
4547 Decl *D, bool &HasDefault, bool &HasCommas, bool &HasNotDefault,
4548 SmallVectorImpl<SmallString<64>> &StringsBuffer);
4549
4550 ErrorAttr *mergeErrorAttr(Decl *D, const AttributeCommonInfo &CI,
4551 StringRef NewUserDiagnostic);
4552 FormatAttr *mergeFormatAttr(Decl *D, const AttributeCommonInfo &CI,
4553 IdentifierInfo *Format, int FormatIdx,
4554 int FirstArg);
4555
4556
4557 void AddAlignedAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E,
4558 bool IsPackExpansion);
4559 void AddAlignedAttr(Decl *D, const AttributeCommonInfo &CI, TypeSourceInfo *T,
4560 bool IsPackExpansion);
4561
4562
4563
4564 void AddAlignValueAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E);
4565
4566
4567 Attr *CreateAnnotationAttr(const AttributeCommonInfo &CI, StringRef Annot,
4568 MutableArrayRef<Expr *> Args);
4569 Attr *CreateAnnotationAttr(const ParsedAttr &AL);
4570
4571 bool checkMSInheritanceAttrOnDefinition(CXXRecordDecl *RD, SourceRange Range,
4572 bool BestCase,
4573 MSInheritanceModel SemanticSpelling);
4574
4575 void CheckAlignasUnderalignment(Decl *D);
4576
4577
4578 void AddModeAttr(Decl *D, const AttributeCommonInfo &CI, IdentifierInfo *Name,
4579 bool InInstantiation = false);
4580 AlwaysInlineAttr *mergeAlwaysInlineAttr(Decl *D,
4581 const AttributeCommonInfo &CI,
4582 const IdentifierInfo *Ident);
4583 MinSizeAttr *mergeMinSizeAttr(Decl *D, const AttributeCommonInfo &CI);
4584 OptimizeNoneAttr *mergeOptimizeNoneAttr(Decl *D,
4585 const AttributeCommonInfo &CI);
4586 InternalLinkageAttr *mergeInternalLinkageAttr(Decl *D, const ParsedAttr &AL);
4587 InternalLinkageAttr *mergeInternalLinkageAttr(Decl *D,
4588 const InternalLinkageAttr &AL);
4589
4590
4591
4592
4593 bool CheckCallingConvAttr(
4594 const ParsedAttr &attr, CallingConv &CC, const FunctionDecl *FD = nullptr,
4595 CUDAFunctionTarget CFT = CUDAFunctionTarget::InvalidTarget);
4596
4597
4598
4599 bool CheckRegparmAttr(const ParsedAttr &attr, unsigned &value);
4600
4601
4602 CUDALaunchBoundsAttr *CreateLaunchBoundsAttr(const AttributeCommonInfo &CI,
4603 Expr *MaxThreads,
4604 Expr *MinBlocks,
4605 Expr *MaxBlocks);
4606
4607
4608
4609 void AddLaunchBoundsAttr(Decl *D, const AttributeCommonInfo &CI,
4610 Expr *MaxThreads, Expr *MinBlocks, Expr *MaxBlocks);
4611
4612 enum class RetainOwnershipKind { NS, CF, OS };
4613
4614 UuidAttr *mergeUuidAttr(Decl *D, const AttributeCommonInfo &CI,
4615 StringRef UuidAsWritten, MSGuidDecl *GuidDecl);
4616
4617 BTFDeclTagAttr *mergeBTFDeclTagAttr(Decl *D, const BTFDeclTagAttr &AL);
4618
4619 DLLImportAttr *mergeDLLImportAttr(Decl *D, const AttributeCommonInfo &CI);
4620 DLLExportAttr *mergeDLLExportAttr(Decl *D, const AttributeCommonInfo &CI);
4621 MSInheritanceAttr *mergeMSInheritanceAttr(Decl *D,
4622 const AttributeCommonInfo &CI,
4623 bool BestCase,
4624 MSInheritanceModel Model);
4625
4626 EnforceTCBAttr *mergeEnforceTCBAttr(Decl *D, const EnforceTCBAttr &AL);
4627 EnforceTCBLeafAttr *mergeEnforceTCBLeafAttr(Decl *D,
4628 const EnforceTCBLeafAttr &AL);
4629
4630
4631
4632 void ProcessDeclAttributeDelayed(Decl *D,
4633 const ParsedAttributesView &AttrList);
4634
4635
4636 struct ProcessDeclAttributeOptions {
4637 ProcessDeclAttributeOptions()
4638 : IncludeCXX11Attributes(true), IgnoreTypeAttributes(false) {}
4639
4640 ProcessDeclAttributeOptions WithIncludeCXX11Attributes(bool Val) {
4641 ProcessDeclAttributeOptions Result = *this;
4642 Result.IncludeCXX11Attributes = Val;
4643 return Result;
4644 }
4645
4646 ProcessDeclAttributeOptions WithIgnoreTypeAttributes(bool Val) {
4647 ProcessDeclAttributeOptions Result = *this;
4648 Result.IgnoreTypeAttributes = Val;
4649 return Result;
4650 }
4651
4652
4653 bool IncludeCXX11Attributes;
4654
4655
4656
4657
4658
4659 bool IgnoreTypeAttributes;
4660 };
4661
4662
4663
4664 void ProcessDeclAttributeList(Scope *S, Decl *D,
4665 const ParsedAttributesView &AttrList,
4666 const ProcessDeclAttributeOptions &Options =
4667 ProcessDeclAttributeOptions());
4668
4669
4670
4671 bool ProcessAccessDeclAttributeList(AccessSpecDecl *ASDecl,
4672 const ParsedAttributesView &AttrList);
4673
4674
4675
4676
4677 void checkUnusedDeclAttributes(Declarator &D);
4678
4679
4680
4681 NamedDecl *DeclClonePragmaWeak(NamedDecl *ND, const IdentifierInfo *II,
4682 SourceLocation Loc);
4683
4684
4685
4686 void DeclApplyPragmaWeak(Scope *S, NamedDecl *ND, const WeakInfo &W);
4687
4688 void ProcessPragmaWeak(Scope *S, Decl *D);
4689
4690 void ProcessDeclAttributes(Scope *S, Decl *D, const Declarator &PD);
4691
4692 void PopParsingDeclaration(ParsingDeclState state, Decl *decl);
4693
4694
4695
4696
4697 void redelayDiagnostics(sema::DelayedDiagnosticPool &pool);
4698
4699
4700
4701
4702
4703 template <typename AttrInfo>
4704 bool checkFunctionOrMethodParameterIndex(const Decl *D, const AttrInfo &AI,
4705 unsigned AttrArgNum,
4706 const Expr *IdxExpr, ParamIdx &Idx,
4707 bool CanIndexImplicitThis = false) {
4708 assert(isFunctionOrMethodOrBlockForAttrSubject(D));
4709
4710
4711
4712 bool HP = hasFunctionProto(D);
4713 bool HasImplicitThisParam = isInstanceMethod(D);
4714 bool IV = HP && isFunctionOrMethodVariadic(D);
4715 unsigned NumParams =
4716 (HP ? getFunctionOrMethodNumParams(D) : 0) + HasImplicitThisParam;
4717
4718 std::optional<llvm::APSInt> IdxInt;
4719 if (IdxExpr->isTypeDependent() ||
4720 !(IdxInt = IdxExpr->getIntegerConstantExpr(Context))) {
4721 Diag(getAttrLoc(AI), diag::err_attribute_argument_n_type)
4722 << &AI << AttrArgNum << AANT_ArgumentIntegerConstant
4723 << IdxExpr->getSourceRange();
4724 return false;
4725 }
4726
4727 unsigned IdxSource = IdxInt->getLimitedValue(UINT_MAX);
4728 if (IdxSource < 1 || (!IV && IdxSource > NumParams)) {
4729 Diag(getAttrLoc(AI), diag::err_attribute_argument_out_of_bounds)
4730 << &AI << AttrArgNum << IdxExpr->getSourceRange();
4731 return false;
4732 }
4733 if (HasImplicitThisParam && !CanIndexImplicitThis) {
4734 if (IdxSource == 1) {
4735 Diag(getAttrLoc(AI), diag::err_attribute_invalid_implicit_this_argument)
4736 << &AI << IdxExpr->getSourceRange();
4737 return false;
4738 }
4739 }
4740
4741 Idx = ParamIdx(IdxSource, D);
4742 return true;
4743 }
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757 public:
4758 void CheckDelegatingCtorCycles();
4759
4760
4761
4762 void ActOnStartFunctionDeclarationDeclarator(Declarator &D,
4763 unsigned TemplateParameterDepth);
4764
4765
4766
4767 void ActOnFinishFunctionDeclarationDeclarator(Declarator &D);
4768
4769
4770 Decl *ActOnStartNamespaceDef(Scope *S, SourceLocation InlineLoc,
4771 SourceLocation NamespaceLoc,
4772 SourceLocation IdentLoc, IdentifierInfo *Ident,
4773 SourceLocation LBrace,
4774 const ParsedAttributesView &AttrList,
4775 UsingDirectiveDecl *&UsingDecl, bool IsNested);
4776
4777
4778
4779 void ActOnFinishNamespaceDef(Decl *Dcl, SourceLocation RBrace);
4780
4781 NamespaceDecl *getStdNamespace() const;
4782
4783
4784
4785 NamespaceDecl *getOrCreateStdNamespace();
4786
4787 CXXRecordDecl *getStdBadAlloc() const;
4788 EnumDecl *getStdAlignValT() const;
4789
4790 ValueDecl *tryLookupUnambiguousFieldDecl(RecordDecl *ClassDecl,
4791 const IdentifierInfo *MemberOrBase);
4792
4793 enum class ComparisonCategoryUsage {
4794
4795
4796 OperatorInExpression,
4797
4798
4799
4800 DefaultedOperator,
4801 };
4802
4803
4804
4805
4806
4807
4808
4809 QualType CheckComparisonCategoryType(ComparisonCategoryType Kind,
4810 SourceLocation Loc,
4811 ComparisonCategoryUsage Usage);
4812
4813
4814
4815 bool isStdInitializerList(QualType Ty, QualType *Element);
4816
4817
4818
4819
4820
4821 QualType BuildStdInitializerList(QualType Element, SourceLocation Loc);
4822
4823
4824
4825 bool isInitListConstructor(const FunctionDecl *Ctor);
4826
4827 Decl *ActOnUsingDirective(Scope *CurScope, SourceLocation UsingLoc,
4828 SourceLocation NamespcLoc, CXXScopeSpec &SS,
4829 SourceLocation IdentLoc,
4830 IdentifierInfo *NamespcName,
4831 const ParsedAttributesView &AttrList);
4832
4833 void PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir);
4834
4835 Decl *ActOnNamespaceAliasDef(Scope *CurScope, SourceLocation NamespaceLoc,
4836 SourceLocation AliasLoc, IdentifierInfo *Alias,
4837 CXXScopeSpec &SS, SourceLocation IdentLoc,
4838 IdentifierInfo *Ident);
4839
4840
4841
4842
4843
4844
4845 void FilterUsingLookup(Scope *S, LookupResult &lookup);
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874 void HideUsingShadowDecl(Scope *S, UsingShadowDecl *Shadow);
4875
4876
4877
4878 bool CheckUsingShadowDecl(BaseUsingDecl *BUD, NamedDecl *Target,
4879 const LookupResult &PreviousDecls,
4880 UsingShadowDecl *&PrevShadow);
4881
4882
4883 UsingShadowDecl *BuildUsingShadowDecl(Scope *S, BaseUsingDecl *BUD,
4884 NamedDecl *Target,
4885 UsingShadowDecl *PrevDecl);
4886
4887
4888
4889
4890 bool CheckUsingDeclRedeclaration(SourceLocation UsingLoc,
4891 bool HasTypenameKeyword,
4892 const CXXScopeSpec &SS,
4893 SourceLocation NameLoc,
4894 const LookupResult &Previous);
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904 bool CheckUsingDeclQualifier(SourceLocation UsingLoc, bool HasTypename,
4905 const CXXScopeSpec &SS,
4906 const DeclarationNameInfo &NameInfo,
4907 SourceLocation NameLoc,
4908 const LookupResult *R = nullptr,
4909 const UsingDecl *UD = nullptr);
4910
4911
4912
4913
4914
4915
4916 NamedDecl *BuildUsingDeclaration(Scope *S, AccessSpecifier AS,
4917 SourceLocation UsingLoc,
4918 bool HasTypenameKeyword,
4919 SourceLocation TypenameLoc, CXXScopeSpec &SS,
4920 DeclarationNameInfo NameInfo,
4921 SourceLocation EllipsisLoc,
4922 const ParsedAttributesView &AttrList,
4923 bool IsInstantiation, bool IsUsingIfExists);
4924 NamedDecl *BuildUsingEnumDeclaration(Scope *S, AccessSpecifier AS,
4925 SourceLocation UsingLoc,
4926 SourceLocation EnumLoc,
4927 SourceLocation NameLoc,
4928 TypeSourceInfo *EnumType, EnumDecl *ED);
4929 NamedDecl *BuildUsingPackDecl(NamedDecl *InstantiatedFrom,
4930 ArrayRef<NamedDecl *> Expansions);
4931
4932
4933 bool CheckInheritingConstructorUsingDecl(UsingDecl *UD);
4934
4935
4936
4937
4938 CXXConstructorDecl *
4939 findInheritingConstructor(SourceLocation Loc, CXXConstructorDecl *BaseCtor,
4940 ConstructorUsingShadowDecl *DerivedShadow);
4941
4942 Decl *ActOnUsingDeclaration(Scope *CurScope, AccessSpecifier AS,
4943 SourceLocation UsingLoc,
4944 SourceLocation TypenameLoc, CXXScopeSpec &SS,
4945 UnqualifiedId &Name, SourceLocation EllipsisLoc,
4946 const ParsedAttributesView &AttrList);
4947 Decl *ActOnUsingEnumDeclaration(Scope *CurScope, AccessSpecifier AS,
4948 SourceLocation UsingLoc,
4949 SourceLocation EnumLoc, SourceRange TyLoc,
4950 const IdentifierInfo &II, ParsedType Ty,
4951 CXXScopeSpec *SS = nullptr);
4952 Decl *ActOnAliasDeclaration(Scope *CurScope, AccessSpecifier AS,
4953 MultiTemplateParamsArg TemplateParams,
4954 SourceLocation UsingLoc, UnqualifiedId &Name,
4955 const ParsedAttributesView &AttrList,
4956 TypeResult Type, Decl *DeclFromDeclSpec);
4957
4958
4959
4960
4961
4962 ExprResult BuildCXXConstructExpr(
4963 SourceLocation ConstructLoc, QualType DeclInitType, NamedDecl *FoundDecl,
4964 CXXConstructorDecl *Constructor, MultiExprArg Exprs,
4965 bool HadMultipleCandidates, bool IsListInitialization,
4966 bool IsStdInitListInitialization, bool RequiresZeroInit,
4967 CXXConstructionKind ConstructKind, SourceRange ParenRange);
4968
4969
4970
4971 ExprResult BuildCXXConstructExpr(
4972 SourceLocation ConstructLoc, QualType DeclInitType,
4973 CXXConstructorDecl *Constructor, bool Elidable, MultiExprArg Exprs,
4974 bool HadMultipleCandidates, bool IsListInitialization,
4975 bool IsStdInitListInitialization, bool RequiresZeroInit,
4976 CXXConstructionKind ConstructKind, SourceRange ParenRange);
4977
4978
4979
4980 ExprResult BuildCXXConstructExpr(
4981 SourceLocation ConstructLoc, QualType DeclInitType, NamedDecl *FoundDecl,
4982 CXXConstructorDecl *Constructor, bool Elidable, MultiExprArg Exprs,
4983 bool HadMultipleCandidates, bool IsListInitialization,
4984 bool IsStdInitListInitialization, bool RequiresZeroInit,
4985 CXXConstructionKind ConstructKind, SourceRange ParenRange);
4986
4987 ExprResult ConvertMemberDefaultInitExpression(FieldDecl *FD, Expr *InitExpr,
4988 SourceLocation InitLoc);
4989
4990
4991
4992 void FinalizeVarWithDestructor(VarDecl *VD, const RecordType *DeclInitType);
4993
4994
4995
4996 class ImplicitExceptionSpecification {
4997
4998 Sema *Self;
4999
5000
5001
5002
5003
5004
5005 ExceptionSpecificationType ComputedEST;
5006 llvm::SmallPtrSet<CanQualType, 4> ExceptionsSeen;
5007 SmallVector<QualType, 4> Exceptions;
5008
5009 void ClearExceptions() {
5010 ExceptionsSeen.clear();
5011 Exceptions.clear();
5012 }
5013
5014 public:
5015 explicit ImplicitExceptionSpecification(Sema &Self)
5016 : Self(&Self), ComputedEST(EST_BasicNoexcept) {
5017 if (!Self.getLangOpts().CPlusPlus11)
5018 ComputedEST = EST_DynamicNone;
5019 }
5020
5021
5022 ExceptionSpecificationType getExceptionSpecType() const {
5023 assert(!isComputedNoexcept(ComputedEST) &&
5024 "noexcept(expr) should not be a possible result");
5025 return ComputedEST;
5026 }
5027
5028
5029 unsigned size() const { return Exceptions.size(); }
5030
5031
5032 const QualType *data() const { return Exceptions.data(); }
5033
5034
5035 void CalledDecl(SourceLocation CallLoc, const CXXMethodDecl *Method);
5036
5037
5038 void CalledExpr(Expr *E) { CalledStmt(E); }
5039
5040
5041 void CalledStmt(Stmt *S);
5042
5043
5044
5045 FunctionProtoType::ExceptionSpecInfo getExceptionSpec() const {
5046 FunctionProtoType::ExceptionSpecInfo ESI;
5047 ESI.Type = getExceptionSpecType();
5048 if (ESI.Type == EST_Dynamic) {
5049 ESI.Exceptions = Exceptions;
5050 } else if (ESI.Type == EST_None) {
5051
5052
5053
5054 ESI.Type = EST_NoexceptFalse;
5055 ESI.NoexceptExpr =
5056 Self->ActOnCXXBoolLiteral(SourceLocation(), tok::kw_false).get();
5057 }
5058 return ESI;
5059 }
5060 };
5061
5062
5063
5064 void EvaluateImplicitExceptionSpec(SourceLocation Loc, FunctionDecl *FD);
5065
5066
5067
5068 void checkExceptionSpecification(bool IsTopLevel,
5069 ExceptionSpecificationType EST,
5070 ArrayRef<ParsedType> DynamicExceptions,
5071 ArrayRef<SourceRange> DynamicExceptionRanges,
5072 Expr *NoexceptExpr,
5073 SmallVectorImpl<QualType> &Exceptions,
5074 FunctionProtoType::ExceptionSpecInfo &ESI);
5075
5076
5077
5078
5079 void actOnDelayedExceptionSpecification(
5080 Decl *D, ExceptionSpecificationType EST, SourceRange SpecificationRange,
5081 ArrayRef<ParsedType> DynamicExceptions,
5082 ArrayRef<SourceRange> DynamicExceptionRanges, Expr *NoexceptExpr);
5083
5084 class InheritedConstructorInfo;
5085
5086
5087
5088 bool ShouldDeleteSpecialMember(CXXMethodDecl *MD, CXXSpecialMemberKind CSM,
5089 InheritedConstructorInfo *ICI = nullptr,
5090 bool Diagnose = false);
5091
5092
5093 void DiagnoseDeletedDefaultedFunction(FunctionDecl *FD);
5094
5095
5096
5097
5098
5099
5100
5101 CXXConstructorDecl *
5102 DeclareImplicitDefaultConstructor(CXXRecordDecl *ClassDecl);
5103
5104
5105
5106 void DefineImplicitDefaultConstructor(SourceLocation CurrentLocation,
5107 CXXConstructorDecl *Constructor);
5108
5109
5110
5111
5112
5113
5114
5115 CXXDestructorDecl *DeclareImplicitDestructor(CXXRecordDecl *ClassDecl);
5116
5117
5118
5119 void DefineImplicitDestructor(SourceLocation CurrentLocation,
5120 CXXDestructorDecl *Destructor);
5121
5122
5123
5124
5125
5126 void AdjustDestructorExceptionSpec(CXXDestructorDecl *Destructor);
5127
5128
5129 void DefineInheritingConstructor(SourceLocation UseLoc,
5130 CXXConstructorDecl *Constructor);
5131
5132
5133
5134
5135
5136
5137
5138 CXXConstructorDecl *DeclareImplicitCopyConstructor(CXXRecordDecl *ClassDecl);
5139
5140
5141
5142 void DefineImplicitCopyConstructor(SourceLocation CurrentLocation,
5143 CXXConstructorDecl *Constructor);
5144
5145
5146
5147
5148
5149
5150
5151
5152 CXXConstructorDecl *DeclareImplicitMoveConstructor(CXXRecordDecl *ClassDecl);
5153
5154
5155
5156 void DefineImplicitMoveConstructor(SourceLocation CurrentLocation,
5157 CXXConstructorDecl *Constructor);
5158
5159
5160
5161
5162
5163
5164
5165 CXXMethodDecl *DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl);
5166
5167
5168 void DefineImplicitCopyAssignment(SourceLocation CurrentLocation,
5169 CXXMethodDecl *MethodDecl);
5170
5171
5172
5173
5174
5175
5176
5177
5178 CXXMethodDecl *DeclareImplicitMoveAssignment(CXXRecordDecl *ClassDecl);
5179
5180
5181 void DefineImplicitMoveAssignment(SourceLocation CurrentLocation,
5182 CXXMethodDecl *MethodDecl);
5183
5184
5185 void CheckImplicitSpecialMemberDeclaration(Scope *S, FunctionDecl *FD);
5186
5187
5188
5189 bool isImplicitlyDeleted(FunctionDecl *FD);
5190
5191
5192
5193
5194
5195 bool checkThisInStaticMemberFunctionType(CXXMethodDecl *Method);
5196
5197
5198
5199 bool checkThisInStaticMemberFunctionExceptionSpec(CXXMethodDecl *Method);
5200
5201
5202
5203
5204
5205 bool checkThisInStaticMemberFunctionAttributes(CXXMethodDecl *Method);
5206
5207 bool CheckImmediateEscalatingFunctionDefinition(
5208 FunctionDecl *FD, const sema::FunctionScopeInfo *FSI);
5209
5210 void DiagnoseImmediateEscalatingReason(FunctionDecl *FD);
5211
5212
5213
5214
5215
5216
5217 bool CompleteConstructorCall(CXXConstructorDecl *Constructor,
5218 QualType DeclInitType, MultiExprArg ArgsPtr,
5219 SourceLocation Loc,
5220 SmallVectorImpl<Expr *> &ConvertedArgs,
5221 bool AllowExplicit = false,
5222 bool IsListInitialization = false);
5223
5224
5225
5226
5227
5228
5229 void ActOnCXXEnterDeclInitializer(Scope *S, Decl *Dcl);
5230
5231
5232
5233 void ActOnCXXExitDeclInitializer(Scope *S, Decl *Dcl);
5234
5235
5236
5237
5238
5239
5240
5241
5242 void
5243 DefineImplicitLambdaToFunctionPointerConversion(SourceLocation CurrentLoc,
5244 CXXConversionDecl *Conv);
5245
5246
5247
5248
5249
5250
5251
5252
5253 void DefineImplicitLambdaToBlockPointerConversion(SourceLocation CurrentLoc,
5254 CXXConversionDecl *Conv);
5255
5256
5257
5258
5259
5260
5261
5262 Decl *ActOnStartLinkageSpecification(Scope *S, SourceLocation ExternLoc,
5263 Expr *LangStr, SourceLocation LBraceLoc);
5264
5265
5266
5267
5268
5269 Decl *ActOnFinishLinkageSpecification(Scope *S, Decl *LinkageSpec,
5270 SourceLocation RBraceLoc);
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284 CXXRecordDecl *getCurrentClass(Scope *S, const CXXScopeSpec *SS);
5285
5286
5287
5288
5289
5290 bool isCurrentClassName(const IdentifierInfo &II, Scope *S,
5291 const CXXScopeSpec *SS = nullptr);
5292
5293
5294
5295
5296 bool isCurrentClassNameTypo(IdentifierInfo *&II, const CXXScopeSpec *SS);
5297
5298
5299 bool ActOnAccessSpecifier(AccessSpecifier Access, SourceLocation ASLoc,
5300 SourceLocation ColonLoc,
5301 const ParsedAttributesView &Attrs);
5302
5303
5304
5305
5306
5307
5308 NamedDecl *
5309 ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, Declarator &D,
5310 MultiTemplateParamsArg TemplateParameterLists,
5311 Expr *BitfieldWidth, const VirtSpecifiers &VS,
5312 InClassInitStyle InitStyle);
5313
5314
5315
5316
5317 void ActOnStartCXXInClassMemberInitializer();
5318
5319
5320
5321
5322
5323 void ActOnFinishCXXInClassMemberInitializer(Decl *VarDecl,
5324 SourceLocation EqualLoc,
5325 ExprResult Init);
5326
5327
5328 MemInitResult
5329 ActOnMemInitializer(Decl *ConstructorD, Scope *S, CXXScopeSpec &SS,
5330 IdentifierInfo *MemberOrBase, ParsedType TemplateTypeTy,
5331 const DeclSpec &DS, SourceLocation IdLoc,
5332 SourceLocation LParenLoc, ArrayRef<Expr *> Args,
5333 SourceLocation RParenLoc, SourceLocation EllipsisLoc);
5334
5335
5336 MemInitResult ActOnMemInitializer(Decl *ConstructorD, Scope *S,
5337 CXXScopeSpec &SS,
5338 IdentifierInfo *MemberOrBase,
5339 ParsedType TemplateTypeTy,
5340 const DeclSpec &DS, SourceLocation IdLoc,
5341 Expr *InitList, SourceLocation EllipsisLoc);
5342
5343
5344 MemInitResult BuildMemInitializer(Decl *ConstructorD, Scope *S,
5345 CXXScopeSpec &SS,
5346 IdentifierInfo *MemberOrBase,
5347 ParsedType TemplateTypeTy,
5348 const DeclSpec &DS, SourceLocation IdLoc,
5349 Expr *Init, SourceLocation EllipsisLoc);
5350
5351 MemInitResult BuildMemberInitializer(ValueDecl *Member, Expr *Init,
5352 SourceLocation IdLoc);
5353
5354 MemInitResult BuildBaseInitializer(QualType BaseType,
5355 TypeSourceInfo *BaseTInfo, Expr *Init,
5356 CXXRecordDecl *ClassDecl,
5357 SourceLocation EllipsisLoc);
5358
5359 MemInitResult BuildDelegatingInitializer(TypeSourceInfo *TInfo, Expr *Init,
5360 CXXRecordDecl *ClassDecl);
5361
5362 bool SetDelegatingInitializer(CXXConstructorDecl *Constructor,
5363 CXXCtorInitializer *Initializer);
5364
5365 bool SetCtorInitializers(CXXConstructorDecl *Constructor, bool AnyErrors,
5366 ArrayRef<CXXCtorInitializer *> Initializers = {});
5367
5368
5369
5370
5371 void MarkBaseAndMemberDestructorsReferenced(SourceLocation Loc,
5372 CXXRecordDecl *Record);
5373
5374
5375
5376
5377
5378 void MarkVirtualBaseDestructorsReferenced(
5379 SourceLocation Location, CXXRecordDecl *ClassDecl,
5380 llvm::SmallPtrSetImpl<const RecordType *> *DirectVirtualBases = nullptr);
5381
5382
5383
5384
5385
5386
5387 void CheckCompleteDestructorVariant(SourceLocation CurrentLocation,
5388 CXXDestructorDecl *Dtor);
5389
5390
5391
5392
5393 typedef std::pair<CXXRecordDecl *, SourceLocation> VTableUse;
5394
5395
5396
5397 SmallVector<VTableUse, 16> VTableUses;
5398
5399
5400
5401
5402
5403 llvm::DenseMap<CXXRecordDecl *, bool> VTablesUsed;
5404
5405
5406 void LoadExternalVTableUses();
5407
5408
5409
5410 void MarkVTableUsed(SourceLocation Loc, CXXRecordDecl *Class,
5411 bool DefinitionRequired = false);
5412
5413
5414
5415 void MarkVirtualMemberExceptionSpecsNeeded(SourceLocation Loc,
5416 const CXXRecordDecl *RD);
5417
5418
5419
5420 void MarkVirtualMembersReferenced(SourceLocation Loc, const CXXRecordDecl *RD,
5421 bool ConstexprOnly = false);
5422
5423
5424
5425
5426
5427
5428 bool DefineUsedVTables();
5429
5430
5431
5432
5433
5434
5435 void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl);
5436
5437
5438 void ActOnMemInitializers(Decl *ConstructorDecl, SourceLocation ColonLoc,
5439 ArrayRef<CXXCtorInitializer *> MemInits,
5440 bool AnyErrors);
5441
5442
5443
5444
5445 void checkClassLevelDLLAttribute(CXXRecordDecl *Class);
5446 void checkClassLevelCodeSegAttribute(CXXRecordDecl *Class);
5447
5448 void referenceDLLExportedClassMethods();
5449
5450
5451
5452 void propagateDLLAttrToBaseClassTemplate(
5453 CXXRecordDecl *Class, Attr *ClassAttr,
5454 ClassTemplateSpecializationDecl *BaseTemplateSpec,
5455 SourceLocation BaseLoc);
5456
5457
5458
5459
5460
5461
5462
5463
5464 void CheckCompletedCXXClass(Scope *S, CXXRecordDecl *Record);
5465
5466
5467
5468 void checkIllFormedTrivialABIStruct(CXXRecordDecl &RD);
5469
5470
5471
5472 void checkIncorrectVTablePointerAuthenticationAttribute(CXXRecordDecl &RD);
5473
5474 void ActOnFinishCXXMemberSpecification(Scope *S, SourceLocation RLoc,
5475 Decl *TagDecl, SourceLocation LBrac,
5476 SourceLocation RBrac,
5477 const ParsedAttributesView &AttrList);
5478
5479
5480
5481 void ActOnFinishCXXMemberDecls();
5482 void ActOnFinishCXXNonNestedClass();
5483
5484
5485
5486
5487 void ActOnReenterCXXMethodParameter(Scope *S, ParmVarDecl *Param);
5488 unsigned ActOnReenterTemplateScope(Decl *Template,
5489 llvm::function_ref<Scope *()> EnterScope);
5490 void ActOnStartDelayedMemberDeclarations(Scope *S, Decl *Record);
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500 void ActOnStartDelayedCXXMethodDeclaration(Scope *S, Decl *Method);
5501 void ActOnDelayedCXXMethodParameter(Scope *S, Decl *Param);
5502 void ActOnFinishDelayedMemberDeclarations(Scope *S, Decl *Record);
5503
5504
5505
5506
5507
5508
5509
5510 void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, Decl *Method);
5511 void ActOnFinishDelayedMemberInitializers(Decl *Record);
5512
5513 bool EvaluateStaticAssertMessageAsString(Expr *Message, std::string &Result,
5514 ASTContext &Ctx,
5515 bool ErrorOnInvalidMessage);
5516 Decl *ActOnStaticAssertDeclaration(SourceLocation StaticAssertLoc,
5517 Expr *AssertExpr, Expr *AssertMessageExpr,
5518 SourceLocation RParenLoc);
5519 Decl *BuildStaticAssertDeclaration(SourceLocation StaticAssertLoc,
5520 Expr *AssertExpr, Expr *AssertMessageExpr,
5521 SourceLocation RParenLoc, bool Failed);
5522
5523
5524
5525 void DiagnoseStaticAssertDetails(const Expr *E);
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544 Decl *ActOnFriendTypeDecl(Scope *S, const DeclSpec &DS,
5545 MultiTemplateParamsArg TemplateParams,
5546 SourceLocation EllipsisLoc);
5547 NamedDecl *ActOnFriendFunctionDecl(Scope *S, Declarator &D,
5548 MultiTemplateParamsArg TemplateParams);
5549
5550
5551
5552
5553
5554
5555
5556 QualType CheckConstructorDeclarator(Declarator &D, QualType R,
5557 StorageClass &SC);
5558
5559
5560
5561
5562 void CheckConstructor(CXXConstructorDecl *Constructor);
5563
5564
5565
5566
5567
5568
5569
5570 QualType CheckDestructorDeclarator(Declarator &D, QualType R,
5571 StorageClass &SC);
5572
5573
5574
5575
5576 bool CheckDestructor(CXXDestructorDecl *Destructor);
5577
5578
5579
5580
5581
5582
5583
5584 void CheckConversionDeclarator(Declarator &D, QualType &R, StorageClass &SC);
5585
5586
5587
5588
5589
5590 Decl *ActOnConversionDeclarator(CXXConversionDecl *Conversion);
5591
5592
5593
5594
5595
5596 bool CheckDeductionGuideDeclarator(Declarator &D, QualType &R,
5597 StorageClass &SC);
5598
5599 void CheckExplicitlyDefaultedFunction(Scope *S, FunctionDecl *MD);
5600
5601 bool CheckExplicitlyDefaultedSpecialMember(CXXMethodDecl *MD,
5602 CXXSpecialMemberKind CSM,
5603 SourceLocation DefaultLoc);
5604 void CheckDelayedMemberExceptionSpecs();
5605
5606
5607 enum class DefaultedComparisonKind : unsigned char {
5608
5609 None,
5610
5611
5612 Equal,
5613
5614
5615 ThreeWay,
5616
5617
5618 NotEqual,
5619
5620
5621 Relational,
5622 };
5623
5624 bool CheckExplicitlyDefaultedComparison(Scope *S, FunctionDecl *MD,
5625 DefaultedComparisonKind DCK);
5626 void DeclareImplicitEqualityComparison(CXXRecordDecl *RD,
5627 FunctionDecl *Spaceship);
5628 void DefineDefaultedComparison(SourceLocation Loc, FunctionDecl *FD,
5629 DefaultedComparisonKind DCK);
5630
5631 void CheckExplicitObjectMemberFunction(Declarator &D, DeclarationName Name,
5632 QualType R, bool IsLambda,
5633 DeclContext *DC = nullptr);
5634 void CheckExplicitObjectMemberFunction(DeclContext *DC, Declarator &D,
5635 DeclarationName Name, QualType R);
5636 void CheckExplicitObjectLambda(Declarator &D);
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646 CXXBaseSpecifier *CheckBaseSpecifier(CXXRecordDecl *Class,
5647 SourceRange SpecifierRange, bool Virtual,
5648 AccessSpecifier Access,
5649 TypeSourceInfo *TInfo,
5650 SourceLocation EllipsisLoc);
5651
5652
5653
5654
5655
5656
5657 BaseResult ActOnBaseSpecifier(Decl *classdecl, SourceRange SpecifierRange,
5658 const ParsedAttributesView &Attrs, bool Virtual,
5659 AccessSpecifier Access, ParsedType basetype,
5660 SourceLocation BaseLoc,
5661 SourceLocation EllipsisLoc);
5662
5663
5664
5665 bool AttachBaseSpecifiers(CXXRecordDecl *Class,
5666 MutableArrayRef<CXXBaseSpecifier *> Bases);
5667
5668
5669
5670
5671 void ActOnBaseSpecifiers(Decl *ClassDecl,
5672 MutableArrayRef<CXXBaseSpecifier *> Bases);
5673
5674
5675
5676 bool IsDerivedFrom(SourceLocation Loc, QualType Derived, QualType Base);
5677
5678
5679
5680 bool IsDerivedFrom(SourceLocation Loc, QualType Derived, QualType Base,
5681 CXXBasePaths &Paths);
5682
5683
5684 void BuildBasePathArray(const CXXBasePaths &Paths, CXXCastPath &BasePath);
5685
5686 bool CheckDerivedToBaseConversion(QualType Derived, QualType Base,
5687 SourceLocation Loc, SourceRange Range,
5688 CXXCastPath *BasePath = nullptr,
5689 bool IgnoreAccess = false);
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703 bool CheckDerivedToBaseConversion(QualType Derived, QualType Base,
5704 unsigned InaccessibleBaseID,
5705 unsigned AmbiguousBaseConvID,
5706 SourceLocation Loc, SourceRange Range,
5707 DeclarationName Name, CXXCastPath *BasePath,
5708 bool IgnoreAccess = false);
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722 std::string getAmbiguousPathsDisplayString(CXXBasePaths &Paths);
5723
5724 bool CheckOverridingFunctionAttributes(CXXMethodDecl *New,
5725 const CXXMethodDecl *Old);
5726
5727
5728
5729 bool CheckOverridingFunctionReturnType(const CXXMethodDecl *New,
5730 const CXXMethodDecl *Old);
5731
5732
5733 bool CheckExplicitObjectOverride(CXXMethodDecl *New,
5734 const CXXMethodDecl *Old);
5735
5736
5737
5738
5739
5740
5741 bool CheckPureMethod(CXXMethodDecl *Method, SourceRange InitRange);
5742
5743
5744 void CheckOverrideControl(NamedDecl *D);
5745
5746
5747
5748 void DiagnoseAbsenceOfOverrideControl(NamedDecl *D, bool Inconsistent);
5749
5750
5751
5752
5753 bool CheckIfOverriddenFunctionIsMarkedFinal(const CXXMethodDecl *New,
5754 const CXXMethodDecl *Old);
5755
5756 enum AbstractDiagSelID {
5757 AbstractNone = -1,
5758 AbstractReturnType,
5759 AbstractParamType,
5760 AbstractVariableType,
5761 AbstractFieldType,
5762 AbstractIvarType,
5763 AbstractSynthesizedIvarType,
5764 AbstractArrayType
5765 };
5766
5767 struct TypeDiagnoser;
5768
5769 bool isAbstractType(SourceLocation Loc, QualType T);
5770 bool RequireNonAbstractType(SourceLocation Loc, QualType T,
5771 TypeDiagnoser &Diagnoser);
5772 template <typename... Ts>
5773 bool RequireNonAbstractType(SourceLocation Loc, QualType T, unsigned DiagID,
5774 const Ts &...Args) {
5775 BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...);
5776 return RequireNonAbstractType(Loc, T, Diagnoser);
5777 }
5778
5779 void DiagnoseAbstractType(const CXXRecordDecl *RD);
5780
5781
5782
5783
5784
5785
5786
5787
5788 bool CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl);
5789
5790
5791
5792
5793 bool CheckLiteralOperatorDeclaration(FunctionDecl *FnDecl);
5794
5795
5796
5797 ExplicitSpecifier ActOnExplicitBoolSpecifier(Expr *E);
5798
5799
5800
5801 bool tryResolveExplicitSpecifier(ExplicitSpecifier &ExplicitSpec);
5802
5803
5804
5805
5806 DeclResult ActOnCXXConditionDeclaration(Scope *S, Declarator &D);
5807
5808
5809
5810 SmallVector<CXXRecordDecl *, 4> DelayedDllExportClasses;
5811 SmallVector<CXXMethodDecl *, 4> DelayedDllExportMemberFunctions;
5812
5813
5814
5815
5816
5817
5818 void MergeVarDeclExceptionSpecs(VarDecl *New, VarDecl *Old);
5819
5820
5821
5822
5823
5824 bool MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old, Scope *S);
5825
5826
5827 void CheckCXXDefaultArguments(FunctionDecl *FD);
5828
5829
5830
5831
5832
5833
5834 void CheckExtraCXXDefaultArguments(Declarator &D);
5835
5836 CXXSpecialMemberKind getSpecialMember(const CXXMethodDecl *MD) {
5837 return getDefaultedFunctionKind(MD).asSpecialMember();
5838 }
5839
5840
5841
5842
5843 VarDecl *BuildExceptionDeclaration(Scope *S, TypeSourceInfo *TInfo,
5844 SourceLocation StartLoc,
5845 SourceLocation IdLoc,
5846 const IdentifierInfo *Id);
5847
5848
5849
5850 Decl *ActOnExceptionDeclarator(Scope *S, Declarator &D);
5851
5852 void DiagnoseReturnInConstructorExceptionHandler(CXXTryStmt *TryBlock);
5853
5854
5855
5856 DeclResult ActOnTemplatedFriendTag(Scope *S, SourceLocation FriendLoc,
5857 unsigned TagSpec, SourceLocation TagLoc,
5858 CXXScopeSpec &SS, IdentifierInfo *Name,
5859 SourceLocation NameLoc,
5860 SourceLocation EllipsisLoc,
5861 const ParsedAttributesView &Attr,
5862 MultiTemplateParamsArg TempParamLists);
5863
5864 MSPropertyDecl *HandleMSProperty(Scope *S, RecordDecl *TagD,
5865 SourceLocation DeclStart, Declarator &D,
5866 Expr *BitfieldWidth,
5867 InClassInitStyle InitStyle,
5868 AccessSpecifier AS,
5869 const ParsedAttr &MSPropertyAttr);
5870
5871
5872
5873 void DiagnoseNontrivial(const CXXRecordDecl *Record,
5874 CXXSpecialMemberKind CSM);
5875
5876 enum TrivialABIHandling {
5877
5878 TAH_IgnoreTrivialABI,
5879
5880
5881 TAH_ConsiderTrivialABI
5882 };
5883
5884
5885
5886
5887 bool SpecialMemberIsTrivial(CXXMethodDecl *MD, CXXSpecialMemberKind CSM,
5888 TrivialABIHandling TAH = TAH_IgnoreTrivialABI,
5889 bool Diagnose = false);
5890
5891
5892 class DefaultedFunctionKind {
5893 LLVM_PREFERRED_TYPE(CXXSpecialMemberKind)
5894 unsigned SpecialMember : 8;
5895 unsigned Comparison : 8;
5896
5897 public:
5898 DefaultedFunctionKind()
5899 : SpecialMember(llvm::to_underlying(CXXSpecialMemberKind::Invalid)),
5900 Comparison(llvm::to_underlying(DefaultedComparisonKind::None)) {}
5901 DefaultedFunctionKind(CXXSpecialMemberKind CSM)
5902 : SpecialMember(llvm::to_underlying(CSM)),
5903 Comparison(llvm::to_underlying(DefaultedComparisonKind::None)) {}
5904 DefaultedFunctionKind(DefaultedComparisonKind Comp)
5905 : SpecialMember(llvm::to_underlying(CXXSpecialMemberKind::Invalid)),
5906 Comparison(llvm::to_underlying(Comp)) {}
5907
5908 bool isSpecialMember() const {
5909 return static_cast<CXXSpecialMemberKind>(SpecialMember) !=
5910 CXXSpecialMemberKind::Invalid;
5911 }
5912 bool isComparison() const {
5913 return static_cast<DefaultedComparisonKind>(Comparison) !=
5914 DefaultedComparisonKind::None;
5915 }
5916
5917 explicit operator bool() const {
5918 return isSpecialMember() || isComparison();
5919 }
5920
5921 CXXSpecialMemberKind asSpecialMember() const {
5922 return static_cast<CXXSpecialMemberKind>(SpecialMember);
5923 }
5924 DefaultedComparisonKind asComparison() const {
5925 return static_cast<DefaultedComparisonKind>(Comparison);
5926 }
5927
5928
5929 unsigned getDiagnosticIndex() const {
5930 static_assert(llvm::to_underlying(CXXSpecialMemberKind::Invalid) >
5931 llvm::to_underlying(CXXSpecialMemberKind::Destructor),
5932 "invalid should have highest index");
5933 static_assert((unsigned)DefaultedComparisonKind::None == 0,
5934 "none should be equal to zero");
5935 return SpecialMember + Comparison;
5936 }
5937 };
5938
5939
5940
5941
5942
5943
5944
5945
5946 DefaultedFunctionKind getDefaultedFunctionKind(const FunctionDecl *FD);
5947
5948
5949 Decl *ActOnEmptyDeclaration(Scope *S, const ParsedAttributesView &AttrList,
5950 SourceLocation SemiLoc);
5951
5952 enum class CheckConstexprKind {
5953
5954 Diagnose,
5955
5956
5957 CheckValid
5958 };
5959
5960
5961
5962
5963
5964
5965
5966 bool CheckConstexprFunctionDefinition(const FunctionDecl *FD,
5967 CheckConstexprKind Kind);
5968
5969
5970
5971 void DiagnoseHiddenVirtualMethods(CXXMethodDecl *MD);
5972
5973
5974
5975 void
5976 FindHiddenVirtualMethods(CXXMethodDecl *MD,
5977 SmallVectorImpl<CXXMethodDecl *> &OverloadedMethods);
5978 void
5979 NoteHiddenVirtualMethods(CXXMethodDecl *MD,
5980 SmallVectorImpl<CXXMethodDecl *> &OverloadedMethods);
5981
5982
5983
5984
5985 void ActOnParamDefaultArgument(Decl *param, SourceLocation EqualLoc,
5986 Expr *defarg);
5987
5988
5989
5990
5991
5992 void ActOnParamUnparsedDefaultArgument(Decl *param, SourceLocation EqualLoc,
5993 SourceLocation ArgLoc);
5994
5995
5996
5997 void ActOnParamDefaultArgumentError(Decl *param, SourceLocation EqualLoc,
5998 Expr *DefaultArg);
5999 ExprResult ConvertParamDefaultArgument(ParmVarDecl *Param, Expr *DefaultArg,
6000 SourceLocation EqualLoc);
6001 void SetParamDefaultArgument(ParmVarDecl *Param, Expr *DefaultArg,
6002 SourceLocation EqualLoc);
6003
6004 void ActOnPureSpecifier(Decl *D, SourceLocation PureSpecLoc);
6005 void SetDeclDeleted(Decl *dcl, SourceLocation DelLoc,
6006 StringLiteral *Message = nullptr);
6007 void SetDeclDefaulted(Decl *dcl, SourceLocation DefaultLoc);
6008
6009 void SetFunctionBodyKind(Decl *D, SourceLocation Loc, FnBodyKind BodyKind,
6010 StringLiteral *DeletedMessage = nullptr);
6011 void ActOnStartTrailingRequiresClause(Scope *S, Declarator &D);
6012 ExprResult ActOnFinishTrailingRequiresClause(ExprResult ConstraintExpr);
6013 ExprResult ActOnRequiresClause(ExprResult ConstraintExpr);
6014
6015 NamedDecl *
6016 ActOnDecompositionDeclarator(Scope *S, Declarator &D,
6017 MultiTemplateParamsArg TemplateParamLists);
6018 void DiagPlaceholderVariableDefinition(SourceLocation Loc);
6019 bool DiagRedefinedPlaceholderFieldDecl(SourceLocation Loc,
6020 RecordDecl *ClassDecl,
6021 const IdentifierInfo *Name);
6022
6023 void CheckCompleteDecompositionDeclaration(DecompositionDecl *DD);
6024
6025
6026
6027
6028
6029
6030 SmallVector<InventedTemplateParameterInfo, 4> InventedParameterInfos;
6031
6032
6033 std::unique_ptr<CXXFieldCollector> FieldCollector;
6034
6035 typedef llvm::SmallSetVector<const NamedDecl *, 16> NamedDeclSetType;
6036
6037 NamedDeclSetType UnusedPrivateFields;
6038
6039 typedef llvm::SmallPtrSet<const CXXRecordDecl *, 8> RecordDeclSetTy;
6040
6041
6042
6043
6044 std::unique_ptr<RecordDeclSetTy> PureVirtualClassDiagSet;
6045
6046 typedef LazyVector<CXXConstructorDecl *, ExternalSemaSource,
6047 &ExternalSemaSource::ReadDelegatingConstructors, 2, 2>
6048 DelegatingCtorDeclsType;
6049
6050
6051
6052 DelegatingCtorDeclsType DelegatingCtorDecls;
6053
6054
6055 LazyDeclPtr StdNamespace;
6056
6057
6058
6059 ClassTemplateDecl *StdInitializerList;
6060
6061
6062
6063 llvm::DenseMap<ParmVarDecl *, SourceLocation> UnparsedDefaultArgLocs;
6064
6065
6066
6067 llvm::MapVector<NamedDecl *, SourceLocation> UndefinedButUsed;
6068
6069 typedef llvm::PointerIntPair<CXXRecordDecl *, 3, CXXSpecialMemberKind>
6070 SpecialMemberDecl;
6071
6072
6073
6074
6075 llvm::SmallPtrSet<SpecialMemberDecl, 4> SpecialMembersBeingDeclared;
6076
6077 void NoteDeletedInheritingConstructor(CXXConstructorDecl *CD);
6078
6079 void ActOnDefaultCtorInitializers(Decl *CDtorDecl);
6080
6081 typedef ProcessingContextState ParsingClassState;
6082 ParsingClassState PushParsingClass() {
6083 ParsingClassDepth++;
6084 return DelayedDiagnostics.pushUndelayed();
6085 }
6086 void PopParsingClass(ParsingClassState state) {
6087 ParsingClassDepth--;
6088 DelayedDiagnostics.popUndelayed(state);
6089 }
6090
6091 ValueDecl *tryLookupCtorInitMemberDecl(CXXRecordDecl *ClassDecl,
6092 CXXScopeSpec &SS,
6093 ParsedType TemplateTypeTy,
6094 IdentifierInfo *MemberOrBase);
6095
6096 private:
6097 void setupImplicitSpecialMemberType(CXXMethodDecl *SpecialMem,
6098 QualType ResultTy,
6099 ArrayRef<QualType> Args);
6100
6101
6102
6103
6104 llvm::SmallBitVector FullyCheckedComparisonCategories;
6105
6106
6107 void CheckShadowInheritedFields(const SourceLocation &Loc,
6108 DeclarationName FieldName,
6109 const CXXRecordDecl *RD,
6110 bool DeclIsField = true);
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124 public:
6125
6126
6127
6128 SmallVector<std::pair<const CXXMethodDecl *, const CXXMethodDecl *>, 2>
6129 DelayedOverridingExceptionSpecChecks;
6130
6131
6132
6133
6134
6135
6136 SmallVector<std::pair<FunctionDecl *, FunctionDecl *>, 2>
6137 DelayedEquivalentExceptionSpecChecks;
6138
6139
6140
6141 bool isLibstdcxxEagerExceptionSpecHack(const Declarator &D);
6142
6143
6144
6145 ExprResult ActOnNoexceptSpec(Expr *NoexceptExpr,
6146 ExceptionSpecificationType &EST);
6147
6148 CanThrowResult canThrow(const Stmt *E);
6149
6150
6151 static CanThrowResult canCalleeThrow(Sema &S, const Expr *E, const Decl *D,
6152 SourceLocation Loc = SourceLocation());
6153 const FunctionProtoType *ResolveExceptionSpec(SourceLocation Loc,
6154 const FunctionProtoType *FPT);
6155 void UpdateExceptionSpec(FunctionDecl *FD,
6156 const FunctionProtoType::ExceptionSpecInfo &ESI);
6157
6158
6159
6160
6161
6162
6163
6164
6165 bool CheckSpecifiedExceptionType(QualType &T, SourceRange Range);
6166
6167
6168
6169
6170 bool CheckDistantExceptionSpec(QualType T);
6171 bool CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New);
6172
6173
6174
6175
6176
6177 bool CheckEquivalentExceptionSpec(const FunctionProtoType *Old,
6178 SourceLocation OldLoc,
6179 const FunctionProtoType *New,
6180 SourceLocation NewLoc);
6181 bool CheckEquivalentExceptionSpec(const PartialDiagnostic &DiagID,
6182 const PartialDiagnostic &NoteID,
6183 const FunctionProtoType *Old,
6184 SourceLocation OldLoc,
6185 const FunctionProtoType *New,
6186 SourceLocation NewLoc);
6187 bool handlerCanCatch(QualType HandlerType, QualType ExceptionType);
6188
6189
6190
6191
6192 bool CheckExceptionSpecSubset(
6193 const PartialDiagnostic &DiagID, const PartialDiagnostic &NestedDiagID,
6194 const PartialDiagnostic &NoteID, const PartialDiagnostic &NoThrowDiagID,
6195 const FunctionProtoType *Superset, bool SkipSupersetFirstParameter,
6196 SourceLocation SuperLoc, const FunctionProtoType *Subset,
6197 bool SkipSubsetFirstParameter, SourceLocation SubLoc);
6198
6199
6200
6201
6202
6203
6204 bool CheckParamExceptionSpec(
6205 const PartialDiagnostic &NestedDiagID, const PartialDiagnostic &NoteID,
6206 const FunctionProtoType *Target, bool SkipTargetFirstParameter,
6207 SourceLocation TargetLoc, const FunctionProtoType *Source,
6208 bool SkipSourceFirstParameter, SourceLocation SourceLoc);
6209
6210 bool CheckExceptionSpecCompatibility(Expr *From, QualType ToType);
6211
6212
6213
6214 bool CheckOverridingFunctionExceptionSpec(const CXXMethodDecl *New,
6215 const CXXMethodDecl *Old);
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229 public:
6230
6231
6232 enum class ExpressionEvaluationContext {
6233
6234
6235
6236
6237
6238 Unevaluated,
6239
6240
6241
6242
6243
6244 UnevaluatedList,
6245
6246
6247
6248
6249 DiscardedStatement,
6250
6251
6252
6253
6254 UnevaluatedAbstract,
6255
6256
6257
6258
6259 ConstantEvaluated,
6260
6261
6262
6263
6264 ImmediateFunctionContext,
6265
6266
6267
6268
6269 PotentiallyEvaluated,
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279 PotentiallyEvaluatedIfUsed
6280 };
6281
6282
6283
6284
6285
6286
6287 using MaybeODRUseExprSet = llvm::SmallSetVector<Expr *, 4>;
6288 MaybeODRUseExprSet MaybeODRUseExprs;
6289
6290 using ImmediateInvocationCandidate = llvm::PointerIntPair<ConstantExpr *, 1>;
6291
6292
6293
6294 struct ExpressionEvaluationContextRecord {
6295
6296 ExpressionEvaluationContext Context;
6297
6298
6299 CleanupInfo ParentCleanup;
6300
6301
6302
6303 unsigned NumCleanupObjects;
6304
6305
6306
6307 unsigned NumTypos;
6308
6309 MaybeODRUseExprSet SavedMaybeODRUseExprs;
6310
6311
6312
6313 SmallVector<LambdaExpr *, 2> Lambdas;
6314
6315
6316
6317
6318 Decl *ManglingContextDecl;
6319
6320
6321
6322 SmallVector<CallExpr *, 8> DelayedDecltypeCalls;
6323
6324
6325
6326 SmallVector<CXXBindTemporaryExpr *, 8> DelayedDecltypeBinds;
6327
6328 llvm::SmallPtrSet<const Expr *, 8> PossibleDerefs;
6329
6330
6331
6332
6333 SmallVector<Expr *, 2> VolatileAssignmentLHSs;
6334
6335
6336 llvm::SmallVector<ImmediateInvocationCandidate, 4>
6337 ImmediateInvocationCandidates;
6338
6339
6340
6341 llvm::SmallPtrSet<DeclRefExpr *, 4> ReferenceToConsteval;
6342
6343
6344
6345
6346
6347 SmallVector<MaterializeTemporaryExpr *, 8> ForRangeLifetimeExtendTemps;
6348
6349
6350
6351 enum ExpressionKind {
6352 EK_Decltype,
6353 EK_TemplateArgument,
6354 EK_AttrArgument,
6355 EK_Other
6356 } ExprContext;
6357
6358
6359
6360 bool InDiscardedStatement;
6361 bool InImmediateFunctionContext;
6362 bool InImmediateEscalatingFunctionContext;
6363
6364 bool IsCurrentlyCheckingDefaultArgumentOrInitializer = false;
6365
6366
6367
6368
6369 bool InConditionallyConstantEvaluateContext = false;
6370
6371
6372
6373
6374 bool InLifetimeExtendingContext = false;
6375
6376
6377 bool RebuildDefaultArgOrDefaultInit = false;
6378
6379
6380
6381
6382
6383 struct InitializationContext {
6384 InitializationContext(SourceLocation Loc, ValueDecl *Decl,
6385 DeclContext *Context)
6386 : Loc(Loc), Decl(Decl), Context(Context) {
6387 assert(Decl && Context && "invalid initialization context");
6388 }
6389
6390 SourceLocation Loc;
6391 ValueDecl *Decl = nullptr;
6392 DeclContext *Context = nullptr;
6393 };
6394 std::optional<InitializationContext> DelayedDefaultInitializationContext;
6395
6396 ExpressionEvaluationContextRecord(ExpressionEvaluationContext Context,
6397 unsigned NumCleanupObjects,
6398 CleanupInfo ParentCleanup,
6399 Decl *ManglingContextDecl,
6400 ExpressionKind ExprContext)
6401 : Context(Context), ParentCleanup(ParentCleanup),
6402 NumCleanupObjects(NumCleanupObjects), NumTypos(0),
6403 ManglingContextDecl(ManglingContextDecl), ExprContext(ExprContext),
6404 InDiscardedStatement(false), InImmediateFunctionContext(false),
6405 InImmediateEscalatingFunctionContext(false) {}
6406
6407 bool isUnevaluated() const {
6408 return Context == ExpressionEvaluationContext::Unevaluated ||
6409 Context == ExpressionEvaluationContext::UnevaluatedAbstract ||
6410 Context == ExpressionEvaluationContext::UnevaluatedList;
6411 }
6412
6413 bool isPotentiallyEvaluated() const {
6414 return Context == ExpressionEvaluationContext::PotentiallyEvaluated ||
6415 Context ==
6416 ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed ||
6417 Context == ExpressionEvaluationContext::ConstantEvaluated;
6418 }
6419
6420 bool isConstantEvaluated() const {
6421 return Context == ExpressionEvaluationContext::ConstantEvaluated ||
6422 Context == ExpressionEvaluationContext::ImmediateFunctionContext;
6423 }
6424
6425 bool isImmediateFunctionContext() const {
6426 return Context == ExpressionEvaluationContext::ImmediateFunctionContext ||
6427 (Context == ExpressionEvaluationContext::DiscardedStatement &&
6428 InImmediateFunctionContext) ||
6429
6430
6431
6432
6433
6434
6435
6436 (Context == ExpressionEvaluationContext::PotentiallyEvaluated &&
6437 InImmediateFunctionContext);
6438 }
6439
6440 bool isDiscardedStatementContext() const {
6441 return Context == ExpressionEvaluationContext::DiscardedStatement ||
6442 (Context ==
6443 ExpressionEvaluationContext::ImmediateFunctionContext &&
6444 InDiscardedStatement);
6445 }
6446 };
6447
6448 const ExpressionEvaluationContextRecord ¤tEvaluationContext() const {
6449 assert(!ExprEvalContexts.empty() &&
6450 "Must be in an expression evaluation context");
6451 return ExprEvalContexts.back();
6452 };
6453
6454 ExpressionEvaluationContextRecord ¤tEvaluationContext() {
6455 assert(!ExprEvalContexts.empty() &&
6456 "Must be in an expression evaluation context");
6457 return ExprEvalContexts.back();
6458 };
6459
6460 ExpressionEvaluationContextRecord &parentEvaluationContext() {
6461 assert(ExprEvalContexts.size() >= 2 &&
6462 "Must be in an expression evaluation context");
6463 return ExprEvalContexts[ExprEvalContexts.size() - 2];
6464 };
6465
6466 const ExpressionEvaluationContextRecord &parentEvaluationContext() const {
6467 return const_cast<Sema *>(this)->parentEvaluationContext();
6468 };
6469
6470 bool isAttrContext() const {
6471 return ExprEvalContexts.back().ExprContext ==
6472 ExpressionEvaluationContextRecord::ExpressionKind::EK_AttrArgument;
6473 }
6474
6475
6476
6477
6478 llvm::DenseMap<const VarDecl *, int> RefsMinusAssignments;
6479
6480
6481 CleanupInfo Cleanup;
6482
6483
6484
6485 SmallVector<ExprWithCleanups::CleanupObject, 8> ExprCleanupObjects;
6486
6487
6488
6489 bool CanUseDecl(NamedDecl *D, bool TreatUnavailableAsInvalid);
6490
6491
6492
6493 bool DiagnoseUseOfOverloadedDecl(NamedDecl *D, SourceLocation Loc) {
6494 return DiagnoseUseOfDecl(
6495 D, Loc, nullptr, false,
6496 false, nullptr,
6497 true);
6498 }
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511 bool DiagnoseUseOfDecl(NamedDecl *D, ArrayRef<SourceLocation> Locs,
6512 const ObjCInterfaceDecl *UnknownObjCClass = nullptr,
6513 bool ObjCPropertyAccess = false,
6514 bool AvoidPartialAvailabilityChecks = false,
6515 ObjCInterfaceDecl *ClassReciever = nullptr,
6516 bool SkipTrailingRequiresClause = false);
6517
6518
6519 void NoteDeletedFunction(FunctionDecl *FD);
6520
6521
6522
6523
6524
6525 void DiagnoseSentinelCalls(const NamedDecl *D, SourceLocation Loc,
6526 ArrayRef<Expr *> Args);
6527
6528 void PushExpressionEvaluationContext(
6529 ExpressionEvaluationContext NewContext, Decl *LambdaContextDecl = nullptr,
6530 ExpressionEvaluationContextRecord::ExpressionKind Type =
6531 ExpressionEvaluationContextRecord::EK_Other);
6532 enum ReuseLambdaContextDecl_t { ReuseLambdaContextDecl };
6533 void PushExpressionEvaluationContext(
6534 ExpressionEvaluationContext NewContext, ReuseLambdaContextDecl_t,
6535 ExpressionEvaluationContextRecord::ExpressionKind Type =
6536 ExpressionEvaluationContextRecord::EK_Other);
6537 void PopExpressionEvaluationContext();
6538
6539 void DiscardCleanupsInEvaluationContext();
6540
6541 ExprResult TransformToPotentiallyEvaluated(Expr *E);
6542 TypeSourceInfo *TransformToPotentiallyEvaluated(TypeSourceInfo *TInfo);
6543 ExprResult HandleExprEvaluationContextForTypeof(Expr *E);
6544
6545
6546
6547
6548
6549 void CheckUnusedVolatileAssignment(Expr *E);
6550
6551 ExprResult ActOnConstantExpression(ExprResult Res);
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565 void MarkAnyDeclReferenced(SourceLocation Loc, Decl *D, bool MightBeOdrUse);
6566
6567
6568
6569 void MarkFunctionReferenced(SourceLocation Loc, FunctionDecl *Func,
6570 bool MightBeOdrUse = true);
6571
6572
6573
6574
6575 void MarkVariableReferenced(SourceLocation Loc, VarDecl *Var);
6576
6577
6578
6579
6580
6581 void MarkDeclRefReferenced(DeclRefExpr *E, const Expr *Base = nullptr);
6582
6583
6584 void MarkMemberReferenced(MemberExpr *E);
6585
6586
6587 void MarkFunctionParmPackReferenced(FunctionParmPackExpr *E);
6588 void MarkCaptureUsedInEnclosingContext(ValueDecl *Capture, SourceLocation Loc,
6589 unsigned CapturingScopeIndex);
6590
6591 ExprResult CheckLValueToRValueConversionOperand(Expr *E);
6592 void CleanupVarDeclMarking();
6593
6594 enum TryCaptureKind {
6595 TryCapture_Implicit,
6596 TryCapture_ExplicitByVal,
6597 TryCapture_ExplicitByRef
6598 };
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633 bool tryCaptureVariable(ValueDecl *Var, SourceLocation Loc,
6634 TryCaptureKind Kind, SourceLocation EllipsisLoc,
6635 bool BuildAndDiagnose, QualType &CaptureType,
6636 QualType &DeclRefType,
6637 const unsigned *const FunctionScopeIndexToStopAt);
6638
6639
6640 bool tryCaptureVariable(ValueDecl *Var, SourceLocation Loc,
6641 TryCaptureKind Kind = TryCapture_Implicit,
6642 SourceLocation EllipsisLoc = SourceLocation());
6643
6644
6645 bool NeedToCaptureVariable(ValueDecl *Var, SourceLocation Loc);
6646
6647
6648
6649 QualType getCapturedDeclRefType(ValueDecl *Var, SourceLocation Loc);
6650
6651
6652
6653
6654 void MarkDeclarationsReferencedInType(SourceLocation Loc, QualType T);
6655
6656
6657
6658
6659
6660
6661
6662 void MarkDeclarationsReferencedInExpr(Expr *E,
6663 bool SkipLocalVariables = false,
6664 ArrayRef<const Expr *> StopAt = {});
6665
6666
6667
6668 ExprResult tryConvertExprToType(Expr *E, QualType Ty);
6669
6670
6671
6672
6673
6674
6675
6676
6677 bool DiagIfReachable(SourceLocation Loc, ArrayRef<const Stmt *> Stmts,
6678 const PartialDiagnostic &PD);
6679
6680
6681
6682
6683
6684
6685
6686
6687 bool DiagRuntimeBehavior(SourceLocation Loc, const Stmt *Statement,
6688 const PartialDiagnostic &PD);
6689
6690
6691 bool DiagRuntimeBehavior(SourceLocation Loc, ArrayRef<const Stmt *> Stmts,
6692 const PartialDiagnostic &PD);
6693
6694
6695 SourceRange getExprRange(Expr *E) const;
6696
6697 ExprResult ActOnIdExpression(Scope *S, CXXScopeSpec &SS,
6698 SourceLocation TemplateKWLoc, UnqualifiedId &Id,
6699 bool HasTrailingLParen, bool IsAddressOfOperand,
6700 CorrectionCandidateCallback *CCC = nullptr,
6701 bool IsInlineAsmIdentifier = false,
6702 Token *KeywordReplacement = nullptr);
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713 void DecomposeUnqualifiedId(const UnqualifiedId &Id,
6714 TemplateArgumentListInfo &Buffer,
6715 DeclarationNameInfo &NameInfo,
6716 const TemplateArgumentListInfo *&TemplateArgs);
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726 bool DiagnoseDependentMemberLookup(const LookupResult &R);
6727
6728
6729
6730
6731 bool
6732 DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R,
6733 CorrectionCandidateCallback &CCC,
6734 TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr,
6735 ArrayRef<Expr *> Args = {},
6736 DeclContext *LookupCtx = nullptr,
6737 TypoExpr **Out = nullptr);
6738
6739
6740
6741 NonOdrUseReason getNonOdrUseReasonInCurrentContext(ValueDecl *D);
6742
6743 DeclRefExpr *BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK,
6744 SourceLocation Loc,
6745 const CXXScopeSpec *SS = nullptr);
6746 DeclRefExpr *
6747 BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK,
6748 const DeclarationNameInfo &NameInfo,
6749 const CXXScopeSpec *SS = nullptr,
6750 NamedDecl *FoundD = nullptr,
6751 SourceLocation TemplateKWLoc = SourceLocation(),
6752 const TemplateArgumentListInfo *TemplateArgs = nullptr);
6753
6754
6755
6756 DeclRefExpr *
6757 BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK,
6758 const DeclarationNameInfo &NameInfo,
6759 NestedNameSpecifierLoc NNS, NamedDecl *FoundD = nullptr,
6760 SourceLocation TemplateKWLoc = SourceLocation(),
6761 const TemplateArgumentListInfo *TemplateArgs = nullptr);
6762
6763 bool UseArgumentDependentLookup(const CXXScopeSpec &SS, const LookupResult &R,
6764 bool HasTrailingLParen);
6765
6766
6767
6768
6769
6770 ExprResult BuildQualifiedDeclarationNameExpr(
6771 CXXScopeSpec &SS, const DeclarationNameInfo &NameInfo,
6772 bool IsAddressOfOperand, TypeSourceInfo **RecoveryTSI = nullptr);
6773
6774 ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, LookupResult &R,
6775 bool NeedsADL,
6776 bool AcceptInvalidDecl = false);
6777
6778
6779 ExprResult BuildDeclarationNameExpr(
6780 const CXXScopeSpec &SS, const DeclarationNameInfo &NameInfo, NamedDecl *D,
6781 NamedDecl *FoundD = nullptr,
6782 const TemplateArgumentListInfo *TemplateArgs = nullptr,
6783 bool AcceptInvalidDecl = false);
6784
6785
6786
6787
6788 std::vector<Token> ExpandFunctionLocalPredefinedMacros(ArrayRef<Token> Toks);
6789
6790 ExprResult BuildPredefinedExpr(SourceLocation Loc, PredefinedIdentKind IK);
6791 ExprResult ActOnPredefinedExpr(SourceLocation Loc, tok::TokenKind Kind);
6792 ExprResult ActOnIntegerConstant(SourceLocation Loc, int64_t Val);
6793
6794 bool CheckLoopHintExpr(Expr *E, SourceLocation Loc, bool AllowZero);
6795
6796 ExprResult ActOnNumericConstant(const Token &Tok, Scope *UDLScope = nullptr);
6797 ExprResult ActOnCharacterConstant(const Token &Tok,
6798 Scope *UDLScope = nullptr);
6799 ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, Expr *E);
6800 ExprResult ActOnParenListExpr(SourceLocation L, SourceLocation R,
6801 MultiExprArg Val);
6802
6803
6804
6805
6806
6807
6808 ExprResult ActOnStringLiteral(ArrayRef<Token> StringToks,
6809 Scope *UDLScope = nullptr);
6810
6811 ExprResult ActOnUnevaluatedStringLiteral(ArrayRef<Token> StringToks);
6812
6813
6814
6815
6816
6817
6818 ExprResult ActOnGenericSelectionExpr(SourceLocation KeyLoc,
6819 SourceLocation DefaultLoc,
6820 SourceLocation RParenLoc,
6821 bool PredicateIsExpr,
6822 void *ControllingExprOrType,
6823 ArrayRef<ParsedType> ArgTypes,
6824 ArrayRef<Expr *> ArgExprs);
6825
6826
6827
6828
6829 ExprResult CreateGenericSelectionExpr(SourceLocation KeyLoc,
6830 SourceLocation DefaultLoc,
6831 SourceLocation RParenLoc,
6832 bool PredicateIsExpr,
6833 void *ControllingExprOrType,
6834 ArrayRef<TypeSourceInfo *> Types,
6835 ArrayRef<Expr *> Exprs);
6836
6837
6838 ExprResult CreateBuiltinUnaryOp(SourceLocation OpLoc, UnaryOperatorKind Opc,
6839 Expr *InputExpr, bool IsAfterAmp = false);
6840 ExprResult BuildUnaryOp(Scope *S, SourceLocation OpLoc, UnaryOperatorKind Opc,
6841 Expr *Input, bool IsAfterAmp = false);
6842
6843
6844 ExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc, tok::TokenKind Op,
6845 Expr *Input, bool IsAfterAmp = false);
6846
6847
6848
6849
6850 bool isQualifiedMemberAccess(Expr *E);
6851 bool CheckUseOfCXXMethodAsAddressOfOperand(SourceLocation OpLoc,
6852 const Expr *Op,
6853 const CXXMethodDecl *MD);
6854
6855
6856
6857
6858
6859
6860
6861
6862 QualType CheckAddressOfOperand(ExprResult &Operand, SourceLocation OpLoc);
6863
6864
6865
6866
6867
6868
6869
6870
6871 bool ActOnAlignasTypeArgument(StringRef KWName, ParsedType Ty,
6872 SourceLocation OpLoc, SourceRange R);
6873 bool CheckAlignasTypeArgument(StringRef KWName, TypeSourceInfo *TInfo,
6874 SourceLocation OpLoc, SourceRange R);
6875
6876
6877 ExprResult CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo *TInfo,
6878 SourceLocation OpLoc,
6879 UnaryExprOrTypeTrait ExprKind,
6880 SourceRange R);
6881
6882
6883
6884 ExprResult CreateUnaryExprOrTypeTraitExpr(Expr *E, SourceLocation OpLoc,
6885 UnaryExprOrTypeTrait ExprKind);
6886
6887
6888
6889
6890 ExprResult ActOnUnaryExprOrTypeTraitExpr(SourceLocation OpLoc,
6891 UnaryExprOrTypeTrait ExprKind,
6892 bool IsType, void *TyOrEx,
6893 SourceRange ArgRange);
6894
6895
6896
6897 ExprResult CheckPlaceholderExpr(Expr *E);
6898 bool CheckVecStepExpr(Expr *E);
6899
6900
6901
6902
6903
6904
6905
6906
6907 bool CheckUnaryExprOrTypeTraitOperand(Expr *E, UnaryExprOrTypeTrait ExprKind);
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924 bool CheckUnaryExprOrTypeTraitOperand(QualType ExprType, SourceLocation OpLoc,
6925 SourceRange ExprRange,
6926 UnaryExprOrTypeTrait ExprKind,
6927 StringRef KWName);
6928
6929 ExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc,
6930 tok::TokenKind Kind, Expr *Input);
6931
6932 ExprResult ActOnArraySubscriptExpr(Scope *S, Expr *Base, SourceLocation LLoc,
6933 MultiExprArg ArgExprs,
6934 SourceLocation RLoc);
6935 ExprResult CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc,
6936 Expr *Idx, SourceLocation RLoc);
6937
6938 ExprResult CreateBuiltinMatrixSubscriptExpr(Expr *Base, Expr *RowIdx,
6939 Expr *ColumnIdx,
6940 SourceLocation RBLoc);
6941
6942
6943
6944
6945
6946
6947
6948 bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn, FunctionDecl *FDecl,
6949 const FunctionProtoType *Proto,
6950 ArrayRef<Expr *> Args, SourceLocation RParenLoc,
6951 bool ExecConfig = false);
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962 void CheckStaticArrayArgument(SourceLocation CallLoc, ParmVarDecl *Param,
6963 const Expr *ArgExpr);
6964
6965
6966
6967
6968 ExprResult ActOnCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc,
6969 MultiExprArg ArgExprs, SourceLocation RParenLoc,
6970 Expr *ExecConfig = nullptr);
6971
6972
6973
6974
6975 ExprResult BuildCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc,
6976 MultiExprArg ArgExprs, SourceLocation RParenLoc,
6977 Expr *ExecConfig = nullptr,
6978 bool IsExecConfig = false,
6979 bool AllowRecovery = false);
6980
6981
6982
6983 Expr *BuildBuiltinCallExpr(SourceLocation Loc, Builtin::ID Id,
6984 MultiExprArg CallArgs);
6985
6986 using ADLCallKind = CallExpr::ADLCallKind;
6987
6988
6989
6990
6991
6992
6993
6994 ExprResult
6995 BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl, SourceLocation LParenLoc,
6996 ArrayRef<Expr *> Arg, SourceLocation RParenLoc,
6997 Expr *Config = nullptr, bool IsExecConfig = false,
6998 ADLCallKind UsesADL = ADLCallKind::NotADL);
6999
7000 ExprResult ActOnCastExpr(Scope *S, SourceLocation LParenLoc, Declarator &D,
7001 ParsedType &Ty, SourceLocation RParenLoc,
7002 Expr *CastExpr);
7003
7004
7005
7006 CastKind PrepareScalarCast(ExprResult &src, QualType destType);
7007
7008
7009 ExprResult BuildVectorLiteral(SourceLocation LParenLoc,
7010 SourceLocation RParenLoc, Expr *E,
7011 TypeSourceInfo *TInfo);
7012
7013
7014
7015 ExprResult MaybeConvertParenListExprToParenExpr(Scope *S, Expr *ME);
7016
7017 ExprResult ActOnCompoundLiteral(SourceLocation LParenLoc, ParsedType Ty,
7018 SourceLocation RParenLoc, Expr *InitExpr);
7019
7020 ExprResult BuildCompoundLiteralExpr(SourceLocation LParenLoc,
7021 TypeSourceInfo *TInfo,
7022 SourceLocation RParenLoc,
7023 Expr *LiteralExpr);
7024
7025 ExprResult ActOnInitList(SourceLocation LBraceLoc, MultiExprArg InitArgList,
7026 SourceLocation RBraceLoc);
7027
7028 ExprResult BuildInitList(SourceLocation LBraceLoc, MultiExprArg InitArgList,
7029 SourceLocation RBraceLoc);
7030
7031
7032 ExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc, tok::TokenKind Kind,
7033 Expr *LHSExpr, Expr *RHSExpr);
7034 ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc, BinaryOperatorKind Opc,
7035 Expr *LHSExpr, Expr *RHSExpr);
7036
7037
7038
7039
7040 ExprResult CreateBuiltinBinOp(SourceLocation OpLoc, BinaryOperatorKind Opc,
7041 Expr *LHSExpr, Expr *RHSExpr);
7042 void LookupBinOp(Scope *S, SourceLocation OpLoc, BinaryOperatorKind Opc,
7043 UnresolvedSetImpl &Functions);
7044
7045
7046
7047
7048 void DiagnoseCommaOperator(const Expr *LHS, SourceLocation Loc);
7049
7050
7051
7052 ExprResult ActOnConditionalOp(SourceLocation QuestionLoc,
7053 SourceLocation ColonLoc, Expr *CondExpr,
7054 Expr *LHSExpr, Expr *RHSExpr);
7055
7056
7057 ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc,
7058 LabelDecl *TheDecl);
7059
7060 void ActOnStartStmtExpr();
7061 ExprResult ActOnStmtExpr(Scope *S, SourceLocation LPLoc, Stmt *SubStmt,
7062 SourceLocation RPLoc);
7063 ExprResult BuildStmtExpr(SourceLocation LPLoc, Stmt *SubStmt,
7064 SourceLocation RPLoc, unsigned TemplateDepth);
7065
7066 ExprResult ActOnStmtExprResult(ExprResult E);
7067 void ActOnStmtExprError();
7068
7069
7070 struct OffsetOfComponent {
7071 SourceLocation LocStart, LocEnd;
7072 bool isBrackets;
7073 union {
7074 IdentifierInfo *IdentInfo;
7075 Expr *E;
7076 } U;
7077 };
7078
7079
7080 ExprResult BuildBuiltinOffsetOf(SourceLocation BuiltinLoc,
7081 TypeSourceInfo *TInfo,
7082 ArrayRef<OffsetOfComponent> Components,
7083 SourceLocation RParenLoc);
7084 ExprResult ActOnBuiltinOffsetOf(Scope *S, SourceLocation BuiltinLoc,
7085 SourceLocation TypeLoc,
7086 ParsedType ParsedArgTy,
7087 ArrayRef<OffsetOfComponent> Components,
7088 SourceLocation RParenLoc);
7089
7090
7091 ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc, Expr *CondExpr,
7092 Expr *LHSExpr, Expr *RHSExpr,
7093 SourceLocation RPLoc);
7094
7095
7096 ExprResult ActOnVAArg(SourceLocation BuiltinLoc, Expr *E, ParsedType Ty,
7097 SourceLocation RPLoc);
7098 ExprResult BuildVAArgExpr(SourceLocation BuiltinLoc, Expr *E,
7099 TypeSourceInfo *TInfo, SourceLocation RPLoc);
7100
7101
7102
7103 ExprResult ActOnSourceLocExpr(SourceLocIdentKind Kind,
7104 SourceLocation BuiltinLoc,
7105 SourceLocation RPLoc);
7106
7107
7108 ExprResult ActOnEmbedExpr(SourceLocation EmbedKeywordLoc,
7109 StringLiteral *BinaryData);
7110
7111
7112 ExprResult BuildSourceLocExpr(SourceLocIdentKind Kind, QualType ResultTy,
7113 SourceLocation BuiltinLoc, SourceLocation RPLoc,
7114 DeclContext *ParentContext);
7115
7116
7117 ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc);
7118
7119 bool CheckCaseExpression(Expr *E);
7120
7121
7122
7123
7124
7125 void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope);
7126
7127
7128
7129 void ActOnBlockArguments(SourceLocation CaretLoc, Declarator &ParamInfo,
7130 Scope *CurScope);
7131
7132
7133
7134 void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope);
7135
7136
7137
7138 ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, Stmt *Body,
7139 Scope *CurScope);
7140
7141
7142
7143
7144
7145
7146
7147
7148 ExprResult ActOnConvertVectorExpr(Expr *E, ParsedType ParsedDestTy,
7149 SourceLocation BuiltinLoc,
7150 SourceLocation RParenLoc);
7151
7152
7153
7154
7155
7156
7157
7158 ExprResult ActOnAsTypeExpr(Expr *E, ParsedType ParsedDestTy,
7159 SourceLocation BuiltinLoc,
7160 SourceLocation RParenLoc);
7161
7162
7163 ExprResult BuildAsTypeExpr(Expr *E, QualType DestTy,
7164 SourceLocation BuiltinLoc,
7165 SourceLocation RParenLoc);
7166
7167
7168 ExprResult CreateRecoveryExpr(SourceLocation Begin, SourceLocation End,
7169 ArrayRef<Expr *> SubExprs,
7170 QualType T = QualType());
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192 ExprResult PerformObjectMemberConversion(Expr *From,
7193 NestedNameSpecifier *Qualifier,
7194 NamedDecl *FoundDecl,
7195 NamedDecl *Member);
7196
7197
7198
7199
7200 bool CheckCallReturnType(QualType ReturnType, SourceLocation Loc,
7201 CallExpr *CE, FunctionDecl *FD);
7202
7203
7204 void WarnOnPendingNoDerefs(ExpressionEvaluationContextRecord &Rec);
7205
7206 ExprResult BuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field);
7207
7208
7209
7210 bool CheckCXXDefaultArgExpr(SourceLocation CallLoc, FunctionDecl *FD,
7211 ParmVarDecl *Param, Expr *Init = nullptr,
7212 bool SkipImmediateInvocations = true);
7213
7214
7215
7216 ExprResult BuildCXXDefaultArgExpr(SourceLocation CallLoc, FunctionDecl *FD,
7217 ParmVarDecl *Param, Expr *Init = nullptr);
7218
7219
7220
7221 ExprResult CheckForImmediateInvocation(ExprResult E, FunctionDecl *Decl);
7222
7223 void MarkExpressionAsImmediateEscalating(Expr *E);
7224
7225
7226 bool IsInvalidSMECallConversion(QualType FromType, QualType ToType);
7227
7228
7229
7230 class VerifyICEDiagnoser {
7231 public:
7232 bool Suppress;
7233
7234 VerifyICEDiagnoser(bool Suppress = false) : Suppress(Suppress) {}
7235
7236 virtual SemaDiagnosticBuilder
7237 diagnoseNotICEType(Sema &S, SourceLocation Loc, QualType T);
7238 virtual SemaDiagnosticBuilder diagnoseNotICE(Sema &S,
7239 SourceLocation Loc) = 0;
7240 virtual SemaDiagnosticBuilder diagnoseFold(Sema &S, SourceLocation Loc);
7241 virtual ~VerifyICEDiagnoser() {}
7242 };
7243
7244 enum AllowFoldKind {
7245 NoFold,
7246 AllowFold,
7247 };
7248
7249
7250
7251
7252 ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result,
7253 VerifyICEDiagnoser &Diagnoser,
7254 AllowFoldKind CanFold = NoFold);
7255 ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result,
7256 unsigned DiagID,
7257 AllowFoldKind CanFold = NoFold);
7258 ExprResult VerifyIntegerConstantExpression(Expr *E,
7259 llvm::APSInt *Result = nullptr,
7260 AllowFoldKind CanFold = NoFold);
7261 ExprResult VerifyIntegerConstantExpression(Expr *E,
7262 AllowFoldKind CanFold = NoFold) {
7263 return VerifyIntegerConstantExpression(E, nullptr, CanFold);
7264 }
7265
7266
7267
7268 void DiagnoseAssignmentAsCondition(Expr *E);
7269
7270
7271
7272 void DiagnoseEqualityWithExtraParens(ParenExpr *ParenE);
7273
7274 class FullExprArg {
7275 public:
7276 FullExprArg() : E(nullptr) {}
7277 FullExprArg(Sema &actions) : E(nullptr) {}
7278
7279 ExprResult release() { return E; }
7280
7281 Expr *get() const { return E; }
7282
7283 Expr *operator->() { return E; }
7284
7285 private:
7286
7287
7288 friend class Sema;
7289
7290 explicit FullExprArg(Expr *expr) : E(expr) {}
7291
7292 Expr *E;
7293 };
7294
7295 FullExprArg MakeFullExpr(Expr *Arg) {
7296 return MakeFullExpr(Arg, Arg ? Arg->getExprLoc() : SourceLocation());
7297 }
7298 FullExprArg MakeFullExpr(Expr *Arg, SourceLocation CC) {
7299 return FullExprArg(
7300 ActOnFinishFullExpr(Arg, CC, false).get());
7301 }
7302 FullExprArg MakeFullDiscardedValueExpr(Expr *Arg) {
7303 ExprResult FE =
7304 ActOnFinishFullExpr(Arg, Arg ? Arg->getExprLoc() : SourceLocation(),
7305 true);
7306 return FullExprArg(FE.get());
7307 }
7308
7309 class ConditionResult {
7310 Decl *ConditionVar;
7311 FullExprArg Condition;
7312 bool Invalid;
7313 std::optional<bool> KnownValue;
7314
7315 friend class Sema;
7316 ConditionResult(Sema &S, Decl *ConditionVar, FullExprArg Condition,
7317 bool IsConstexpr)
7318 : ConditionVar(ConditionVar), Condition(Condition), Invalid(false) {
7319 if (IsConstexpr && Condition.get()) {
7320 if (std::optional<llvm::APSInt> Val =
7321 Condition.get()->getIntegerConstantExpr(S.Context)) {
7322 KnownValue = !!(*Val);
7323 }
7324 }
7325 }
7326 explicit ConditionResult(bool Invalid)
7327 : ConditionVar(nullptr), Condition(nullptr), Invalid(Invalid),
7328 KnownValue(std::nullopt) {}
7329
7330 public:
7331 ConditionResult() : ConditionResult(false) {}
7332 bool isInvalid() const { return Invalid; }
7333 std::pair<VarDecl *, Expr *> get() const {
7334 return std::make_pair(cast_or_null<VarDecl>(ConditionVar),
7335 Condition.get());
7336 }
7337 std::optional<bool> getKnownValue() const { return KnownValue; }
7338 };
7339 static ConditionResult ConditionError() { return ConditionResult(true); }
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349 ExprResult CheckBooleanCondition(SourceLocation Loc, Expr *E,
7350 bool IsConstexpr = false);
7351
7352 enum class ConditionKind {
7353 Boolean,
7354 ConstexprIf,
7355 Switch
7356 };
7357
7358 ConditionResult ActOnCondition(Scope *S, SourceLocation Loc, Expr *SubExpr,
7359 ConditionKind CK, bool MissingOK = false);
7360
7361 QualType CheckConditionalOperands(
7362 ExprResult &Cond, ExprResult &LHS, ExprResult &RHS, ExprValueKind &VK,
7363 ExprObjectKind &OK, SourceLocation QuestionLoc);
7364
7365
7366
7367
7368 bool DiagnoseConditionalForNull(const Expr *LHSExpr, const Expr *RHSExpr,
7369 SourceLocation QuestionLoc);
7370
7371
7372 QualType CheckVectorOperands(ExprResult &LHS, ExprResult &RHS,
7373 SourceLocation Loc, bool IsCompAssign,
7374 bool AllowBothBool, bool AllowBoolConversion,
7375 bool AllowBoolOperation, bool ReportInvalid);
7376
7377
7378
7379
7380
7381
7382 QualType GetSignedVectorType(QualType V);
7383 QualType GetSignedSizelessVectorType(QualType V);
7384
7385
7386
7387
7388
7389 QualType CheckVectorCompareOperands(ExprResult &LHS, ExprResult &RHS,
7390 SourceLocation Loc,
7391 BinaryOperatorKind Opc);
7392 QualType CheckSizelessVectorCompareOperands(ExprResult &LHS, ExprResult &RHS,
7393 SourceLocation Loc,
7394 BinaryOperatorKind Opc);
7395 QualType CheckVectorLogicalOperands(ExprResult &LHS, ExprResult &RHS,
7396 SourceLocation Loc,
7397 BinaryOperatorKind Opc);
7398
7399
7400 enum ArithConvKind {
7401
7402 ACK_Arithmetic,
7403
7404 ACK_BitwiseOp,
7405
7406 ACK_Comparison,
7407
7408 ACK_Conditional,
7409
7410 ACK_CompAssign,
7411 };
7412
7413
7414 QualType CheckSizelessVectorOperands(ExprResult &LHS, ExprResult &RHS,
7415 SourceLocation Loc, bool IsCompAssign,
7416 ArithConvKind OperationKind);
7417
7418
7419 QualType CheckMatrixElementwiseOperands(ExprResult &LHS, ExprResult &RHS,
7420 SourceLocation Loc,
7421 bool IsCompAssign);
7422 QualType CheckMatrixMultiplyOperands(ExprResult &LHS, ExprResult &RHS,
7423 SourceLocation Loc, bool IsCompAssign);
7424
7425
7426
7427
7428
7429
7430
7431 bool isValidSveBitcast(QualType srcType, QualType destType);
7432
7433
7434
7435 bool areMatrixTypesOfTheSameDimension(QualType srcTy, QualType destTy);
7436
7437 bool areVectorTypesSameSize(QualType srcType, QualType destType);
7438
7439
7440
7441
7442
7443
7444
7445
7446 bool areLaxCompatibleVectorTypes(QualType srcType, QualType destType);
7447
7448
7449
7450 bool isLaxVectorConversion(QualType srcType, QualType destType);
7451
7452
7453 bool anyAltivecTypes(QualType srcType, QualType destType);
7454
7455
7456
7457
7458
7459 ExprResult checkUnknownAnyCast(SourceRange TypeRange, QualType CastType,
7460 Expr *CastExpr, CastKind &CastKind,
7461 ExprValueKind &VK, CXXCastPath &Path);
7462
7463
7464
7465 ExprResult forceUnknownAnyToType(Expr *E, QualType ToType);
7466
7467
7468
7469 ExprResult checkUnknownAnyArg(SourceLocation callLoc, Expr *result,
7470 QualType ¶mType);
7471
7472
7473
7474
7475
7476 bool CheckMatrixCast(SourceRange R, QualType DestTy, QualType SrcTy,
7477 CastKind &Kind);
7478
7479
7480
7481
7482
7483 bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty,
7484 CastKind &Kind);
7485
7486
7487
7488 ExprResult prepareVectorSplat(QualType VectorTy, Expr *SplattedExpr);
7489
7490
7491
7492
7493
7494
7495 ExprResult CheckExtVectorCast(SourceRange R, QualType DestTy, Expr *CastExpr,
7496 CastKind &Kind);
7497
7498 QualType PreferredConditionType(ConditionKind K) const {
7499 return K == ConditionKind::Switch ? Context.IntTy : Context.BoolTy;
7500 }
7501
7502
7503
7504 ExprResult UsualUnaryConversions(Expr *E);
7505
7506
7507
7508 ExprResult CallExprUnaryConversions(Expr *E);
7509
7510
7511
7512 ExprResult DefaultFunctionArrayConversion(Expr *E, bool Diagnose = true);
7513
7514
7515
7516
7517 ExprResult DefaultFunctionArrayLvalueConversion(Expr *E,
7518 bool Diagnose = true);
7519
7520
7521
7522
7523 ExprResult DefaultLvalueConversion(Expr *E);
7524
7525
7526
7527
7528 ExprResult DefaultArgumentPromotion(Expr *E);
7529
7530 VariadicCallType getVariadicCallType(FunctionDecl *FDecl,
7531 const FunctionProtoType *Proto,
7532 Expr *Fn);
7533
7534
7535
7536 enum VarArgKind {
7537 VAK_Valid,
7538 VAK_ValidInCXX11,
7539 VAK_Undefined,
7540 VAK_MSVCUndefined,
7541 VAK_Invalid
7542 };
7543
7544
7545
7546
7547 VarArgKind isValidVarArgType(const QualType &Ty);
7548
7549
7550
7551 void checkVariadicArgument(const Expr *E, VariadicCallType CT);
7552
7553
7554
7555 bool GatherArgumentsForCall(SourceLocation CallLoc, FunctionDecl *FDecl,
7556 const FunctionProtoType *Proto,
7557 unsigned FirstParam, ArrayRef<Expr *> Args,
7558 SmallVectorImpl<Expr *> &AllArgs,
7559 VariadicCallType CallType = VariadicDoesNotApply,
7560 bool AllowExplicit = false,
7561 bool IsListInitialization = false);
7562
7563
7564
7565 ExprResult DefaultVariadicArgumentPromotion(Expr *E, VariadicCallType CT,
7566 FunctionDecl *FDecl);
7567
7568
7569
7570
7571
7572
7573 QualType UsualArithmeticConversions(ExprResult &LHS, ExprResult &RHS,
7574 SourceLocation Loc, ArithConvKind ACK);
7575
7576
7577
7578
7579
7580
7581 enum AssignConvertType {
7582
7583 Compatible,
7584
7585
7586
7587 PointerToInt,
7588
7589
7590
7591 IntToPointer,
7592
7593
7594
7595 FunctionVoidPointer,
7596
7597
7598
7599 IncompatiblePointer,
7600
7601
7602
7603
7604 IncompatibleFunctionPointer,
7605
7606
7607
7608
7609
7610 IncompatibleFunctionPointerStrict,
7611
7612
7613
7614
7615
7616 IncompatiblePointerSign,
7617
7618
7619
7620 CompatiblePointerDiscardsQualifiers,
7621
7622
7623
7624
7625 IncompatiblePointerDiscardsQualifiers,
7626
7627
7628
7629
7630
7631 IncompatibleNestedPointerAddressSpaceMismatch,
7632
7633
7634
7635
7636
7637 IncompatibleNestedPointerQualifiers,
7638
7639
7640
7641 IncompatibleVectors,
7642
7643
7644
7645 IntToBlockPointer,
7646
7647
7648
7649 IncompatibleBlockPointer,
7650
7651
7652
7653
7654 IncompatibleObjCQualifiedId,
7655
7656
7657
7658 IncompatibleObjCWeakRef,
7659
7660
7661
7662 Incompatible
7663 };
7664
7665
7666
7667
7668 bool DiagnoseAssignmentResult(AssignConvertType ConvTy, SourceLocation Loc,
7669 QualType DstType, QualType SrcType,
7670 Expr *SrcExpr, AssignmentAction Action,
7671 bool *Complained = nullptr);
7672
7673
7674
7675
7676 AssignConvertType CheckAssignmentConstraints(SourceLocation Loc,
7677 QualType LHSType,
7678 QualType RHSType);
7679
7680
7681
7682
7683 AssignConvertType CheckAssignmentConstraints(QualType LHSType,
7684 ExprResult &RHS, CastKind &Kind,
7685 bool ConvertRHS = true);
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701 AssignConvertType CheckSingleAssignmentConstraints(
7702 QualType LHSType, ExprResult &RHS, bool Diagnose = true,
7703 bool DiagnoseCFAudited = false, bool ConvertRHS = true);
7704
7705
7706
7707 AssignConvertType CheckTransparentUnionArgumentConstraints(QualType ArgType,
7708 ExprResult &RHS);
7709
7710
7711
7712
7713
7714 QualType InvalidOperands(SourceLocation Loc, ExprResult &LHS,
7715 ExprResult &RHS);
7716
7717
7718
7719
7720 QualType InvalidLogicalVectorOperands(SourceLocation Loc, ExprResult &LHS,
7721 ExprResult &RHS);
7722
7723 QualType CheckMultiplyDivideOperands(
7724 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, bool IsCompAssign,
7725 bool IsDivide);
7726 QualType CheckRemainderOperands(
7727 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc,
7728 bool IsCompAssign = false);
7729 QualType CheckAdditionOperands(
7730 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc,
7731 BinaryOperatorKind Opc, QualType *CompLHSTy = nullptr);
7732 QualType CheckSubtractionOperands(
7733 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc,
7734 QualType *CompLHSTy = nullptr);
7735 QualType CheckShiftOperands(
7736 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc,
7737 BinaryOperatorKind Opc, bool IsCompAssign = false);
7738 void CheckPtrComparisonWithNullChar(ExprResult &E, ExprResult &NullE);
7739 QualType CheckCompareOperands(
7740 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc,
7741 BinaryOperatorKind Opc);
7742 QualType CheckBitwiseOperands(
7743 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc,
7744 BinaryOperatorKind Opc);
7745 QualType CheckLogicalOperands(
7746 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc,
7747 BinaryOperatorKind Opc);
7748
7749
7750
7751 QualType CheckAssignmentOperands(
7752 Expr *LHSExpr, ExprResult &RHS, SourceLocation Loc, QualType CompoundType,
7753 BinaryOperatorKind Opc);
7754
7755
7756
7757 static bool TooManyArguments(size_t NumParams, size_t NumArgs,
7758 bool PartialOverloading = false) {
7759
7760 if (NumArgs > 0 && PartialOverloading)
7761 return NumArgs + 1 > NumParams;
7762 return NumArgs > NumParams;
7763 }
7764
7765
7766
7767
7768 bool RebuildingImmediateInvocation = false;
7769
7770 bool isAlwaysConstantEvaluatedContext() const {
7771 const ExpressionEvaluationContextRecord &Ctx = currentEvaluationContext();
7772 return (Ctx.isConstantEvaluated() || isConstantEvaluatedOverride) &&
7773 !Ctx.InConditionallyConstantEvaluateContext;
7774 }
7775
7776
7777
7778 bool isUnevaluatedContext() const {
7779 return currentEvaluationContext().isUnevaluated();
7780 }
7781
7782 bool isImmediateFunctionContext() const {
7783 return currentEvaluationContext().isImmediateFunctionContext();
7784 }
7785
7786 bool isInLifetimeExtendingContext() const {
7787 return currentEvaluationContext().InLifetimeExtendingContext;
7788 }
7789
7790 bool needsRebuildOfDefaultArgOrInit() const {
7791 return currentEvaluationContext().RebuildDefaultArgOrDefaultInit;
7792 }
7793
7794 bool isCheckingDefaultArgumentOrInitializer() const {
7795 const ExpressionEvaluationContextRecord &Ctx = currentEvaluationContext();
7796 return (Ctx.Context ==
7797 ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed) ||
7798 Ctx.IsCurrentlyCheckingDefaultArgumentOrInitializer;
7799 }
7800
7801 std::optional<ExpressionEvaluationContextRecord::InitializationContext>
7802 InnermostDeclarationWithDelayedImmediateInvocations() const {
7803 assert(!ExprEvalContexts.empty() &&
7804 "Must be in an expression evaluation context");
7805 for (const auto &Ctx : llvm::reverse(ExprEvalContexts)) {
7806 if (Ctx.Context == ExpressionEvaluationContext::PotentiallyEvaluated &&
7807 Ctx.DelayedDefaultInitializationContext)
7808 return Ctx.DelayedDefaultInitializationContext;
7809 if (Ctx.isConstantEvaluated() || Ctx.isImmediateFunctionContext() ||
7810 Ctx.isUnevaluated())
7811 break;
7812 }
7813 return std::nullopt;
7814 }
7815
7816 std::optional<ExpressionEvaluationContextRecord::InitializationContext>
7817 OutermostDeclarationWithDelayedImmediateInvocations() const {
7818 assert(!ExprEvalContexts.empty() &&
7819 "Must be in an expression evaluation context");
7820 std::optional<ExpressionEvaluationContextRecord::InitializationContext> Res;
7821 for (auto &Ctx : llvm::reverse(ExprEvalContexts)) {
7822 if (Ctx.Context == ExpressionEvaluationContext::PotentiallyEvaluated &&
7823 !Ctx.DelayedDefaultInitializationContext && Res)
7824 break;
7825 if (Ctx.isConstantEvaluated() || Ctx.isImmediateFunctionContext() ||
7826 Ctx.isUnevaluated())
7827 break;
7828 Res = Ctx.DelayedDefaultInitializationContext;
7829 }
7830 return Res;
7831 }
7832
7833 DefaultedComparisonKind getDefaultedComparisonKind(const FunctionDecl *FD) {
7834 return getDefaultedFunctionKind(FD).asComparison();
7835 }
7836
7837
7838
7839 const FieldDecl *
7840 getSelfAssignmentClassMemberCandidate(const ValueDecl *SelfAssigned);
7841
7842 void MaybeSuggestAddingStaticToDecl(const FunctionDecl *D);
7843
7844 template <typename... Ts>
7845 bool RequireCompleteSizedType(SourceLocation Loc, QualType T, unsigned DiagID,
7846 const Ts &...Args) {
7847 SizelessTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...);
7848 return RequireCompleteType(Loc, T, CompleteTypeKind::Normal, Diagnoser);
7849 }
7850
7851 template <typename... Ts>
7852 bool RequireCompleteSizedExprType(Expr *E, unsigned DiagID,
7853 const Ts &...Args) {
7854 SizelessTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...);
7855 return RequireCompleteExprType(E, CompleteTypeKind::Normal, Diagnoser);
7856 }
7857
7858
7859 struct TypeDiagnoser {
7860 TypeDiagnoser() {}
7861
7862 virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) = 0;
7863 virtual ~TypeDiagnoser() {}
7864 };
7865
7866 template <typename... Ts> class BoundTypeDiagnoser : public TypeDiagnoser {
7867 protected:
7868 unsigned DiagID;
7869 std::tuple<const Ts &...> Args;
7870
7871 template <std::size_t... Is>
7872 void emit(const SemaDiagnosticBuilder &DB,
7873 std::index_sequence<Is...>) const {
7874
7875 bool Dummy[] = {false, (DB << getPrintable(std::get<Is>(Args)))...};
7876 (void)Dummy;
7877 }
7878
7879 public:
7880 BoundTypeDiagnoser(unsigned DiagID, const Ts &...Args)
7881 : TypeDiagnoser(), DiagID(DiagID), Args(Args...) {
7882 assert(DiagID != 0 && "no diagnostic for type diagnoser");
7883 }
7884
7885 void diagnose(Sema &S, SourceLocation Loc, QualType T) override {
7886 const SemaDiagnosticBuilder &DB = S.Diag(Loc, DiagID);
7887 emit(DB, std::index_sequence_for<Ts...>());
7888 DB << T;
7889 }
7890 };
7891
7892
7893
7894
7895
7896 template <typename... Ts>
7897 class SizelessTypeDiagnoser : public BoundTypeDiagnoser<Ts...> {
7898 public:
7899 SizelessTypeDiagnoser(unsigned DiagID, const Ts &...Args)
7900 : BoundTypeDiagnoser<Ts...>(DiagID, Args...) {}
7901
7902 void diagnose(Sema &S, SourceLocation Loc, QualType T) override {
7903 const SemaDiagnosticBuilder &DB = S.Diag(Loc, this->DiagID);
7904 this->emit(DB, std::index_sequence_for<Ts...>());
7905 DB << T->isSizelessType() << T;
7906 }
7907 };
7908
7909
7910
7911 bool CheckArgsForPlaceholders(MultiExprArg args);
7912
7913
7914
7915 RecordDecl *StdSourceLocationImplDecl;
7916
7917
7918 SmallVector<ExpressionEvaluationContextRecord, 8> ExprEvalContexts;
7919
7920
7921 llvm::SmallPtrSet<ConstantExpr *, 4> FailedImmediateInvocations;
7922
7923
7924
7925 llvm::SmallVector<std::pair<SourceLocation, const BlockDecl *>, 1>
7926 ImplicitlyRetainedSelfLocs;
7927
7928
7929 void maybeExtendBlockObject(ExprResult &E);
7930
7931 std::vector<std::pair<QualType, unsigned>> ExcessPrecisionNotSatisfied;
7932 SourceLocation LocationOfExcessPrecisionNotSatisfied;
7933 void DiagnosePrecisionLossInComplexDivision();
7934
7935 private:
7936 static BinaryOperatorKind ConvertTokenKindToBinaryOpcode(tok::TokenKind Kind);
7937
7938
7939
7940
7941
7942
7943
7944
7945 void CheckSubscriptAccessOfNoDeref(const ArraySubscriptExpr *E);
7946 void CheckAddressOfNoDeref(const Expr *E);
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960 public:
7961
7962
7963 LazyDeclPtr StdBadAlloc;
7964
7965
7966
7967 LazyDeclPtr StdAlignValT;
7968
7969
7970 RecordDecl *CXXTypeInfoDecl;
7971
7972
7973
7974 bool GlobalNewDeleteDeclared;
7975
7976
7977
7978
7979
7980
7981 llvm::MapVector<FieldDecl *, DeleteLocs> DeleteExprs;
7982
7983
7984
7985
7986
7987 ParsedType getInheritingConstructorName(CXXScopeSpec &SS,
7988 SourceLocation NameLoc,
7989 const IdentifierInfo &Name);
7990
7991 ParsedType getConstructorName(const IdentifierInfo &II,
7992 SourceLocation NameLoc, Scope *S,
7993 CXXScopeSpec &SS, bool EnteringContext);
7994 ParsedType getDestructorName(const IdentifierInfo &II, SourceLocation NameLoc,
7995 Scope *S, CXXScopeSpec &SS,
7996 ParsedType ObjectType, bool EnteringContext);
7997
7998 ParsedType getDestructorTypeForDecltype(const DeclSpec &DS,
7999 ParsedType ObjectType);
8000
8001
8002 ExprResult BuildCXXTypeId(QualType TypeInfoType, SourceLocation TypeidLoc,
8003 TypeSourceInfo *Operand, SourceLocation RParenLoc);
8004
8005
8006 ExprResult BuildCXXTypeId(QualType TypeInfoType, SourceLocation TypeidLoc,
8007 Expr *Operand, SourceLocation RParenLoc);
8008
8009
8010 ExprResult ActOnCXXTypeid(SourceLocation OpLoc, SourceLocation LParenLoc,
8011 bool isType, void *TyOrExpr,
8012 SourceLocation RParenLoc);
8013
8014
8015 ExprResult BuildCXXUuidof(QualType TypeInfoType, SourceLocation TypeidLoc,
8016 TypeSourceInfo *Operand, SourceLocation RParenLoc);
8017
8018
8019 ExprResult BuildCXXUuidof(QualType TypeInfoType, SourceLocation TypeidLoc,
8020 Expr *Operand, SourceLocation RParenLoc);
8021
8022
8023 ExprResult ActOnCXXUuidof(SourceLocation OpLoc, SourceLocation LParenLoc,
8024 bool isType, void *TyOrExpr,
8025 SourceLocation RParenLoc);
8026
8027
8028 ExprResult ActOnCXXThis(SourceLocation Loc);
8029
8030
8031 bool CheckCXXThisType(SourceLocation Loc, QualType Type);
8032
8033
8034 Expr *BuildCXXThisExpr(SourceLocation Loc, QualType Type, bool IsImplicit);
8035 void MarkThisReferenced(CXXThisExpr *This);
8036
8037
8038
8039
8040 QualType getCurrentThisType();
8041
8042
8043
8044
8045 QualType CXXThisTypeOverride;
8046
8047
8048
8049 class CXXThisScopeRAII {
8050 Sema &S;
8051 QualType OldCXXThisTypeOverride;
8052 bool Enabled;
8053
8054 public:
8055
8056
8057
8058
8059 CXXThisScopeRAII(Sema &S, Decl *ContextDecl, Qualifiers CXXThisTypeQuals,
8060 bool Enabled = true);
8061
8062 ~CXXThisScopeRAII();
8063 };
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080 bool CheckCXXThisCapture(
8081 SourceLocation Loc, bool Explicit = false, bool BuildAndDiagnose = true,
8082 const unsigned *const FunctionScopeIndexToStopAt = nullptr,
8083 bool ByCopy = false);
8084
8085
8086
8087
8088 bool isThisOutsideMemberFunctionBody(QualType BaseType);
8089
8090
8091 ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind);
8092
8093
8094 ExprResult ActOnCXXNullPtrLiteral(SourceLocation Loc);
8095
8096
8097 ExprResult ActOnCXXThrow(Scope *S, SourceLocation OpLoc, Expr *expr);
8098 ExprResult BuildCXXThrow(SourceLocation OpLoc, Expr *Ex,
8099 bool IsThrownVarInScope);
8100
8101
8102 bool CheckCXXThrowOperand(SourceLocation ThrowLoc, QualType ThrowTy, Expr *E);
8103
8104
8105
8106
8107
8108 ExprResult ActOnCXXTypeConstructExpr(ParsedType TypeRep,
8109 SourceLocation LParenOrBraceLoc,
8110 MultiExprArg Exprs,
8111 SourceLocation RParenOrBraceLoc,
8112 bool ListInitialization);
8113
8114 ExprResult BuildCXXTypeConstructExpr(TypeSourceInfo *Type,
8115 SourceLocation LParenLoc,
8116 MultiExprArg Exprs,
8117 SourceLocation RParenLoc,
8118 bool ListInitialization);
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136 ExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal,
8137 SourceLocation PlacementLParen,
8138 MultiExprArg PlacementArgs,
8139 SourceLocation PlacementRParen,
8140 SourceRange TypeIdParens, Declarator &D,
8141 Expr *Initializer);
8142 ExprResult
8143 BuildCXXNew(SourceRange Range, bool UseGlobal, SourceLocation PlacementLParen,
8144 MultiExprArg PlacementArgs, SourceLocation PlacementRParen,
8145 SourceRange TypeIdParens, QualType AllocType,
8146 TypeSourceInfo *AllocTypeInfo, std::optional<Expr *> ArraySize,
8147 SourceRange DirectInitRange, Expr *Initializer);
8148
8149
8150
8151 bool isUnavailableAlignedAllocationFunction(const FunctionDecl &FD) const;
8152
8153
8154
8155 void diagnoseUnavailableAlignedAllocation(const FunctionDecl &FD,
8156 SourceLocation Loc);
8157
8158
8159
8160 bool CheckAllocatedType(QualType AllocType, SourceLocation Loc,
8161 SourceRange R);
8162
8163
8164 enum AllocationFunctionScope {
8165
8166 AFS_Global,
8167
8168
8169 AFS_Class,
8170
8171
8172 AFS_Both
8173 };
8174
8175
8176
8177 bool FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range,
8178 AllocationFunctionScope NewScope,
8179 AllocationFunctionScope DeleteScope,
8180 QualType AllocType, bool IsArray,
8181 bool &PassAlignment, MultiExprArg PlaceArgs,
8182 FunctionDecl *&OperatorNew,
8183 FunctionDecl *&OperatorDelete,
8184 bool Diagnose = true);
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209 void DeclareGlobalNewDelete();
8210 void DeclareGlobalAllocationFunction(DeclarationName Name, QualType Return,
8211 ArrayRef<QualType> Params);
8212
8213 bool FindDeallocationFunction(SourceLocation StartLoc, CXXRecordDecl *RD,
8214 DeclarationName Name, FunctionDecl *&Operator,
8215 bool Diagnose = true, bool WantSize = false,
8216 bool WantAligned = false);
8217 FunctionDecl *FindUsualDeallocationFunction(SourceLocation StartLoc,
8218 bool CanProvideSize,
8219 bool Overaligned,
8220 DeclarationName Name);
8221 FunctionDecl *FindDeallocationFunctionForDestructor(SourceLocation StartLoc,
8222 CXXRecordDecl *RD);
8223
8224
8225
8226
8227
8228 ExprResult ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal,
8229 bool ArrayForm, Expr *Operand);
8230 void CheckVirtualDtorCall(CXXDestructorDecl *dtor, SourceLocation Loc,
8231 bool IsDelete, bool CallCanBeVirtual,
8232 bool WarnOnNonAbstractTypes,
8233 SourceLocation DtorLoc);
8234
8235 ExprResult ActOnNoexceptExpr(SourceLocation KeyLoc, SourceLocation LParen,
8236 Expr *Operand, SourceLocation RParen);
8237 ExprResult BuildCXXNoexceptExpr(SourceLocation KeyLoc, Expr *Operand,
8238 SourceLocation RParen);
8239
8240 ExprResult ActOnStartCXXMemberReference(Scope *S, Expr *Base,
8241 SourceLocation OpLoc,
8242 tok::TokenKind OpKind,
8243 ParsedType &ObjectType,
8244 bool &MayBePseudoDestructor);
8245
8246 ExprResult BuildPseudoDestructorExpr(
8247 Expr *Base, SourceLocation OpLoc, tok::TokenKind OpKind,
8248 const CXXScopeSpec &SS, TypeSourceInfo *ScopeType, SourceLocation CCLoc,
8249 SourceLocation TildeLoc, PseudoDestructorTypeStorage DestroyedType);
8250
8251 ExprResult ActOnPseudoDestructorExpr(
8252 Scope *S, Expr *Base, SourceLocation OpLoc, tok::TokenKind OpKind,
8253 CXXScopeSpec &SS, UnqualifiedId &FirstTypeName, SourceLocation CCLoc,
8254 SourceLocation TildeLoc, UnqualifiedId &SecondTypeName);
8255
8256 ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base,
8257 SourceLocation OpLoc,
8258 tok::TokenKind OpKind,
8259 SourceLocation TildeLoc,
8260 const DeclSpec &DS);
8261
8262
8263
8264
8265 Expr *MaybeCreateExprWithCleanups(Expr *SubExpr);
8266 Stmt *MaybeCreateStmtWithCleanups(Stmt *SubStmt);
8267 ExprResult MaybeCreateExprWithCleanups(ExprResult SubExpr);
8268
8269 ExprResult ActOnFinishFullExpr(Expr *Expr, bool DiscardedValue) {
8270 return ActOnFinishFullExpr(
8271 Expr, Expr ? Expr->getExprLoc() : SourceLocation(), DiscardedValue);
8272 }
8273 ExprResult ActOnFinishFullExpr(Expr *Expr, SourceLocation CC,
8274 bool DiscardedValue, bool IsConstexpr = false,
8275 bool IsTemplateArgument = false);
8276 StmtResult ActOnFinishFullStmt(Stmt *Stmt);
8277
8278
8279
8280
8281
8282 ExprResult ActOnDecltypeExpression(Expr *E);
8283
8284 bool checkLiteralOperatorId(const CXXScopeSpec &SS, const UnqualifiedId &Id,
8285 bool IsUDSuffix);
8286
8287 bool isUsualDeallocationFunction(const CXXMethodDecl *FD);
8288
8289 ConditionResult ActOnConditionVariable(Decl *ConditionVar,
8290 SourceLocation StmtLoc,
8291 ConditionKind CK);
8292
8293
8294
8295 ExprResult CheckConditionVariable(VarDecl *ConditionVar,
8296 SourceLocation StmtLoc, ConditionKind CK);
8297
8298
8299 ExprResult CheckCXXBooleanCondition(Expr *CondExpr, bool IsConstexpr = false);
8300
8301
8302
8303
8304
8305 bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType);
8306
8307
8308
8309
8310
8311
8312 ExprResult PerformImplicitConversion(
8313 Expr *From, QualType ToType, const ImplicitConversionSequence &ICS,
8314 AssignmentAction Action,
8315 CheckedConversionKind CCK = CheckedConversionKind::Implicit);
8316
8317
8318
8319
8320
8321
8322 ExprResult PerformImplicitConversion(Expr *From, QualType ToType,
8323 const StandardConversionSequence &SCS,
8324 AssignmentAction Action,
8325 CheckedConversionKind CCK);
8326
8327 bool CheckTypeTraitArity(unsigned Arity, SourceLocation Loc, size_t N);
8328
8329
8330 ExprResult ActOnTypeTrait(TypeTrait Kind, SourceLocation KWLoc,
8331 ArrayRef<ParsedType> Args,
8332 SourceLocation RParenLoc);
8333 ExprResult BuildTypeTrait(TypeTrait Kind, SourceLocation KWLoc,
8334 ArrayRef<TypeSourceInfo *> Args,
8335 SourceLocation RParenLoc);
8336
8337
8338
8339 ExprResult ActOnArrayTypeTrait(ArrayTypeTrait ATT, SourceLocation KWLoc,
8340 ParsedType LhsTy, Expr *DimExpr,
8341 SourceLocation RParen);
8342
8343 ExprResult BuildArrayTypeTrait(ArrayTypeTrait ATT, SourceLocation KWLoc,
8344 TypeSourceInfo *TSInfo, Expr *DimExpr,
8345 SourceLocation RParen);
8346
8347
8348
8349 ExprResult ActOnExpressionTrait(ExpressionTrait OET, SourceLocation KWLoc,
8350 Expr *Queried, SourceLocation RParen);
8351
8352 ExprResult BuildExpressionTrait(ExpressionTrait OET, SourceLocation KWLoc,
8353 Expr *Queried, SourceLocation RParen);
8354
8355 QualType CheckPointerToMemberOperands(
8356 ExprResult &LHS, ExprResult &RHS, ExprValueKind &VK, SourceLocation OpLoc,
8357 bool isIndirect);
8358 QualType CheckVectorConditionalTypes(ExprResult &Cond, ExprResult &LHS,
8359 ExprResult &RHS,
8360 SourceLocation QuestionLoc);
8361
8362 QualType CheckSizelessVectorConditionalTypes(ExprResult &Cond,
8363 ExprResult &LHS, ExprResult &RHS,
8364 SourceLocation QuestionLoc);
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386 QualType CXXCheckConditionalOperands(
8387 ExprResult &cond, ExprResult &lhs, ExprResult &rhs, ExprValueKind &VK,
8388 ExprObjectKind &OK, SourceLocation questionLoc);
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402 QualType FindCompositePointerType(SourceLocation Loc, Expr *&E1, Expr *&E2,
8403 bool ConvertArgs = true);
8404 QualType FindCompositePointerType(SourceLocation Loc, ExprResult &E1,
8405 ExprResult &E2, bool ConvertArgs = true) {
8406 Expr *E1Tmp = E1.get(), *E2Tmp = E2.get();
8407 QualType Composite =
8408 FindCompositePointerType(Loc, E1Tmp, E2Tmp, ConvertArgs);
8409 E1 = E1Tmp;
8410 E2 = E2Tmp;
8411 return Composite;
8412 }
8413
8414
8415
8416
8417 ExprResult MaybeBindToTemporary(Expr *E);
8418
8419
8420
8421
8422 ExprResult IgnoredValueConversions(Expr *E);
8423
8424 ExprResult CheckUnevaluatedOperand(Expr *E);
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443 ExprResult CorrectDelayedTyposInExpr(
8444 Expr *E, VarDecl *InitDecl = nullptr,
8445 bool RecoverUncorrectedTypos = false,
8446 llvm::function_ref<ExprResult(Expr *)> Filter =
8447 [](Expr *E) -> ExprResult { return E; });
8448
8449 ExprResult CorrectDelayedTyposInExpr(
8450 ExprResult ER, VarDecl *InitDecl = nullptr,
8451 bool RecoverUncorrectedTypos = false,
8452 llvm::function_ref<ExprResult(Expr *)> Filter =
8453 [](Expr *E) -> ExprResult { return E; }) {
8454 return ER.isInvalid()
8455 ? ER
8456 : CorrectDelayedTyposInExpr(ER.get(), InitDecl,
8457 RecoverUncorrectedTypos, Filter);
8458 }
8459
8460
8461 enum IfExistsResult {
8462
8463 IER_Exists,
8464
8465
8466 IER_DoesNotExist,
8467
8468
8469
8470 IER_Dependent,
8471
8472
8473 IER_Error
8474 };
8475
8476 IfExistsResult
8477 CheckMicrosoftIfExistsSymbol(Scope *S, CXXScopeSpec &SS,
8478 const DeclarationNameInfo &TargetNameInfo);
8479
8480 IfExistsResult CheckMicrosoftIfExistsSymbol(Scope *S,
8481 SourceLocation KeywordLoc,
8482 bool IsIfExists, CXXScopeSpec &SS,
8483 UnqualifiedId &Name);
8484
8485 RequiresExprBodyDecl *
8486 ActOnStartRequiresExpr(SourceLocation RequiresKWLoc,
8487 ArrayRef<ParmVarDecl *> LocalParameters,
8488 Scope *BodyScope);
8489 void ActOnFinishRequiresExpr();
8490 concepts::Requirement *ActOnSimpleRequirement(Expr *E);
8491 concepts::Requirement *ActOnTypeRequirement(SourceLocation TypenameKWLoc,
8492 CXXScopeSpec &SS,
8493 SourceLocation NameLoc,
8494 const IdentifierInfo *TypeName,
8495 TemplateIdAnnotation *TemplateId);
8496 concepts::Requirement *ActOnCompoundRequirement(Expr *E,
8497 SourceLocation NoexceptLoc);
8498 concepts::Requirement *ActOnCompoundRequirement(
8499 Expr *E, SourceLocation NoexceptLoc, CXXScopeSpec &SS,
8500 TemplateIdAnnotation *TypeConstraint, unsigned Depth);
8501 concepts::Requirement *ActOnNestedRequirement(Expr *Constraint);
8502 concepts::ExprRequirement *BuildExprRequirement(
8503 Expr *E, bool IsSatisfied, SourceLocation NoexceptLoc,
8504 concepts::ExprRequirement::ReturnTypeRequirement ReturnTypeRequirement);
8505 concepts::ExprRequirement *BuildExprRequirement(
8506 concepts::Requirement::SubstitutionDiagnostic *ExprSubstDiag,
8507 bool IsSatisfied, SourceLocation NoexceptLoc,
8508 concepts::ExprRequirement::ReturnTypeRequirement ReturnTypeRequirement);
8509 concepts::TypeRequirement *BuildTypeRequirement(TypeSourceInfo *Type);
8510 concepts::TypeRequirement *BuildTypeRequirement(
8511 concepts::Requirement::SubstitutionDiagnostic *SubstDiag);
8512 concepts::NestedRequirement *BuildNestedRequirement(Expr *E);
8513 concepts::NestedRequirement *
8514 BuildNestedRequirement(StringRef InvalidConstraintEntity,
8515 const ASTConstraintSatisfaction &Satisfaction);
8516 ExprResult ActOnRequiresExpr(SourceLocation RequiresKWLoc,
8517 RequiresExprBodyDecl *Body,
8518 SourceLocation LParenLoc,
8519 ArrayRef<ParmVarDecl *> LocalParameters,
8520 SourceLocation RParenLoc,
8521 ArrayRef<concepts::Requirement *> Requirements,
8522 SourceLocation ClosingBraceLoc);
8523
8524 private:
8525 ExprResult BuiltinOperatorNewDeleteOverloaded(ExprResult TheCallResult,
8526 bool IsDelete);
8527
8528 void AnalyzeDeleteExprMismatch(const CXXDeleteExpr *DE);
8529 void AnalyzeDeleteExprMismatch(FieldDecl *Field, SourceLocation DeleteLoc,
8530 bool DeleteWasArrayForm);
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544 public:
8545
8546 bool isPotentialImplicitMemberAccess(const CXXScopeSpec &SS, LookupResult &R,
8547 bool IsAddressOfOperand);
8548
8549
8550 ExprResult BuildPossibleImplicitMemberExpr(
8551 const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, LookupResult &R,
8552 const TemplateArgumentListInfo *TemplateArgs, const Scope *S);
8553
8554
8555
8556
8557
8558 ExprResult
8559 BuildImplicitMemberExpr(const CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
8560 LookupResult &R,
8561 const TemplateArgumentListInfo *TemplateArgs,
8562 bool IsDefiniteInstance, const Scope *S);
8563
8564 ExprResult ActOnDependentMemberExpr(
8565 Expr *Base, QualType BaseType, bool IsArrow, SourceLocation OpLoc,
8566 const CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
8567 NamedDecl *FirstQualifierInScope, const DeclarationNameInfo &NameInfo,
8568 const TemplateArgumentListInfo *TemplateArgs);
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580 ExprResult ActOnMemberAccessExpr(Scope *S, Expr *Base, SourceLocation OpLoc,
8581 tok::TokenKind OpKind, CXXScopeSpec &SS,
8582 SourceLocation TemplateKWLoc,
8583 UnqualifiedId &Member, Decl *ObjCImpDecl);
8584
8585 MemberExpr *
8586 BuildMemberExpr(Expr *Base, bool IsArrow, SourceLocation OpLoc,
8587 NestedNameSpecifierLoc NNS, SourceLocation TemplateKWLoc,
8588 ValueDecl *Member, DeclAccessPair FoundDecl,
8589 bool HadMultipleCandidates,
8590 const DeclarationNameInfo &MemberNameInfo, QualType Ty,
8591 ExprValueKind VK, ExprObjectKind OK,
8592 const TemplateArgumentListInfo *TemplateArgs = nullptr);
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606 bool CheckQualifiedMemberReference(Expr *BaseExpr, QualType BaseType,
8607 const CXXScopeSpec &SS,
8608 const LookupResult &R);
8609
8610
8611
8612
8613
8614
8615 struct ActOnMemberAccessExtraArgs {
8616 Scope *S;
8617 UnqualifiedId &Id;
8618 Decl *ObjCImpDecl;
8619 };
8620
8621 ExprResult BuildMemberReferenceExpr(
8622 Expr *Base, QualType BaseType, SourceLocation OpLoc, bool IsArrow,
8623 CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
8624 NamedDecl *FirstQualifierInScope, const DeclarationNameInfo &NameInfo,
8625 const TemplateArgumentListInfo *TemplateArgs, const Scope *S,
8626 ActOnMemberAccessExtraArgs *ExtraArgs = nullptr);
8627
8628 ExprResult
8629 BuildMemberReferenceExpr(Expr *Base, QualType BaseType, SourceLocation OpLoc,
8630 bool IsArrow, const CXXScopeSpec &SS,
8631 SourceLocation TemplateKWLoc,
8632 NamedDecl *FirstQualifierInScope, LookupResult &R,
8633 const TemplateArgumentListInfo *TemplateArgs,
8634 const Scope *S, bool SuppressQualifierCheck = false,
8635 ActOnMemberAccessExtraArgs *ExtraArgs = nullptr);
8636
8637 ExprResult BuildFieldReferenceExpr(Expr *BaseExpr, bool IsArrow,
8638 SourceLocation OpLoc,
8639 const CXXScopeSpec &SS, FieldDecl *Field,
8640 DeclAccessPair FoundDecl,
8641 const DeclarationNameInfo &MemberNameInfo);
8642
8643
8644 ExprResult PerformMemberExprBaseConversion(Expr *Base, bool IsArrow);
8645
8646 ExprResult BuildAnonymousStructUnionMemberReference(
8647 const CXXScopeSpec &SS, SourceLocation nameLoc,
8648 IndirectFieldDecl *indirectField,
8649 DeclAccessPair FoundDecl = DeclAccessPair::make(nullptr, AS_none),
8650 Expr *baseObjectExpr = nullptr, SourceLocation opLoc = SourceLocation());
8651
8652 private:
8653 void CheckMemberAccessOfNoDeref(const MemberExpr *E);
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667 public:
8668
8669
8670 llvm::SmallVector<QualType, 4> CurrentParameterCopyTypes;
8671
8672 llvm::DenseMap<unsigned, CXXDeductionGuideDecl *>
8673 AggregateDeductionCandidates;
8674
8675 bool IsStringInit(Expr *Init, const ArrayType *AT);
8676
8677
8678
8679 bool CanPerformAggregateInitializationForOverloadResolution(
8680 const InitializedEntity &Entity, InitListExpr *From);
8681
8682 ExprResult ActOnDesignatedInitializer(Designation &Desig,
8683 SourceLocation EqualOrColonLoc,
8684 bool GNUSyntax, ExprResult Init);
8685
8686
8687
8688
8689 void checkInitializerLifetime(const InitializedEntity &Entity, Expr *Init);
8690
8691 MaterializeTemporaryExpr *
8692 CreateMaterializeTemporaryExpr(QualType T, Expr *Temporary,
8693 bool BoundToLvalueReference);
8694
8695
8696
8697
8698 ExprResult TemporaryMaterializationConversion(Expr *E);
8699
8700 ExprResult PerformQualificationConversion(
8701 Expr *E, QualType Ty, ExprValueKind VK = VK_PRValue,
8702 CheckedConversionKind CCK = CheckedConversionKind::Implicit);
8703
8704 bool CanPerformCopyInitialization(const InitializedEntity &Entity,
8705 ExprResult Init);
8706 ExprResult PerformCopyInitialization(const InitializedEntity &Entity,
8707 SourceLocation EqualLoc, ExprResult Init,
8708 bool TopLevelOfInitList = false,
8709 bool AllowExplicit = false);
8710
8711 QualType DeduceTemplateSpecializationFromInitializer(
8712 TypeSourceInfo *TInfo, const InitializedEntity &Entity,
8713 const InitializationKind &Kind, MultiExprArg Init);
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727 public:
8728
8729 CXXRecordDecl *createLambdaClosureType(SourceRange IntroducerRange,
8730 TypeSourceInfo *Info,
8731 unsigned LambdaDependencyKind,
8732 LambdaCaptureDefault CaptureDefault);
8733
8734
8735 void handleLambdaNumbering(CXXRecordDecl *Class, CXXMethodDecl *Method,
8736 std::optional<CXXRecordDecl::LambdaNumbering>
8737 NumberingOverride = std::nullopt);
8738
8739
8740 void buildLambdaScope(sema::LambdaScopeInfo *LSI, CXXMethodDecl *CallOperator,
8741 SourceRange IntroducerRange,
8742 LambdaCaptureDefault CaptureDefault,
8743 SourceLocation CaptureDefaultLoc, bool ExplicitParams,
8744 bool Mutable);
8745
8746 CXXMethodDecl *CreateLambdaCallOperator(SourceRange IntroducerRange,
8747 CXXRecordDecl *Class);
8748
8749 void AddTemplateParametersToLambdaCallOperator(
8750 CXXMethodDecl *CallOperator, CXXRecordDecl *Class,
8751 TemplateParameterList *TemplateParams);
8752
8753 void CompleteLambdaCallOperator(
8754 CXXMethodDecl *Method, SourceLocation LambdaLoc,
8755 SourceLocation CallOperatorLoc, Expr *TrailingRequiresClause,
8756 TypeSourceInfo *MethodTyInfo, ConstexprSpecKind ConstexprKind,
8757 StorageClass SC, ArrayRef<ParmVarDecl *> Params,
8758 bool HasExplicitResultType);
8759
8760
8761 bool DiagnoseInvalidExplicitObjectParameterInLambda(CXXMethodDecl *Method,
8762 SourceLocation CallLoc);
8763
8764
8765
8766
8767 ParsedType actOnLambdaInitCaptureInitialization(
8768 SourceLocation Loc, bool ByRef, SourceLocation EllipsisLoc,
8769 IdentifierInfo *Id, LambdaCaptureInitKind InitKind, Expr *&Init) {
8770 return ParsedType::make(buildLambdaInitCaptureInitialization(
8771 Loc, ByRef, EllipsisLoc, std::nullopt, Id,
8772 InitKind != LambdaCaptureInitKind::CopyInit, Init));
8773 }
8774 QualType buildLambdaInitCaptureInitialization(
8775 SourceLocation Loc, bool ByRef, SourceLocation EllipsisLoc,
8776 std::optional<unsigned> NumExpansions, IdentifierInfo *Id,
8777 bool DirectInit, Expr *&Init);
8778
8779
8780
8781
8782
8783
8784 VarDecl *createLambdaInitCaptureVarDecl(
8785 SourceLocation Loc, QualType InitCaptureType, SourceLocation EllipsisLoc,
8786 IdentifierInfo *Id, unsigned InitStyle, Expr *Init, DeclContext *DeclCtx);
8787
8788
8789 void addInitCapture(sema::LambdaScopeInfo *LSI, VarDecl *Var, bool ByRef);
8790
8791
8792
8793 void finishLambdaExplicitCaptures(sema::LambdaScopeInfo *LSI);
8794
8795
8796
8797 void deduceClosureReturnType(sema::CapturingScopeInfo &CSI);
8798
8799
8800
8801
8802
8803 void ActOnLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro,
8804 Scope *CurContext);
8805
8806
8807
8808 void ActOnLambdaExplicitTemplateParameterList(LambdaIntroducer &Intro,
8809 SourceLocation LAngleLoc,
8810 ArrayRef<NamedDecl *> TParams,
8811 SourceLocation RAngleLoc,
8812 ExprResult RequiresClause);
8813
8814 void ActOnLambdaClosureQualifiers(LambdaIntroducer &Intro,
8815 SourceLocation MutableLoc);
8816
8817 void ActOnLambdaClosureParameters(
8818 Scope *LambdaScope,
8819 MutableArrayRef<DeclaratorChunk::ParamInfo> ParamInfo);
8820
8821
8822
8823
8824
8825 void ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro,
8826 Declarator &ParamInfo, const DeclSpec &DS);
8827
8828
8829
8830 void ActOnLambdaError(SourceLocation StartLoc, Scope *CurScope,
8831 bool IsInstantiation = false);
8832
8833
8834
8835 ExprResult ActOnLambdaExpr(SourceLocation StartLoc, Stmt *Body);
8836
8837
8838 bool CaptureHasSideEffects(const sema::Capture &From);
8839
8840
8841
8842 bool DiagnoseUnusedLambdaCapture(SourceRange CaptureRange,
8843 const sema::Capture &From);
8844
8845
8846 FieldDecl *BuildCaptureField(RecordDecl *RD, const sema::Capture &Capture);
8847
8848
8849 ExprResult BuildCaptureInit(const sema::Capture &Capture,
8850 SourceLocation ImplicitCaptureLoc,
8851 bool IsOpenMPMapping = false);
8852
8853
8854
8855 ExprResult BuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc,
8856 sema::LambdaScopeInfo *LSI);
8857
8858
8859
8860 QualType
8861 getLambdaConversionFunctionResultType(const FunctionProtoType *CallOpType,
8862 CallingConv CC);
8863
8864 ExprResult BuildBlockForLambdaConversion(SourceLocation CurrentLocation,
8865 SourceLocation ConvLocation,
8866 CXXConversionDecl *Conv, Expr *Src);
8867
8868 class LambdaScopeForCallOperatorInstantiationRAII
8869 : private FunctionScopeRAII {
8870 public:
8871 LambdaScopeForCallOperatorInstantiationRAII(
8872 Sema &SemasRef, FunctionDecl *FD, MultiLevelTemplateArgumentList MLTAL,
8873 LocalInstantiationScope &Scope,
8874 bool ShouldAddDeclsFromParentScope = true);
8875 };
8876
8877
8878
8879
8880
8881
8882 std::tuple<MangleNumberingContext *, Decl *>
8883 getCurrentMangleNumberContext(const DeclContext *DC);
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922 public:
8923
8924
8925 bool DisableTypoCorrection;
8926
8927
8928 unsigned TyposCorrected;
8929
8930 typedef llvm::SmallSet<SourceLocation, 2> SrcLocSet;
8931 typedef llvm::DenseMap<IdentifierInfo *, SrcLocSet> IdentifierSourceLocations;
8932
8933
8934
8935
8936 IdentifierSourceLocations TypoCorrectionFailures;
8937
8938
8939
8940
8941
8942
8943 class SpecialMemberOverloadResult {
8944 public:
8945 enum Kind { NoMemberOrDeleted, Ambiguous, Success };
8946
8947 private:
8948 llvm::PointerIntPair<CXXMethodDecl *, 2> Pair;
8949
8950 public:
8951 SpecialMemberOverloadResult() {}
8952 SpecialMemberOverloadResult(CXXMethodDecl *MD)
8953 : Pair(MD, MD->isDeleted() ? NoMemberOrDeleted : Success) {}
8954
8955 CXXMethodDecl *getMethod() const { return Pair.getPointer(); }
8956 void setMethod(CXXMethodDecl *MD) { Pair.setPointer(MD); }
8957
8958 Kind getKind() const { return static_cast<Kind>(Pair.getInt()); }
8959 void setKind(Kind K) { Pair.setInt(K); }
8960 };
8961
8962 class SpecialMemberOverloadResultEntry : public llvm::FastFoldingSetNode,
8963 public SpecialMemberOverloadResult {
8964 public:
8965 SpecialMemberOverloadResultEntry(const llvm::FoldingSetNodeID &ID)
8966 : FastFoldingSetNode(ID) {}
8967 };
8968
8969
8970
8971 llvm::FoldingSet<SpecialMemberOverloadResultEntry> SpecialMemberCache;
8972
8973
8974
8975
8976
8977 llvm::SmallVector<TypoExpr *, 2> TypoExprs;
8978
8979 enum class AcceptableKind { Visible, Reachable };
8980
8981
8982
8983 typedef llvm::SmallSetVector<DeclContext *, 16> AssociatedNamespaceSet;
8984 typedef llvm::SmallSetVector<CXXRecordDecl *, 16> AssociatedClassSet;
8985
8986
8987 enum LookupNameKind {
8988
8989
8990
8991 LookupOrdinaryName = 0,
8992
8993
8994 LookupTagName,
8995
8996 LookupLabel,
8997
8998
8999 LookupMemberName,
9000
9001
9002
9003 LookupOperatorName,
9004
9005
9006 LookupDestructorName,
9007
9008
9009
9010 LookupNestedNameSpecifierName,
9011
9012
9013
9014 LookupNamespaceName,
9015
9016
9017
9018 LookupUsingDeclName,
9019
9020
9021
9022
9023 LookupRedeclarationWithLinkage,
9024
9025
9026 LookupLocalFriendName,
9027
9028 LookupObjCProtocolName,
9029
9030 LookupObjCImplicitSelfParam,
9031
9032 LookupOMPReductionName,
9033
9034 LookupOMPMapperName,
9035
9036 LookupAnyName
9037 };
9038
9039
9040 enum LiteralOperatorLookupResult {
9041
9042 LOLR_Error,
9043
9044 LOLR_ErrorNoDiagnostic,
9045
9046
9047 LOLR_Cooked,
9048
9049
9050 LOLR_Raw,
9051
9052
9053
9054 LOLR_Template,
9055
9056
9057
9058 LOLR_StringTemplatePack,
9059 };
9060
9061 SpecialMemberOverloadResult
9062 LookupSpecialMember(CXXRecordDecl *D, CXXSpecialMemberKind SM, bool ConstArg,
9063 bool VolatileArg, bool RValueThis, bool ConstThis,
9064 bool VolatileThis);
9065
9066 typedef std::function<void(const TypoCorrection &)> TypoDiagnosticGenerator;
9067 typedef std::function<ExprResult(Sema &, TypoExpr *, TypoCorrection)>
9068 TypoRecoveryCallback;
9069
9070 RedeclarationKind forRedeclarationInCurContext() const;
9071
9072
9073
9074
9075
9076
9077 NamedDecl *LookupSingleName(
9078 Scope *S, DeclarationName Name, SourceLocation Loc,
9079 LookupNameKind NameKind,
9080 RedeclarationKind Redecl = RedeclarationKind::NotForRedeclaration);
9081
9082
9083
9084 bool LookupBuiltin(LookupResult &R);
9085 void LookupNecessaryTypesForBuiltin(Scope *S, unsigned ID);
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115 bool LookupName(LookupResult &R, Scope *S, bool AllowBuiltinCreation = false,
9116 bool ForceNoCPlusPlus = false);
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140 bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx,
9141 bool InUnqualifiedLookup = false);
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158 bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx,
9159 CXXScopeSpec &SS);
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180 bool LookupParsedName(LookupResult &R, Scope *S, CXXScopeSpec *SS,
9181 QualType ObjectType, bool AllowBuiltinCreation = false,
9182 bool EnteringContext = false);
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193 bool LookupInSuper(LookupResult &R, CXXRecordDecl *Class);
9194
9195 void LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S,
9196 UnresolvedSetImpl &Functions);
9197
9198
9199
9200
9201
9202 LabelDecl *LookupOrCreateLabel(IdentifierInfo *II, SourceLocation IdentLoc,
9203 SourceLocation GnuLabelLoc = SourceLocation());
9204
9205
9206 DeclContextLookupResult LookupConstructors(CXXRecordDecl *Class);
9207
9208
9209 CXXConstructorDecl *LookupDefaultConstructor(CXXRecordDecl *Class);
9210
9211
9212 CXXConstructorDecl *LookupCopyingConstructor(CXXRecordDecl *Class,
9213 unsigned Quals);
9214
9215
9216 CXXMethodDecl *LookupCopyingAssignment(CXXRecordDecl *Class, unsigned Quals,
9217 bool RValueThis, unsigned ThisQuals);
9218
9219
9220 CXXConstructorDecl *LookupMovingConstructor(CXXRecordDecl *Class,
9221 unsigned Quals);
9222
9223
9224 CXXMethodDecl *LookupMovingAssignment(CXXRecordDecl *Class, unsigned Quals,
9225 bool RValueThis, unsigned ThisQuals);
9226
9227
9228
9229
9230
9231
9232
9233 CXXDestructorDecl *LookupDestructor(CXXRecordDecl *Class);
9234
9235
9236
9237 void ForceDeclarationOfImplicitMembers(CXXRecordDecl *Class);
9238
9239
9240
9241 void makeMergedDefinitionVisible(NamedDecl *ND);
9242
9243
9244
9245
9246 template <typename T,
9247 typename = std::enable_if_t<std::is_base_of<NamedDecl, T>::value>>
9248 bool ActOnDuplicateODRHashDefinition(T *Duplicate, T *Previous) {
9249 if (Duplicate->getODRHash() != Previous->getODRHash())
9250 return false;
9251
9252
9253 makeMergedDefinitionVisible(Previous);
9254 return true;
9255 }
9256
9257
9258
9259
9260 llvm::DenseSet<Module *> &getLookupModules();
9261
9262 bool hasVisibleMergedDefinition(const NamedDecl *Def);
9263 bool hasMergedDefinitionInCurrentModule(const NamedDecl *Def);
9264
9265
9266 bool
9267 hasVisibleDefaultArgument(const NamedDecl *D,
9268 llvm::SmallVectorImpl<Module *> *Modules = nullptr);
9269
9270 bool hasReachableDefaultArgument(
9271 const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr);
9272
9273 bool hasAcceptableDefaultArgument(const NamedDecl *D,
9274 llvm::SmallVectorImpl<Module *> *Modules,
9275 Sema::AcceptableKind Kind);
9276
9277
9278
9279
9280 bool hasVisibleExplicitSpecialization(
9281 const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr);
9282
9283
9284
9285 bool hasReachableExplicitSpecialization(
9286 const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr);
9287
9288
9289
9290 bool hasVisibleMemberSpecialization(
9291 const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr);
9292
9293
9294 bool hasReachableMemberSpecialization(
9295 const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr);
9296
9297 bool isModuleVisible(const Module *M, bool ModulePrivate = false);
9298
9299
9300 bool
9301 hasVisibleDeclaration(const NamedDecl *D,
9302 llvm::SmallVectorImpl<Module *> *Modules = nullptr) {
9303 return isVisible(D) || hasVisibleDeclarationSlow(D, Modules);
9304 }
9305
9306 bool hasVisibleDeclarationSlow(const NamedDecl *D,
9307 llvm::SmallVectorImpl<Module *> *Modules);
9308
9309 bool
9310 hasReachableDeclaration(const NamedDecl *D,
9311 llvm::SmallVectorImpl<Module *> *Modules = nullptr) {
9312 return isReachable(D) || hasReachableDeclarationSlow(D, Modules);
9313 }
9314 bool hasReachableDeclarationSlow(
9315 const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr);
9316
9317 void diagnoseTypo(const TypoCorrection &Correction,
9318 const PartialDiagnostic &TypoDiag,
9319 bool ErrorRecovery = true);
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334 void diagnoseTypo(const TypoCorrection &Correction,
9335 const PartialDiagnostic &TypoDiag,
9336 const PartialDiagnostic &PrevNote,
9337 bool ErrorRecovery = true);
9338
9339
9340
9341
9342
9343
9344
9345
9346 void FindAssociatedClassesAndNamespaces(
9347 SourceLocation InstantiationLoc, ArrayRef<Expr *> Args,
9348 AssociatedNamespaceSet &AssociatedNamespaces,
9349 AssociatedClassSet &AssociatedClasses);
9350
9351
9352
9353
9354
9355 void DiagnoseAmbiguousLookup(LookupResult &Result);
9356
9357
9358
9359
9360
9361
9362
9363
9364 LiteralOperatorLookupResult
9365 LookupLiteralOperator(Scope *S, LookupResult &R, ArrayRef<QualType> ArgTys,
9366 bool AllowRaw, bool AllowTemplate,
9367 bool AllowStringTemplate, bool DiagnoseMissing,
9368 StringLiteral *StringLit = nullptr);
9369
9370 void ArgumentDependentLookup(DeclarationName Name, SourceLocation Loc,
9371 ArrayRef<Expr *> Args, ADLResult &Functions);
9372
9373 void LookupVisibleDecls(Scope *S, LookupNameKind Kind,
9374 VisibleDeclConsumer &Consumer,
9375 bool IncludeGlobalScope = true,
9376 bool LoadExternal = true);
9377 void LookupVisibleDecls(DeclContext *Ctx, LookupNameKind Kind,
9378 VisibleDeclConsumer &Consumer,
9379 bool IncludeGlobalScope = true,
9380 bool IncludeDependentBases = false,
9381 bool LoadExternal = true);
9382
9383 enum CorrectTypoKind {
9384 CTK_NonError,
9385 CTK_ErrorRecovery
9386 };
9387
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419 TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo,
9420 Sema::LookupNameKind LookupKind, Scope *S,
9421 CXXScopeSpec *SS, CorrectionCandidateCallback &CCC,
9422 CorrectTypoKind Mode,
9423 DeclContext *MemberContext = nullptr,
9424 bool EnteringContext = false,
9425 const ObjCObjectPointerType *OPT = nullptr,
9426 bool RecordFailure = true);
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9466 TypoExpr *CorrectTypoDelayed(
9467 const DeclarationNameInfo &Typo, Sema::LookupNameKind LookupKind,
9468 Scope *S, CXXScopeSpec *SS, CorrectionCandidateCallback &CCC,
9469 TypoDiagnosticGenerator TDG, TypoRecoveryCallback TRC,
9470 CorrectTypoKind Mode, DeclContext *MemberContext = nullptr,
9471 bool EnteringContext = false, const ObjCObjectPointerType *OPT = nullptr);
9472
9473
9474
9475 enum class MissingImportKind {
9476 Declaration,
9477 Definition,
9478 DefaultArgument,
9479 ExplicitSpecialization,
9480 PartialSpecialization
9481 };
9482
9483
9484
9485 void diagnoseMissingImport(SourceLocation Loc, const NamedDecl *Decl,
9486 MissingImportKind MIK, bool Recover = true);
9487 void diagnoseMissingImport(SourceLocation Loc, const NamedDecl *Decl,
9488 SourceLocation DeclLoc, ArrayRef<Module *> Modules,
9489 MissingImportKind MIK, bool Recover);
9490
9491 struct TypoExprState {
9492 std::unique_ptr<TypoCorrectionConsumer> Consumer;
9493 TypoDiagnosticGenerator DiagHandler;
9494 TypoRecoveryCallback RecoveryHandler;
9495 TypoExprState();
9496 TypoExprState(TypoExprState &&other) noexcept;
9497 TypoExprState &operator=(TypoExprState &&other) noexcept;
9498 };
9499
9500 const TypoExprState &getTypoExprState(TypoExpr *TE) const;
9501
9502
9503 void clearDelayedTypo(TypoExpr *TE);
9504
9505
9506 void ActOnPragmaDump(Scope *S, SourceLocation Loc, IdentifierInfo *II);
9507
9508
9509 void ActOnPragmaDump(Expr *E);
9510
9511 private:
9512
9513
9514
9515
9516 llvm::MapVector<NamespaceDecl *, bool> KnownNamespaces;
9517
9518
9519
9520 bool LoadedExternalKnownNamespaces;
9521
9522 bool CppLookupName(LookupResult &R, Scope *S);
9523
9524
9525 bool isUsableModule(const Module *M);
9526
9527
9528
9529
9530 std::unique_ptr<TypoCorrectionConsumer> makeTypoCorrectionConsumer(
9531 const DeclarationNameInfo &Typo, Sema::LookupNameKind LookupKind,
9532 Scope *S, CXXScopeSpec *SS, CorrectionCandidateCallback &CCC,
9533 DeclContext *MemberContext, bool EnteringContext,
9534 const ObjCObjectPointerType *OPT, bool ErrorRecovery);
9535
9536
9537 llvm::MapVector<TypoExpr *, TypoExprState> DelayedTypos;
9538
9539
9540 TypoExpr *createDelayedTypo(std::unique_ptr<TypoCorrectionConsumer> TCC,
9541 TypoDiagnosticGenerator TDG,
9542 TypoRecoveryCallback TRC, SourceLocation TypoLoc);
9543
9544
9545 llvm::DenseSet<const Module *> UsableModuleUnitsCache;
9546
9547
9548 TypoCorrection FailedCorrection(IdentifierInfo *Typo, SourceLocation TypoLoc,
9549 bool RecordFailure = true) {
9550 if (RecordFailure)
9551 TypoCorrectionFailures[Typo].insert(TypoLoc);
9552 return TypoCorrection();
9553 }
9554
9555 bool isAcceptableSlow(const NamedDecl *D, AcceptableKind Kind);
9556
9557
9558
9559
9560 bool shouldLinkPossiblyHiddenDecl(const NamedDecl *Old,
9561 const NamedDecl *New) {
9562 if (isVisible(Old))
9563 return true;
9564
9565
9566 if (New->isExternallyDeclarable()) {
9567 assert(Old->isExternallyDeclarable() &&
9568 "should not have found a non-externally-declarable previous decl");
9569 return true;
9570 }
9571 return false;
9572 }
9573 bool shouldLinkPossiblyHiddenDecl(LookupResult &Old, const NamedDecl *New);
9574
9575
9576
9577
9578
9579
9580
9581
9582
9583
9584
9585
9586
9587 public:
9588
9589 Module *getCurrentModule() const {
9590 return ModuleScopes.empty() ? nullptr : ModuleScopes.back().Module;
9591 }
9592
9593
9594 bool currentModuleIsImplementation() const {
9595 return ModuleScopes.empty()
9596 ? false
9597 : ModuleScopes.back().Module->isModuleImplementation();
9598 }
9599
9600
9601
9602 void makeModuleVisible(Module *Mod, SourceLocation ImportLoc) {
9603 VisibleModules.setVisible(Mod, ImportLoc);
9604 }
9605
9606 enum class ModuleDeclKind {
9607 Interface,
9608 Implementation,
9609 PartitionInterface,
9610 PartitionImplementation,
9611 };
9612
9613
9614
9615
9616 enum class ModuleImportState {
9617 FirstDecl,
9618 GlobalFragment,
9619 ImportAllowed,
9620 ImportFinished,
9621 PrivateFragmentImportAllowed,
9622
9623 PrivateFragmentImportFinished,
9624
9625 NotACXX20Module
9626 };
9627
9628
9629
9630 DeclGroupPtrTy ActOnModuleDecl(SourceLocation StartLoc,
9631 SourceLocation ModuleLoc, ModuleDeclKind MDK,
9632 ModuleIdPath Path, ModuleIdPath Partition,
9633 ModuleImportState &ImportState);
9634
9635
9636
9637
9638 DeclGroupPtrTy ActOnGlobalModuleFragmentDecl(SourceLocation ModuleLoc);
9639
9640
9641
9642
9643
9644 DeclGroupPtrTy ActOnPrivateModuleFragmentDecl(SourceLocation ModuleLoc,
9645 SourceLocation PrivateLoc);
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655 DeclResult ActOnModuleImport(SourceLocation StartLoc,
9656 SourceLocation ExportLoc,
9657 SourceLocation ImportLoc, ModuleIdPath Path,
9658 bool IsPartition = false);
9659 DeclResult ActOnModuleImport(SourceLocation StartLoc,
9660 SourceLocation ExportLoc,
9661 SourceLocation ImportLoc, Module *M,
9662 ModuleIdPath Path = {});
9663
9664
9665
9666 void ActOnAnnotModuleInclude(SourceLocation DirectiveLoc, Module *Mod);
9667 void BuildModuleInclude(SourceLocation DirectiveLoc, Module *Mod);
9668
9669
9670 void ActOnAnnotModuleBegin(SourceLocation DirectiveLoc, Module *Mod);
9671
9672 void ActOnAnnotModuleEnd(SourceLocation DirectiveLoc, Module *Mod);
9673
9674
9675
9676
9677
9678
9679
9680 void createImplicitModuleImportForErrorRecovery(SourceLocation Loc,
9681 Module *Mod);
9682
9683
9684
9685 Decl *ActOnStartExportDecl(Scope *S, SourceLocation ExportLoc,
9686 SourceLocation LBraceLoc);
9687
9688
9689 Decl *ActOnFinishExportDecl(Scope *S, Decl *ExportDecl,
9690 SourceLocation RBraceLoc);
9691
9692 private:
9693
9694
9695 void HandleStartOfHeaderUnit();
9696
9697 struct ModuleScope {
9698 SourceLocation BeginLoc;
9699 clang::Module *Module = nullptr;
9700 VisibleModuleSet OuterVisibleModules;
9701 };
9702
9703 llvm::SmallVector<ModuleScope, 16> ModuleScopes;
9704
9705
9706 clang::Module *ThePrimaryInterface = nullptr;
9707
9708
9709
9710
9711 clang::Module *TheGlobalModuleFragment = nullptr;
9712
9713
9714
9715
9716 clang::Module *TheImplicitGlobalModuleFragment = nullptr;
9717
9718
9719 llvm::SmallPtrSet<const NamespaceDecl *, 8> DeferredExportedNamespaces;
9720
9721
9722
9723
9724 llvm::SmallPtrSet<const FunctionDecl *, 8> PendingInlineFuncDecls;
9725
9726
9727
9728 bool isCurrentModulePurview() const;
9729
9730
9731 Module *PushGlobalModuleFragment(SourceLocation BeginLoc);
9732
9733 void PopGlobalModuleFragment();
9734
9735
9736 Module *PushImplicitGlobalModuleFragment(SourceLocation BeginLoc);
9737
9738 void PopImplicitGlobalModuleFragment();
9739
9740 VisibleModuleSet VisibleModules;
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754 public:
9755
9756 bool DeferDiags = false;
9757
9758
9759 class DeferDiagsRAII {
9760 Sema &S;
9761 bool SavedDeferDiags = false;
9762
9763 public:
9764 DeferDiagsRAII(Sema &S, bool DeferDiags)
9765 : S(S), SavedDeferDiags(S.DeferDiags) {
9766 S.DeferDiags = DeferDiags;
9767 }
9768 ~DeferDiagsRAII() { S.DeferDiags = SavedDeferDiags; }
9769 };
9770
9771
9772
9773
9774
9775 bool IsBuildingRecoveryCallExpr;
9776
9777 enum OverloadKind {
9778
9779
9780 Ovl_Overload,
9781
9782
9783
9784 Ovl_Match,
9785
9786
9787
9788 Ovl_NonFunction
9789 };
9790
9791
9792
9793
9794
9795
9796
9797
9798
9799
9800
9801
9802
9803
9804
9805
9806
9807
9808
9809
9810
9811
9812
9813
9814
9815
9816
9817
9818
9819
9820
9821
9822
9823
9824 OverloadKind CheckOverload(Scope *S, FunctionDecl *New,
9825 const LookupResult &OldDecls, NamedDecl *&OldDecl,
9826 bool UseMemberUsingDeclRules);
9827 bool IsOverload(FunctionDecl *New, FunctionDecl *Old,
9828 bool UseMemberUsingDeclRules, bool ConsiderCudaAttrs = true);
9829
9830
9831
9832 bool IsOverride(FunctionDecl *MD, FunctionDecl *BaseMD,
9833 bool UseMemberUsingDeclRules, bool ConsiderCudaAttrs = true);
9834
9835 enum class AllowedExplicit {
9836
9837 None,
9838
9839 Conversions,
9840
9841 All
9842 };
9843
9844 ImplicitConversionSequence TryImplicitConversion(
9845 Expr *From, QualType ToType, bool SuppressUserConversions,
9846 AllowedExplicit AllowExplicit, bool InOverloadResolution, bool CStyle,
9847 bool AllowObjCWritebackConversion);
9848
9849
9850
9851
9852
9853
9854 ExprResult PerformImplicitConversion(Expr *From, QualType ToType,
9855 AssignmentAction Action,
9856 bool AllowExplicit = false);
9857
9858
9859
9860
9861
9862 bool IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType);
9863
9864
9865
9866
9867 bool IsFloatingPointPromotion(QualType FromType, QualType ToType);
9868
9869
9870
9871
9872
9873
9874 bool IsComplexPromotion(QualType FromType, QualType ToType);
9875
9876
9877
9878
9879
9880
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892 bool IsPointerConversion(Expr *From, QualType FromType, QualType ToType,
9893 bool InOverloadResolution, QualType &ConvertedType,
9894 bool &IncompatibleObjC);
9895
9896
9897
9898
9899 bool isObjCPointerConversion(QualType FromType, QualType ToType,
9900 QualType &ConvertedType, bool &IncompatibleObjC);
9901 bool IsBlockPointerConversion(QualType FromType, QualType ToType,
9902 QualType &ConvertedType);
9903
9904
9905
9906
9907
9908
9909
9910
9911 bool FunctionParamTypesAreEqual(ArrayRef<QualType> Old,
9912 ArrayRef<QualType> New,
9913 unsigned *ArgPos = nullptr,
9914 bool Reversed = false);
9915
9916 bool FunctionParamTypesAreEqual(const FunctionProtoType *OldType,
9917 const FunctionProtoType *NewType,
9918 unsigned *ArgPos = nullptr,
9919 bool Reversed = false);
9920
9921 bool FunctionNonObjectParamTypesAreEqual(const FunctionDecl *OldFunction,
9922 const FunctionDecl *NewFunction,
9923 unsigned *ArgPos = nullptr,
9924 bool Reversed = false);
9925
9926
9927
9928
9929 void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag, QualType FromType,
9930 QualType ToType);
9931
9932
9933
9934
9935
9936
9937
9938 bool CheckPointerConversion(Expr *From, QualType ToType, CastKind &Kind,
9939 CXXCastPath &BasePath, bool IgnoreBaseAccess,
9940 bool Diagnose = true);
9941
9942
9943
9944
9945
9946
9947 bool IsMemberPointerConversion(Expr *From, QualType FromType, QualType ToType,
9948 bool InOverloadResolution,
9949 QualType &ConvertedType);
9950
9951
9952
9953
9954
9955
9956
9957 bool CheckMemberPointerConversion(Expr *From, QualType ToType, CastKind &Kind,
9958 CXXCastPath &BasePath,
9959 bool IgnoreBaseAccess);
9960
9961
9962
9963
9964
9965
9966
9967
9968 bool IsQualificationConversion(QualType FromType, QualType ToType,
9969 bool CStyle, bool &ObjCLifetimeConversion);
9970
9971
9972
9973
9974 bool IsFunctionConversion(QualType FromType, QualType ToType,
9975 QualType &ResultTy);
9976 bool DiagnoseMultipleUserDefinedConversion(Expr *From, QualType ToType);
9977 void DiagnoseUseOfDeletedFunction(SourceLocation Loc, SourceRange Range,
9978 DeclarationName Name,
9979 OverloadCandidateSet &CandidateSet,
9980 FunctionDecl *Fn, MultiExprArg Args,
9981 bool IsMember = false);
9982
9983 ExprResult InitializeExplicitObjectArgument(Sema &S, Expr *Obj,
9984 FunctionDecl *Fun);
9985 ExprResult PerformImplicitObjectArgumentInitialization(
9986 Expr *From, NestedNameSpecifier *Qualifier, NamedDecl *FoundDecl,
9987 CXXMethodDecl *Method);
9988
9989
9990
9991 ExprResult PerformContextuallyConvertToBool(Expr *From);
9992
9993
9994
9995
9996 ExprResult PerformContextuallyConvertToObjCPointer(Expr *From);
9997
9998
9999 enum CCEKind {
10000 CCEK_CaseValue,
10001 CCEK_Enumerator,
10002 CCEK_TemplateArg,
10003 CCEK_InjectedTTP,
10004 CCEK_ArrayBound,
10005 CCEK_ExplicitBool,
10006 CCEK_Noexcept,
10007 CCEK_StaticAssertMessageSize,
10008
10009 CCEK_StaticAssertMessageData,
10010
10011 };
10012
10013 ExprResult BuildConvertedConstantExpression(Expr *From, QualType T,
10014 CCEKind CCE,
10015 NamedDecl *Dest = nullptr);
10016
10017 ExprResult CheckConvertedConstantExpression(Expr *From, QualType T,
10018 llvm::APSInt &Value, CCEKind CCE);
10019 ExprResult CheckConvertedConstantExpression(Expr *From, QualType T,
10020 APValue &Value, CCEKind CCE,
10021 NamedDecl *Dest = nullptr);
10022
10023
10024
10025
10026 ExprResult
10027 EvaluateConvertedConstantExpression(Expr *E, QualType T, APValue &Value,
10028 CCEKind CCE, bool RequireInt,
10029 const APValue &PreNarrowingValue);
10030
10031
10032
10033 class ContextualImplicitConverter {
10034 public:
10035 bool Suppress;
10036 bool SuppressConversion;
10037
10038 ContextualImplicitConverter(bool Suppress = false,
10039 bool SuppressConversion = false)
10040 : Suppress(Suppress), SuppressConversion(SuppressConversion) {}
10041
10042
10043
10044 virtual bool match(QualType T) = 0;
10045
10046
10047
10048 virtual SemaDiagnosticBuilder diagnoseNoMatch(Sema &S, SourceLocation Loc,
10049 QualType T) = 0;
10050
10051
10052 virtual SemaDiagnosticBuilder
10053 diagnoseIncomplete(Sema &S, SourceLocation Loc, QualType T) = 0;
10054
10055
10056
10057 virtual SemaDiagnosticBuilder diagnoseExplicitConv(Sema &S,
10058 SourceLocation Loc,
10059 QualType T,
10060 QualType ConvTy) = 0;
10061
10062
10063 virtual SemaDiagnosticBuilder
10064 noteExplicitConv(Sema &S, CXXConversionDecl *Conv, QualType ConvTy) = 0;
10065
10066
10067
10068 virtual SemaDiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc,
10069 QualType T) = 0;
10070
10071
10072 virtual SemaDiagnosticBuilder
10073 noteAmbiguous(Sema &S, CXXConversionDecl *Conv, QualType ConvTy) = 0;
10074
10075
10076
10077 virtual SemaDiagnosticBuilder diagnoseConversion(Sema &S,
10078 SourceLocation Loc,
10079 QualType T,
10080 QualType ConvTy) = 0;
10081
10082 virtual ~ContextualImplicitConverter() {}
10083 };
10084
10085 class ICEConvertDiagnoser : public ContextualImplicitConverter {
10086 bool AllowScopedEnumerations;
10087
10088 public:
10089 ICEConvertDiagnoser(bool AllowScopedEnumerations, bool Suppress,
10090 bool SuppressConversion)
10091 : ContextualImplicitConverter(Suppress, SuppressConversion),
10092 AllowScopedEnumerations(AllowScopedEnumerations) {}
10093
10094
10095 bool match(QualType T) override;
10096
10097 SemaDiagnosticBuilder diagnoseNoMatch(Sema &S, SourceLocation Loc,
10098 QualType T) override {
10099 return diagnoseNotInt(S, Loc, T);
10100 }
10101
10102
10103
10104 virtual SemaDiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc,
10105 QualType T) = 0;
10106 };
10107
10108
10109 ExprResult
10110 PerformContextualImplicitConversion(SourceLocation Loc, Expr *FromE,
10111 ContextualImplicitConverter &Converter);
10112
10113
10114
10115
10116 enum ReferenceCompareResult {
10117
10118
10119 Ref_Incompatible = 0,
10120
10121
10122
10123 Ref_Related,
10124
10125 Ref_Compatible
10126 };
10127
10128
10129 struct ReferenceConversionsScope {
10130
10131
10132
10133 enum ReferenceConversions {
10134 Qualification = 0x1,
10135 NestedQualification = 0x2,
10136 Function = 0x4,
10137 DerivedToBase = 0x8,
10138 ObjC = 0x10,
10139 ObjCLifetime = 0x20,
10140
10141 LLVM_MARK_AS_BITMASK_ENUM(ObjCLifetime)
10142 };
10143 };
10144 using ReferenceConversions = ReferenceConversionsScope::ReferenceConversions;
10145
10146
10147
10148
10149
10150
10151
10152 ReferenceCompareResult
10153 CompareReferenceRelationship(SourceLocation Loc, QualType T1, QualType T2,
10154 ReferenceConversions *Conv = nullptr);
10155
10156
10157
10158
10159
10160
10161
10162
10163
10164 void AddOverloadCandidate(FunctionDecl *Function, DeclAccessPair FoundDecl,
10165 ArrayRef<Expr *> Args,
10166 OverloadCandidateSet &CandidateSet,
10167 bool SuppressUserConversions = false,
10168 bool PartialOverloading = false,
10169 bool AllowExplicit = true,
10170 bool AllowExplicitConversion = false,
10171 ADLCallKind IsADLCandidate = ADLCallKind::NotADL,
10172 ConversionSequenceList EarlyConversions = {},
10173 OverloadCandidateParamOrder PO = {},
10174 bool AggregateCandidateDeduction = false,
10175 bool HasMatchedPackOnParmToNonPackOnArg = false);
10176
10177
10178
10179 void AddFunctionCandidates(
10180 const UnresolvedSetImpl &Functions, ArrayRef<Expr *> Args,
10181 OverloadCandidateSet &CandidateSet,
10182 TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr,
10183 bool SuppressUserConversions = false, bool PartialOverloading = false,
10184 bool FirstArgumentIsBase = false);
10185
10186
10187
10188 void AddMethodCandidate(DeclAccessPair FoundDecl, QualType ObjectType,
10189 Expr::Classification ObjectClassification,
10190 ArrayRef<Expr *> Args,
10191 OverloadCandidateSet &CandidateSet,
10192 bool SuppressUserConversion = false,
10193 OverloadCandidateParamOrder PO = {});
10194
10195
10196
10197
10198
10199
10200
10201
10202 void AddMethodCandidate(CXXMethodDecl *Method, DeclAccessPair FoundDecl,
10203 CXXRecordDecl *ActingContext, QualType ObjectType,
10204 Expr::Classification ObjectClassification,
10205 ArrayRef<Expr *> Args,
10206 OverloadCandidateSet &CandidateSet,
10207 bool SuppressUserConversions = false,
10208 bool PartialOverloading = false,
10209 ConversionSequenceList EarlyConversions = {},
10210 OverloadCandidateParamOrder PO = {},
10211 bool HasMatchedPackOnParmToNonPackOnArg = false);
10212
10213
10214
10215
10216 void AddMethodTemplateCandidate(
10217 FunctionTemplateDecl *MethodTmpl, DeclAccessPair FoundDecl,
10218 CXXRecordDecl *ActingContext,
10219 TemplateArgumentListInfo *ExplicitTemplateArgs, QualType ObjectType,
10220 Expr::Classification ObjectClassification, ArrayRef<Expr *> Args,
10221 OverloadCandidateSet &CandidateSet, bool SuppressUserConversions = false,
10222 bool PartialOverloading = false, OverloadCandidateParamOrder PO = {});
10223
10224
10225
10226
10227 void AddTemplateOverloadCandidate(
10228 FunctionTemplateDecl *FunctionTemplate, DeclAccessPair FoundDecl,
10229 TemplateArgumentListInfo *ExplicitTemplateArgs, ArrayRef<Expr *> Args,
10230 OverloadCandidateSet &CandidateSet, bool SuppressUserConversions = false,
10231 bool PartialOverloading = false, bool AllowExplicit = true,
10232 ADLCallKind IsADLCandidate = ADLCallKind::NotADL,
10233 OverloadCandidateParamOrder PO = {},
10234 bool AggregateCandidateDeduction = false);
10235
10236
10237
10238
10239 bool CheckNonDependentConversions(
10240 FunctionTemplateDecl *FunctionTemplate, ArrayRef<QualType> ParamTypes,
10241 ArrayRef<Expr *> Args, OverloadCandidateSet &CandidateSet,
10242 ConversionSequenceList &Conversions, bool SuppressUserConversions,
10243 CXXRecordDecl *ActingContext = nullptr, QualType ObjectType = QualType(),
10244 Expr::Classification ObjectClassification = {},
10245 OverloadCandidateParamOrder PO = {});
10246
10247
10248
10249
10250
10251
10252
10253 void AddConversionCandidate(
10254 CXXConversionDecl *Conversion, DeclAccessPair FoundDecl,
10255 CXXRecordDecl *ActingContext, Expr *From, QualType ToType,
10256 OverloadCandidateSet &CandidateSet, bool AllowObjCConversionOnExplicit,
10257 bool AllowExplicit, bool AllowResultConversion = true,
10258 bool HasMatchedPackOnParmToNonPackOnArg = false);
10259
10260
10261
10262
10263
10264
10265 void AddTemplateConversionCandidate(
10266 FunctionTemplateDecl *FunctionTemplate, DeclAccessPair FoundDecl,
10267 CXXRecordDecl *ActingContext, Expr *From, QualType ToType,
10268 OverloadCandidateSet &CandidateSet, bool AllowObjCConversionOnExplicit,
10269 bool AllowExplicit, bool AllowResultConversion = true);
10270
10271
10272
10273
10274
10275
10276 void AddSurrogateCandidate(CXXConversionDecl *Conversion,
10277 DeclAccessPair FoundDecl,
10278 CXXRecordDecl *ActingContext,
10279 const FunctionProtoType *Proto, Expr *Object,
10280 ArrayRef<Expr *> Args,
10281 OverloadCandidateSet &CandidateSet);
10282
10283
10284
10285 void AddNonMemberOperatorCandidates(
10286 const UnresolvedSetImpl &Functions, ArrayRef<Expr *> Args,
10287 OverloadCandidateSet &CandidateSet,
10288 TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr);
10289
10290
10291
10292
10293
10294
10295
10296
10297
10298 void AddMemberOperatorCandidates(OverloadedOperatorKind Op,
10299 SourceLocation OpLoc, ArrayRef<Expr *> Args,
10300 OverloadCandidateSet &CandidateSet,
10301 OverloadCandidateParamOrder PO = {});
10302
10303
10304
10305
10306
10307
10308
10309
10310
10311 void AddBuiltinCandidate(QualType *ParamTys, ArrayRef<Expr *> Args,
10312 OverloadCandidateSet &CandidateSet,
10313 bool IsAssignmentOperator = false,
10314 unsigned NumContextualBoolArguments = 0);
10315
10316
10317
10318
10319
10320
10321 void AddBuiltinOperatorCandidates(OverloadedOperatorKind Op,
10322 SourceLocation OpLoc, ArrayRef<Expr *> Args,
10323 OverloadCandidateSet &CandidateSet);
10324
10325
10326
10327
10328
10329
10330
10331
10332 void AddArgumentDependentLookupCandidates(
10333 DeclarationName Name, SourceLocation Loc, ArrayRef<Expr *> Args,
10334 TemplateArgumentListInfo *ExplicitTemplateArgs,
10335 OverloadCandidateSet &CandidateSet, bool PartialOverloading = false);
10336
10337
10338
10339 EnableIfAttr *CheckEnableIf(FunctionDecl *Function, SourceLocation CallLoc,
10340 ArrayRef<Expr *> Args,
10341 bool MissingImplicitThis = false);
10342
10343
10344
10345
10346
10347
10348
10349
10350 bool diagnoseArgDependentDiagnoseIfAttrs(const FunctionDecl *Function,
10351 const Expr *ThisArg,
10352 ArrayRef<const Expr *> Args,
10353 SourceLocation Loc);
10354
10355
10356
10357
10358
10359
10360
10361
10362 bool diagnoseArgIndependentDiagnoseIfAttrs(const NamedDecl *ND,
10363 SourceLocation Loc);
10364
10365
10366
10367
10368 bool isEquivalentInternalLinkageDeclaration(const NamedDecl *A,
10369 const NamedDecl *B);
10370 void diagnoseEquivalentInternalLinkageDeclarations(
10371 SourceLocation Loc, const NamedDecl *D,
10372 ArrayRef<const NamedDecl *> Equiv);
10373
10374
10375 void NoteOverloadCandidate(
10376 const NamedDecl *Found, const FunctionDecl *Fn,
10377 OverloadCandidateRewriteKind RewriteKind = OverloadCandidateRewriteKind(),
10378 QualType DestType = QualType(), bool TakingAddress = false);
10379
10380
10381
10382 void NoteAllOverloadCandidates(Expr *E, QualType DestType = QualType(),
10383 bool TakingAddress = false);
10384
10385
10386
10387
10388
10389 bool checkAddressOfFunctionIsAvailable(const FunctionDecl *Function,
10390 bool Complain = false,
10391 SourceLocation Loc = SourceLocation());
10392
10393
10394
10395
10396
10397
10398
10399 QualType ExtractUnqualifiedFunctionType(QualType PossiblyAFunctionType);
10400
10401
10402
10403
10404
10405
10406
10407
10408
10409
10410
10411
10412
10413
10414
10415
10416 FunctionDecl *
10417 ResolveAddressOfOverloadedFunction(Expr *AddressOfExpr, QualType TargetType,
10418 bool Complain, DeclAccessPair &Found,
10419 bool *pHadMultipleCandidates = nullptr);
10420
10421
10422
10423
10424
10425
10426
10427
10428 FunctionDecl *
10429 resolveAddressOfSingleOverloadCandidate(Expr *E, DeclAccessPair &FoundResult);
10430
10431
10432
10433
10434
10435
10436
10437
10438 bool resolveAndFixAddressOfSingleOverloadCandidate(
10439 ExprResult &SrcExpr, bool DoFunctionPointerConversion = false);
10440
10441
10442
10443
10444
10445
10446
10447
10448
10449
10450
10451 FunctionDecl *ResolveSingleFunctionTemplateSpecialization(
10452 OverloadExpr *ovl, bool Complain = false, DeclAccessPair *Found = nullptr,
10453 TemplateSpecCandidateSet *FailedTSC = nullptr);
10454
10455
10456
10457
10458
10459
10460
10461
10462
10463 bool ResolveAndFixSingleFunctionTemplateSpecialization(
10464 ExprResult &SrcExpr, bool DoFunctionPointerConversion = false,
10465 bool Complain = false, SourceRange OpRangeForComplaining = SourceRange(),
10466 QualType DestTypeForComplaining = QualType(),
10467 unsigned DiagIDForComplaining = 0);
10468
10469
10470
10471 void AddOverloadedCallCandidates(UnresolvedLookupExpr *ULE,
10472 ArrayRef<Expr *> Args,
10473 OverloadCandidateSet &CandidateSet,
10474 bool PartialOverloading = false);
10475
10476
10477
10478 void AddOverloadedCallCandidates(
10479 LookupResult &R, TemplateArgumentListInfo *ExplicitTemplateArgs,
10480 ArrayRef<Expr *> Args, OverloadCandidateSet &CandidateSet);
10481
10482
10483
10484 enum ForRangeStatus {
10485 FRS_Success,
10486 FRS_NoViableFunction,
10487 FRS_DiagnosticIssued
10488 };
10489
10490
10491
10492
10493
10494
10495
10496
10497 ForRangeStatus BuildForRangeBeginEndCall(SourceLocation Loc,
10498 SourceLocation RangeLoc,
10499 const DeclarationNameInfo &NameInfo,
10500 LookupResult &MemberLookup,
10501 OverloadCandidateSet *CandidateSet,
10502 Expr *Range, ExprResult *CallExpr);
10503
10504
10505
10506
10507
10508
10509
10510 ExprResult BuildOverloadedCallExpr(
10511 Scope *S, Expr *Fn, UnresolvedLookupExpr *ULE, SourceLocation LParenLoc,
10512 MultiExprArg Args, SourceLocation RParenLoc, Expr *ExecConfig,
10513 bool AllowTypoCorrection = true, bool CalleesAddressIsTaken = false);
10514
10515
10516
10517
10518 bool buildOverloadedCallSet(Scope *S, Expr *Fn, UnresolvedLookupExpr *ULE,
10519 MultiExprArg Args, SourceLocation RParenLoc,
10520 OverloadCandidateSet *CandidateSet,
10521 ExprResult *Result);
10522
10523 ExprResult CreateUnresolvedLookupExpr(CXXRecordDecl *NamingClass,
10524 NestedNameSpecifierLoc NNSLoc,
10525 DeclarationNameInfo DNI,
10526 const UnresolvedSetImpl &Fns,
10527 bool PerformADL = true);
10528
10529
10530
10531
10532
10533
10534
10535
10536
10537
10538
10539
10540
10541
10542
10543
10544 ExprResult CreateOverloadedUnaryOp(SourceLocation OpLoc,
10545 UnaryOperatorKind Opc,
10546 const UnresolvedSetImpl &Fns, Expr *input,
10547 bool RequiresADL = true);
10548
10549
10550 void LookupOverloadedBinOp(OverloadCandidateSet &CandidateSet,
10551 OverloadedOperatorKind Op,
10552 const UnresolvedSetImpl &Fns,
10553 ArrayRef<Expr *> Args, bool RequiresADL = true);
10554
10555
10556
10557
10558
10559
10560
10561
10562
10563
10564
10565
10566
10567
10568
10569
10570
10571
10572
10573
10574
10575
10576
10577
10578 ExprResult CreateOverloadedBinOp(SourceLocation OpLoc, BinaryOperatorKind Opc,
10579 const UnresolvedSetImpl &Fns, Expr *LHS,
10580 Expr *RHS, bool RequiresADL = true,
10581 bool AllowRewrittenCandidates = true,
10582 FunctionDecl *DefaultedFn = nullptr);
10583 ExprResult BuildSynthesizedThreeWayComparison(SourceLocation OpLoc,
10584 const UnresolvedSetImpl &Fns,
10585 Expr *LHS, Expr *RHS,
10586 FunctionDecl *DefaultedFn);
10587
10588 ExprResult CreateOverloadedArraySubscriptExpr(SourceLocation LLoc,
10589 SourceLocation RLoc, Expr *Base,
10590 MultiExprArg Args);
10591
10592
10593
10594
10595
10596
10597
10598
10599 ExprResult BuildCallToMemberFunction(
10600 Scope *S, Expr *MemExpr, SourceLocation LParenLoc, MultiExprArg Args,
10601 SourceLocation RParenLoc, Expr *ExecConfig = nullptr,
10602 bool IsExecConfig = false, bool AllowRecovery = false);
10603
10604
10605
10606
10607
10608 ExprResult BuildCallToObjectOfClassType(Scope *S, Expr *Object,
10609 SourceLocation LParenLoc,
10610 MultiExprArg Args,
10611 SourceLocation RParenLoc);
10612
10613
10614
10615
10616 ExprResult BuildOverloadedArrowExpr(Scope *S, Expr *Base,
10617 SourceLocation OpLoc,
10618 bool *NoArrowOperatorFound = nullptr);
10619
10620 ExprResult BuildCXXMemberCallExpr(Expr *Exp, NamedDecl *FoundDecl,
10621 CXXConversionDecl *Method,
10622 bool HadMultipleCandidates);
10623
10624
10625
10626 ExprResult BuildLiteralOperatorCall(
10627 LookupResult &R, DeclarationNameInfo &SuffixInfo, ArrayRef<Expr *> Args,
10628 SourceLocation LitEndLoc,
10629 TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr);
10630
10631
10632
10633
10634
10635
10636 ExprResult FixOverloadedFunctionReference(Expr *E, DeclAccessPair FoundDecl,
10637 FunctionDecl *Fn);
10638 ExprResult FixOverloadedFunctionReference(ExprResult,
10639 DeclAccessPair FoundDecl,
10640 FunctionDecl *Fn);
10641
10642
10643
10644 ObjCMethodDecl *SelectBestMethod(Selector Sel, MultiExprArg Args,
10645 bool IsInstance,
10646 SmallVectorImpl<ObjCMethodDecl *> &Methods);
10647
10648
10649
10650
10651
10652
10653
10654
10655
10656
10657
10658
10659
10660 public:
10661
10662 SmallVector<Scope *, 2> CurrentSEHFinally;
10663
10664 StmtResult ActOnExprStmt(ExprResult Arg, bool DiscardedValue = true);
10665 StmtResult ActOnExprStmtError();
10666
10667 StmtResult ActOnNullStmt(SourceLocation SemiLoc,
10668 bool HasLeadingEmptyMacro = false);
10669
10670 StmtResult ActOnDeclStmt(DeclGroupPtrTy Decl, SourceLocation StartLoc,
10671 SourceLocation EndLoc);
10672 void ActOnForEachDeclStmt(DeclGroupPtrTy Decl);
10673
10674
10675
10676 void DiagnoseDiscardedExprMarkedNodiscard(const Expr *E);
10677
10678
10679
10680 void DiagnoseUnusedExprResult(const Stmt *S, unsigned DiagID);
10681
10682 void ActOnStartOfCompoundStmt(bool IsStmtExpr);
10683 void ActOnAfterCompoundStatementLeadingPragmas();
10684 void ActOnFinishOfCompoundStmt();
10685 StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R,
10686 ArrayRef<Stmt *> Elts, bool isStmtExpr);
10687
10688 sema::CompoundScopeInfo &getCurCompoundScope() const;
10689
10690 ExprResult ActOnCaseExpr(SourceLocation CaseLoc, ExprResult Val);
10691 StmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprResult LHS,
10692 SourceLocation DotDotDotLoc, ExprResult RHS,
10693 SourceLocation ColonLoc);
10694
10695
10696 void ActOnCaseStmtBody(Stmt *CaseStmt, Stmt *SubStmt);
10697
10698 StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc,
10699 SourceLocation ColonLoc, Stmt *SubStmt,
10700 Scope *CurScope);
10701 StmtResult ActOnLabelStmt(SourceLocation IdentLoc, LabelDecl *TheDecl,
10702 SourceLocation ColonLoc, Stmt *SubStmt);
10703
10704 StmtResult BuildAttributedStmt(SourceLocation AttrsLoc,
10705 ArrayRef<const Attr *> Attrs, Stmt *SubStmt);
10706 StmtResult ActOnAttributedStmt(const ParsedAttributes &AttrList,
10707 Stmt *SubStmt);
10708
10709
10710
10711
10712
10713 bool checkAndRewriteMustTailAttr(Stmt *St, const Attr &MTA);
10714
10715 StmtResult ActOnIfStmt(SourceLocation IfLoc, IfStatementKind StatementKind,
10716 SourceLocation LParenLoc, Stmt *InitStmt,
10717 ConditionResult Cond, SourceLocation RParenLoc,
10718 Stmt *ThenVal, SourceLocation ElseLoc, Stmt *ElseVal);
10719 StmtResult BuildIfStmt(SourceLocation IfLoc, IfStatementKind StatementKind,
10720 SourceLocation LParenLoc, Stmt *InitStmt,
10721 ConditionResult Cond, SourceLocation RParenLoc,
10722 Stmt *ThenVal, SourceLocation ElseLoc, Stmt *ElseVal);
10723
10724 ExprResult CheckSwitchCondition(SourceLocation SwitchLoc, Expr *Cond);
10725
10726 StmtResult ActOnStartOfSwitchStmt(SourceLocation SwitchLoc,
10727 SourceLocation LParenLoc, Stmt *InitStmt,
10728 ConditionResult Cond,
10729 SourceLocation RParenLoc);
10730 StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch,
10731 Stmt *Body);
10732
10733
10734
10735 void DiagnoseAssignmentEnum(QualType DstType, QualType SrcType,
10736 Expr *SrcExpr);
10737
10738 StmtResult ActOnWhileStmt(SourceLocation WhileLoc, SourceLocation LParenLoc,
10739 ConditionResult Cond, SourceLocation RParenLoc,
10740 Stmt *Body);
10741 StmtResult ActOnDoStmt(SourceLocation DoLoc, Stmt *Body,
10742 SourceLocation WhileLoc, SourceLocation CondLParen,
10743 Expr *Cond, SourceLocation CondRParen);
10744
10745 StmtResult ActOnForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
10746 Stmt *First, ConditionResult Second,
10747 FullExprArg Third, SourceLocation RParenLoc,
10748 Stmt *Body);
10749
10750
10751
10752
10753
10754 StmtResult ActOnForEachLValueExpr(Expr *E);
10755
10756 enum BuildForRangeKind {
10757
10758 BFRK_Build,
10759
10760
10761 BFRK_Rebuild,
10762
10763
10764 BFRK_Check
10765 };
10766
10767
10768
10769
10770
10771
10772
10773
10774
10775
10776
10777
10778
10779
10780
10781
10782
10783
10784
10785 StmtResult ActOnCXXForRangeStmt(
10786 Scope *S, SourceLocation ForLoc, SourceLocation CoawaitLoc,
10787 Stmt *InitStmt, Stmt *LoopVar, SourceLocation ColonLoc, Expr *Collection,
10788 SourceLocation RParenLoc, BuildForRangeKind Kind,
10789 ArrayRef<MaterializeTemporaryExpr *> LifetimeExtendTemps = {});
10790
10791
10792 StmtResult BuildCXXForRangeStmt(
10793 SourceLocation ForLoc, SourceLocation CoawaitLoc, Stmt *InitStmt,
10794 SourceLocation ColonLoc, Stmt *RangeDecl, Stmt *Begin, Stmt *End,
10795 Expr *Cond, Expr *Inc, Stmt *LoopVarDecl, SourceLocation RParenLoc,
10796 BuildForRangeKind Kind,
10797 ArrayRef<MaterializeTemporaryExpr *> LifetimeExtendTemps = {});
10798
10799
10800
10801
10802
10803 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body);
10804
10805 StmtResult ActOnGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
10806 LabelDecl *TheDecl);
10807 StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc,
10808 SourceLocation StarLoc, Expr *DestExp);
10809 StmtResult ActOnContinueStmt(SourceLocation ContinueLoc, Scope *CurScope);
10810 StmtResult ActOnBreakStmt(SourceLocation BreakLoc, Scope *CurScope);
10811
10812 struct NamedReturnInfo {
10813 const VarDecl *Candidate;
10814
10815 enum Status : uint8_t { None, MoveEligible, MoveEligibleAndCopyElidable };
10816 Status S;
10817
10818 bool isMoveEligible() const { return S != None; };
10819 bool isCopyElidable() const { return S == MoveEligibleAndCopyElidable; }
10820 };
10821 enum class SimplerImplicitMoveMode { ForceOff, Normal, ForceOn };
10822
10823
10824
10825
10826
10827
10828
10829
10830
10831
10832
10833
10834
10835
10836
10837
10838 NamedReturnInfo getNamedReturnInfo(
10839 Expr *&E, SimplerImplicitMoveMode Mode = SimplerImplicitMoveMode::Normal);
10840
10841
10842
10843
10844
10845
10846
10847
10848
10849
10850 NamedReturnInfo getNamedReturnInfo(const VarDecl *VD);
10851
10852
10853
10854
10855
10856
10857
10858
10859
10860
10861 const VarDecl *getCopyElisionCandidate(NamedReturnInfo &Info,
10862 QualType ReturnType);
10863
10864
10865
10866
10867
10868
10869
10870 ExprResult
10871 PerformMoveOrCopyInitialization(const InitializedEntity &Entity,
10872 const NamedReturnInfo &NRInfo, Expr *Value,
10873 bool SupressSimplerImplicitMoves = false);
10874
10875 TypeLoc getReturnTypeLoc(FunctionDecl *FD) const;
10876
10877
10878
10879 bool DeduceFunctionTypeFromReturnExpr(FunctionDecl *FD,
10880 SourceLocation ReturnLoc, Expr *RetExpr,
10881 const AutoType *AT);
10882
10883 StmtResult ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp,
10884 Scope *CurScope);
10885 StmtResult BuildReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp,
10886 bool AllowRecovery = false);
10887
10888
10889
10890 StmtResult ActOnCapScopeReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp,
10891 NamedReturnInfo &NRInfo,
10892 bool SupressSimplerImplicitMoves);
10893
10894
10895
10896 StmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc, Decl *ExDecl,
10897 Stmt *HandlerBlock);
10898
10899
10900
10901 StmtResult ActOnCXXTryBlock(SourceLocation TryLoc, Stmt *TryBlock,
10902 ArrayRef<Stmt *> Handlers);
10903
10904 StmtResult ActOnSEHTryBlock(bool IsCXXTry,
10905 SourceLocation TryLoc, Stmt *TryBlock,
10906 Stmt *Handler);
10907 StmtResult ActOnSEHExceptBlock(SourceLocation Loc, Expr *FilterExpr,
10908 Stmt *Block);
10909 void ActOnStartSEHFinallyBlock();
10910 void ActOnAbortSEHFinallyBlock();
10911 StmtResult ActOnFinishSEHFinallyBlock(SourceLocation Loc, Stmt *Block);
10912 StmtResult ActOnSEHLeaveStmt(SourceLocation Loc, Scope *CurScope);
10913
10914 StmtResult BuildMSDependentExistsStmt(SourceLocation KeywordLoc,
10915 bool IsIfExists,
10916 NestedNameSpecifierLoc QualifierLoc,
10917 DeclarationNameInfo NameInfo,
10918 Stmt *Nested);
10919 StmtResult ActOnMSDependentExistsStmt(SourceLocation KeywordLoc,
10920 bool IsIfExists, CXXScopeSpec &SS,
10921 UnqualifiedId &Name, Stmt *Nested);
10922
10923 void ActOnCapturedRegionStart(SourceLocation Loc, Scope *CurScope,
10924 CapturedRegionKind Kind, unsigned NumParams);
10925 typedef std::pair<StringRef, QualType> CapturedParamNameType;
10926 void ActOnCapturedRegionStart(SourceLocation Loc, Scope *CurScope,
10927 CapturedRegionKind Kind,
10928 ArrayRef<CapturedParamNameType> Params,
10929 unsigned OpenMPCaptureLevel = 0);
10930 StmtResult ActOnCapturedRegionEnd(Stmt *S);
10931 void ActOnCapturedRegionError();
10932 RecordDecl *CreateCapturedStmtRecordDecl(CapturedDecl *&CD,
10933 SourceLocation Loc,
10934 unsigned NumParams);
10935
10936 private:
10937
10938
10939 bool checkMustTailAttr(const Stmt *St, const Attr &MTA);
10940
10941
10942
10943 void CheckBreakContinueBinding(Expr *E);
10944
10945
10946
10947
10948
10949
10950
10951
10952
10953
10954
10955
10956
10957 public:
10958 StmtResult ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
10959 bool IsVolatile, unsigned NumOutputs,
10960 unsigned NumInputs, IdentifierInfo **Names,
10961 MultiExprArg Constraints, MultiExprArg Exprs,
10962 Expr *AsmString, MultiExprArg Clobbers,
10963 unsigned NumLabels, SourceLocation RParenLoc);
10964
10965 void FillInlineAsmIdentifierInfo(Expr *Res,
10966 llvm::InlineAsmIdentifierInfo &Info);
10967 ExprResult LookupInlineAsmIdentifier(CXXScopeSpec &SS,
10968 SourceLocation TemplateKWLoc,
10969 UnqualifiedId &Id,
10970 bool IsUnevaluatedContext);
10971 bool LookupInlineAsmField(StringRef Base, StringRef Member, unsigned &Offset,
10972 SourceLocation AsmLoc);
10973 ExprResult LookupInlineAsmVarDeclField(Expr *RefExpr, StringRef Member,
10974 SourceLocation AsmLoc);
10975 StmtResult ActOnMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
10976 ArrayRef<Token> AsmToks, StringRef AsmString,
10977 unsigned NumOutputs, unsigned NumInputs,
10978 ArrayRef<StringRef> Constraints,
10979 ArrayRef<StringRef> Clobbers,
10980 ArrayRef<Expr *> Exprs, SourceLocation EndLoc);
10981 LabelDecl *GetOrCreateMSAsmLabel(StringRef ExternalLabelName,
10982 SourceLocation Location, bool AlwaysCreate);
10983
10984
10985
10986
10987
10988
10989
10990
10991
10992
10993
10994
10995
10996 public:
10997 bool CheckNoInlineAttr(const Stmt *OrigSt, const Stmt *CurSt,
10998 const AttributeCommonInfo &A);
10999 bool CheckAlwaysInlineAttr(const Stmt *OrigSt, const Stmt *CurSt,
11000 const AttributeCommonInfo &A);
11001
11002 CodeAlignAttr *BuildCodeAlignAttr(const AttributeCommonInfo &CI, Expr *E);
11003 bool CheckRebuiltStmtAttributes(ArrayRef<const Attr *> Attrs);
11004
11005
11006
11007 void ProcessStmtAttributes(Stmt *Stmt, const ParsedAttributes &InAttrs,
11008 SmallVectorImpl<const Attr *> &OutAttrs);
11009
11010 ExprResult ActOnCXXAssumeAttr(Stmt *St, const ParsedAttr &A,
11011 SourceRange Range);
11012 ExprResult BuildCXXAssumeExpr(Expr *Assumption,
11013 const IdentifierInfo *AttrName,
11014 SourceRange Range);
11015
11016
11017
11018
11019
11020
11021
11022
11023
11024
11025
11026
11027
11028 public:
11029
11030 class FpPragmaStackSaveRAII {
11031 public:
11032 FpPragmaStackSaveRAII(Sema &S)
11033 : S(S), SavedStack(std::move(S.FpPragmaStack)) {
11034 S.FpPragmaStack.Stack.clear();
11035 }
11036 ~FpPragmaStackSaveRAII() { S.FpPragmaStack = std::move(SavedStack); }
11037
11038 private:
11039 Sema &S;
11040 PragmaStack<FPOptionsOverride> SavedStack;
11041 };
11042
11043 void resetFPOptions(FPOptions FPO) {
11044 CurFPFeatures = FPO;
11045 FpPragmaStack.CurrentValue = FPO.getChangesFrom(FPOptions(LangOpts));
11046 }
11047
11048 ArrayRef<InventedTemplateParameterInfo> getInventedParameterInfos() const {
11049 return llvm::ArrayRef(InventedParameterInfos.begin() +
11050 InventedParameterInfosStart,
11051 InventedParameterInfos.end());
11052 }
11053
11054
11055 unsigned NumSFINAEErrors;
11056
11057 ArrayRef<sema::FunctionScopeInfo *> getFunctionScopes() const {
11058 return llvm::ArrayRef(FunctionScopes.begin() + FunctionScopesStart,
11059 FunctionScopes.end());
11060 }
11061
11062 typedef llvm::MapVector<const FunctionDecl *,
11063 std::unique_ptr<LateParsedTemplate>>
11064 LateParsedTemplateMapT;
11065 LateParsedTemplateMapT LateParsedTemplateMap;
11066
11067
11068
11069
11070
11071
11072 unsigned getTemplateDepth(Scope *S) const;
11073
11074 void FilterAcceptableTemplateNames(LookupResult &R,
11075 bool AllowFunctionTemplates = true,
11076 bool AllowDependent = true);
11077 bool hasAnyAcceptableTemplateNames(LookupResult &R,
11078 bool AllowFunctionTemplates = true,
11079 bool AllowDependent = true,
11080 bool AllowNonTemplateFunctions = false);
11081
11082
11083
11084
11085
11086
11087
11088 static NamedDecl *getAsTemplateNameDecl(NamedDecl *D,
11089 bool AllowFunctionTemplates = true,
11090 bool AllowDependent = true);
11091
11092 enum TemplateNameIsRequiredTag { TemplateNameIsRequired };
11093
11094 class RequiredTemplateKind {
11095 public:
11096
11097 RequiredTemplateKind(SourceLocation TemplateKWLoc = SourceLocation())
11098 : TemplateKW(TemplateKWLoc) {}
11099
11100 RequiredTemplateKind(TemplateNameIsRequiredTag) {}
11101
11102 SourceLocation getTemplateKeywordLoc() const {
11103 return TemplateKW.value_or(SourceLocation());
11104 }
11105 bool hasTemplateKeyword() const {
11106 return getTemplateKeywordLoc().isValid();
11107 }
11108 bool isRequired() const { return TemplateKW != SourceLocation(); }
11109 explicit operator bool() const { return isRequired(); }
11110
11111 private:
11112 std::optional<SourceLocation> TemplateKW;
11113 };
11114
11115 enum class AssumedTemplateKind {
11116
11117 None,
11118
11119 FoundNothing,
11120
11121
11122 FoundFunctions,
11123 };
11124
11125 bool
11126 LookupTemplateName(LookupResult &R, Scope *S, CXXScopeSpec &SS,
11127 QualType ObjectType, bool EnteringContext,
11128 RequiredTemplateKind RequiredTemplate = SourceLocation(),
11129 AssumedTemplateKind *ATK = nullptr,
11130 bool AllowTypoCorrection = true);
11131
11132 TemplateNameKind isTemplateName(Scope *S, CXXScopeSpec &SS,
11133 bool hasTemplateKeyword,
11134 const UnqualifiedId &Name,
11135 ParsedType ObjectType, bool EnteringContext,
11136 TemplateTy &Template,
11137 bool &MemberOfUnknownSpecialization,
11138 bool Disambiguation = false);
11139
11140
11141
11142
11143
11144
11145 void ActOnUndeclaredTypeTemplateName(Scope *S, TemplateTy &Name,
11146 TemplateNameKind &TNK,
11147 SourceLocation NameLoc,
11148 IdentifierInfo *&II);
11149
11150 bool resolveAssumedTemplateNameAsType(Scope *S, TemplateName &Name,
11151 SourceLocation NameLoc,
11152 bool Diagnose = true);
11153
11154
11155
11156 bool isDeductionGuideName(Scope *S, const IdentifierInfo &Name,
11157 SourceLocation NameLoc, CXXScopeSpec &SS,
11158 ParsedTemplateTy *Template = nullptr);
11159
11160 bool DiagnoseUnknownTemplateName(const IdentifierInfo &II,
11161 SourceLocation IILoc, Scope *S,
11162 const CXXScopeSpec *SS,
11163 TemplateTy &SuggestedTemplate,
11164 TemplateNameKind &SuggestedKind);
11165
11166
11167
11168 bool DiagnoseUninstantiableTemplate(SourceLocation PointOfInstantiation,
11169 NamedDecl *Instantiation,
11170 bool InstantiatedFromMember,
11171 const NamedDecl *Pattern,
11172 const NamedDecl *PatternDef,
11173 TemplateSpecializationKind TSK,
11174 bool Complain = true);
11175
11176
11177
11178
11179
11180
11181
11182
11183
11184
11185
11186
11187
11188
11189 void DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl,
11190 bool SupportedForCompatibility = false);
11191
11192
11193
11194
11195
11196 TemplateDecl *AdjustDeclIfTemplate(Decl *&Decl);
11197
11198
11199
11200
11201
11202
11203
11204
11205
11206
11207 NamedDecl *ActOnTypeParameter(Scope *S, bool Typename,
11208 SourceLocation EllipsisLoc,
11209 SourceLocation KeyLoc,
11210 IdentifierInfo *ParamName,
11211 SourceLocation ParamNameLoc, unsigned Depth,
11212 unsigned Position, SourceLocation EqualLoc,
11213 ParsedType DefaultArg, bool HasTypeConstraint);
11214
11215 bool CheckTypeConstraint(TemplateIdAnnotation *TypeConstraint);
11216
11217 bool ActOnTypeConstraint(const CXXScopeSpec &SS,
11218 TemplateIdAnnotation *TypeConstraint,
11219 TemplateTypeParmDecl *ConstrainedParameter,
11220 SourceLocation EllipsisLoc);
11221 bool BuildTypeConstraint(const CXXScopeSpec &SS,
11222 TemplateIdAnnotation *TypeConstraint,
11223 TemplateTypeParmDecl *ConstrainedParameter,
11224 SourceLocation EllipsisLoc,
11225 bool AllowUnexpandedPack);
11226
11227
11228
11229
11230
11231 bool AttachTypeConstraint(NestedNameSpecifierLoc NS,
11232 DeclarationNameInfo NameInfo,
11233 ConceptDecl *NamedConcept, NamedDecl *FoundDecl,
11234 const TemplateArgumentListInfo *TemplateArgs,
11235 TemplateTypeParmDecl *ConstrainedParameter,
11236 QualType ConstrainedType,
11237 SourceLocation EllipsisLoc);
11238
11239 bool AttachTypeConstraint(AutoTypeLoc TL,
11240 NonTypeTemplateParmDecl *NewConstrainedParm,
11241 NonTypeTemplateParmDecl *OrigConstrainedParm,
11242 SourceLocation EllipsisLoc);
11243
11244
11245
11246
11247 bool RequireStructuralType(QualType T, SourceLocation Loc);
11248
11249
11250
11251
11252
11253
11254 QualType CheckNonTypeTemplateParameterType(TypeSourceInfo *&TSI,
11255 SourceLocation Loc);
11256 QualType CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc);
11257
11258 NamedDecl *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D,
11259 unsigned Depth, unsigned Position,
11260 SourceLocation EqualLoc,
11261 Expr *DefaultArg);
11262
11263
11264
11265
11266 NamedDecl *ActOnTemplateTemplateParameter(
11267 Scope *S, SourceLocation TmpLoc, TemplateParameterList *Params,
11268 bool Typename, SourceLocation EllipsisLoc, IdentifierInfo *ParamName,
11269 SourceLocation ParamNameLoc, unsigned Depth, unsigned Position,
11270 SourceLocation EqualLoc, ParsedTemplateArgument DefaultArg);
11271
11272
11273
11274
11275 TemplateParameterList *ActOnTemplateParameterList(
11276 unsigned Depth, SourceLocation ExportLoc, SourceLocation TemplateLoc,
11277 SourceLocation LAngleLoc, ArrayRef<NamedDecl *> Params,
11278 SourceLocation RAngleLoc, Expr *RequiresClause);
11279
11280
11281 enum TemplateParamListContext {
11282
11283
11284 TPC_Other,
11285
11286 TPC_FunctionTemplate,
11287 TPC_ClassTemplateMember,
11288 TPC_FriendClassTemplate,
11289 TPC_FriendFunctionTemplate,
11290 TPC_FriendFunctionTemplateDefinition,
11291 TPC_TemplateTemplateParameterPack,
11292 };
11293
11294
11295
11296
11297
11298
11299
11300
11301
11302
11303
11304
11305
11306
11307
11308
11309
11310
11311
11312
11313
11314
11315
11316
11317
11318
11319
11320
11321
11322 bool CheckTemplateParameterList(TemplateParameterList *NewParams,
11323 TemplateParameterList *OldParams,
11324 TemplateParamListContext TPC,
11325 SkipBodyInfo *SkipBody = nullptr);
11326
11327
11328
11329
11330
11331
11332
11333
11334
11335
11336
11337
11338
11339
11340
11341
11342
11343
11344
11345
11346
11347
11348
11349
11350
11351
11352
11353
11354
11355
11356
11357
11358
11359
11360 TemplateParameterList *MatchTemplateParametersToScopeSpecifier(
11361 SourceLocation DeclStartLoc, SourceLocation DeclLoc,
11362 const CXXScopeSpec &SS, TemplateIdAnnotation *TemplateId,
11363 ArrayRef<TemplateParameterList *> ParamLists, bool IsFriend,
11364 bool &IsMemberSpecialization, bool &Invalid,
11365 bool SuppressDiagnostic = false);
11366
11367
11368
11369 TemplateParameterList *GetTemplateParameterList(TemplateDecl *TD);
11370
11371 DeclResult CheckClassTemplate(
11372 Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc,
11373 CXXScopeSpec &SS, IdentifierInfo *Name, SourceLocation NameLoc,
11374 const ParsedAttributesView &Attr, TemplateParameterList *TemplateParams,
11375 AccessSpecifier AS, SourceLocation ModulePrivateLoc,
11376 SourceLocation FriendLoc, unsigned NumOuterTemplateParamLists,
11377 TemplateParameterList **OuterTemplateParamLists,
11378 SkipBodyInfo *SkipBody = nullptr);
11379
11380
11381
11382 void translateTemplateArguments(const ASTTemplateArgsPtr &In,
11383 TemplateArgumentListInfo &Out);
11384
11385
11386
11387
11388
11389 ParsedTemplateArgument ActOnTemplateTypeArgument(TypeResult ParsedType);
11390
11391 void NoteAllFoundTemplates(TemplateName Name);
11392
11393 QualType CheckTemplateIdType(TemplateName Template,
11394 SourceLocation TemplateLoc,
11395 TemplateArgumentListInfo &TemplateArgs);
11396
11397 TypeResult
11398 ActOnTemplateIdType(Scope *S, CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
11399 TemplateTy Template, const IdentifierInfo *TemplateII,
11400 SourceLocation TemplateIILoc, SourceLocation LAngleLoc,
11401 ASTTemplateArgsPtr TemplateArgs, SourceLocation RAngleLoc,
11402 bool IsCtorOrDtorName = false, bool IsClassName = false,
11403 ImplicitTypenameContext AllowImplicitTypename =
11404 ImplicitTypenameContext::No);
11405
11406
11407
11408 TypeResult ActOnTagTemplateIdType(
11409 TagUseKind TUK, TypeSpecifierType TagSpec, SourceLocation TagLoc,
11410 CXXScopeSpec &SS, SourceLocation TemplateKWLoc, TemplateTy TemplateD,
11411 SourceLocation TemplateLoc, SourceLocation LAngleLoc,
11412 ASTTemplateArgsPtr TemplateArgsIn, SourceLocation RAngleLoc);
11413
11414 DeclResult ActOnVarTemplateSpecialization(
11415 Scope *S, Declarator &D, TypeSourceInfo *DI, LookupResult &Previous,
11416 SourceLocation TemplateKWLoc, TemplateParameterList *TemplateParams,
11417 StorageClass SC, bool IsPartialSpecialization);
11418
11419
11420
11421
11422 DeclResult CheckVarTemplateId(VarTemplateDecl *Template,
11423 SourceLocation TemplateLoc,
11424 SourceLocation TemplateNameLoc,
11425 const TemplateArgumentListInfo &TemplateArgs);
11426
11427
11428
11429
11430 ExprResult CheckVarTemplateId(const CXXScopeSpec &SS,
11431 const DeclarationNameInfo &NameInfo,
11432 VarTemplateDecl *Template, NamedDecl *FoundD,
11433 SourceLocation TemplateLoc,
11434 const TemplateArgumentListInfo *TemplateArgs);
11435
11436 ExprResult
11437 CheckConceptTemplateId(const CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
11438 const DeclarationNameInfo &ConceptNameInfo,
11439 NamedDecl *FoundDecl, ConceptDecl *NamedConcept,
11440 const TemplateArgumentListInfo *TemplateArgs);
11441
11442 void diagnoseMissingTemplateArguments(TemplateName Name, SourceLocation Loc);
11443 void diagnoseMissingTemplateArguments(const CXXScopeSpec &SS,
11444 bool TemplateKeyword, TemplateDecl *TD,
11445 SourceLocation Loc);
11446
11447 ExprResult BuildTemplateIdExpr(const CXXScopeSpec &SS,
11448 SourceLocation TemplateKWLoc, LookupResult &R,
11449 bool RequiresADL,
11450 const TemplateArgumentListInfo *TemplateArgs);
11451
11452
11453 ExprResult
11454 BuildQualifiedTemplateIdExpr(CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
11455 const DeclarationNameInfo &NameInfo,
11456 const TemplateArgumentListInfo *TemplateArgs,
11457 bool IsAddressOfOperand);
11458
11459
11460
11461
11462
11463
11464
11465
11466
11467
11468
11469
11470
11471
11472
11473
11474 TemplateNameKind ActOnTemplateName(Scope *S, CXXScopeSpec &SS,
11475 SourceLocation TemplateKWLoc,
11476 const UnqualifiedId &Name,
11477 ParsedType ObjectType,
11478 bool EnteringContext, TemplateTy &Template,
11479 bool AllowInjectedClassName = false);
11480
11481 DeclResult ActOnClassTemplateSpecialization(
11482 Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc,
11483 SourceLocation ModulePrivateLoc, CXXScopeSpec &SS,
11484 TemplateIdAnnotation &TemplateId, const ParsedAttributesView &Attr,
11485 MultiTemplateParamsArg TemplateParameterLists,
11486 SkipBodyInfo *SkipBody = nullptr);
11487
11488
11489
11490
11491
11492
11493
11494
11495
11496
11497
11498
11499 bool CheckTemplatePartialSpecializationArgs(SourceLocation Loc,
11500 TemplateDecl *PrimaryTemplate,
11501 unsigned NumExplicitArgs,
11502 ArrayRef<TemplateArgument> Args);
11503 void CheckTemplatePartialSpecialization(
11504 ClassTemplatePartialSpecializationDecl *Partial);
11505 void CheckTemplatePartialSpecialization(
11506 VarTemplatePartialSpecializationDecl *Partial);
11507
11508 Decl *ActOnTemplateDeclarator(Scope *S,
11509 MultiTemplateParamsArg TemplateParameterLists,
11510 Declarator &D);
11511
11512
11513
11514
11515
11516
11517
11518
11519
11520
11521
11522
11523
11524
11525
11526
11527
11528
11529
11530
11531
11532
11533
11534
11535
11536 bool CheckSpecializationInstantiationRedecl(
11537 SourceLocation NewLoc,
11538 TemplateSpecializationKind ActOnExplicitInstantiationNewTSK,
11539 NamedDecl *PrevDecl, TemplateSpecializationKind PrevTSK,
11540 SourceLocation PrevPtOfInstantiation, bool &SuppressNew);
11541
11542
11543
11544
11545
11546
11547
11548
11549
11550
11551
11552
11553
11554
11555
11556
11557 bool CheckDependentFunctionTemplateSpecialization(
11558 FunctionDecl *FD, const TemplateArgumentListInfo *ExplicitTemplateArgs,
11559 LookupResult &Previous);
11560
11561
11562
11563
11564
11565
11566
11567
11568
11569
11570
11571
11572
11573
11574
11575
11576
11577
11578
11579
11580
11581
11582
11583 bool CheckFunctionTemplateSpecialization(
11584 FunctionDecl *FD, TemplateArgumentListInfo *ExplicitTemplateArgs,
11585 LookupResult &Previous, bool QualifiedFriend = false);
11586
11587
11588
11589
11590
11591
11592
11593
11594
11595
11596
11597
11598
11599
11600
11601 bool CheckMemberSpecialization(NamedDecl *Member, LookupResult &Previous);
11602 void CompleteMemberSpecialization(NamedDecl *Member, LookupResult &Previous);
11603
11604
11605 DeclResult ActOnExplicitInstantiation(
11606 Scope *S, SourceLocation ExternLoc, SourceLocation TemplateLoc,
11607 unsigned TagSpec, SourceLocation KWLoc, const CXXScopeSpec &SS,
11608 TemplateTy Template, SourceLocation TemplateNameLoc,
11609 SourceLocation LAngleLoc, ASTTemplateArgsPtr TemplateArgs,
11610 SourceLocation RAngleLoc, const ParsedAttributesView &Attr);
11611
11612
11613 DeclResult ActOnExplicitInstantiation(Scope *S, SourceLocation ExternLoc,
11614 SourceLocation TemplateLoc,
11615 unsigned TagSpec, SourceLocation KWLoc,
11616 CXXScopeSpec &SS, IdentifierInfo *Name,
11617 SourceLocation NameLoc,
11618 const ParsedAttributesView &Attr);
11619
11620 DeclResult ActOnExplicitInstantiation(Scope *S, SourceLocation ExternLoc,
11621 SourceLocation TemplateLoc,
11622 Declarator &D);
11623
11624
11625
11626
11627 TemplateArgumentLoc SubstDefaultTemplateArgumentIfAvailable(
11628 TemplateDecl *Template, SourceLocation TemplateLoc,
11629 SourceLocation RAngleLoc, Decl *Param,
11630 ArrayRef<TemplateArgument> SugaredConverted,
11631 ArrayRef<TemplateArgument> CanonicalConverted, bool &HasDefaultArg);
11632
11633
11634
11635
11636
11637 SourceLocation getTopMostPointOfInstantiation(const NamedDecl *) const;
11638
11639
11640
11641 enum CheckTemplateArgumentKind {
11642
11643
11644 CTAK_Specified,
11645
11646
11647
11648 CTAK_Deduced,
11649
11650
11651
11652 CTAK_DeducedFromArrayBound
11653 };
11654
11655 struct CheckTemplateArgumentInfo {
11656 explicit CheckTemplateArgumentInfo(bool PartialOrdering = false,
11657 bool MatchingTTP = false)
11658 : PartialOrdering(PartialOrdering), MatchingTTP(MatchingTTP) {}
11659 CheckTemplateArgumentInfo(const CheckTemplateArgumentInfo &) = delete;
11660 CheckTemplateArgumentInfo &
11661 operator=(const CheckTemplateArgumentInfo &) = delete;
11662
11663
11664
11665 SmallVector<TemplateArgument, 4> SugaredConverted, CanonicalConverted;
11666
11667
11668 bool PartialOrdering;
11669
11670
11671
11672
11673
11674
11675 bool MatchingTTP;
11676
11677
11678
11679 bool MatchedPackOnParmToNonPackOnArg = false;
11680 };
11681
11682
11683
11684
11685
11686
11687
11688
11689
11690
11691
11692
11693
11694
11695
11696
11697
11698
11699
11700
11701
11702
11703
11704
11705 bool CheckTemplateArgument(NamedDecl *Param, TemplateArgumentLoc &Arg,
11706 NamedDecl *Template, SourceLocation TemplateLoc,
11707 SourceLocation RAngleLoc,
11708 unsigned ArgumentPackIndex,
11709 CheckTemplateArgumentInfo &CTAI,
11710 CheckTemplateArgumentKind CTAK);
11711
11712
11713
11714
11715
11716
11717
11718
11719
11720
11721
11722
11723
11724
11725
11726
11727
11728
11729
11730
11731
11732
11733
11734
11735
11736
11737
11738
11739
11740
11741
11742
11743
11744 bool CheckTemplateArgumentList(TemplateDecl *Template,
11745 SourceLocation TemplateLoc,
11746 TemplateArgumentListInfo &TemplateArgs,
11747 const DefaultArguments &DefaultArgs,
11748 bool PartialTemplateArgs,
11749 CheckTemplateArgumentInfo &CTAI,
11750 bool UpdateArgsWithConversions = true,
11751 bool *ConstraintsNotSatisfied = nullptr);
11752
11753 bool CheckTemplateTypeArgument(
11754 TemplateTypeParmDecl *Param, TemplateArgumentLoc &Arg,
11755 SmallVectorImpl<TemplateArgument> &SugaredConverted,
11756 SmallVectorImpl<TemplateArgument> &CanonicalConverted);
11757
11758
11759
11760
11761
11762
11763 bool CheckTemplateArgument(TypeSourceInfo *Arg);
11764
11765
11766
11767
11768
11769
11770
11771
11772 ExprResult CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
11773 QualType InstantiatedParamType, Expr *Arg,
11774 TemplateArgument &SugaredConverted,
11775 TemplateArgument &CanonicalConverted,
11776 bool MatchingTTP,
11777 CheckTemplateArgumentKind CTAK);
11778
11779
11780
11781
11782
11783
11784 bool CheckTemplateTemplateArgument(TemplateTemplateParmDecl *Param,
11785 TemplateParameterList *Params,
11786 TemplateArgumentLoc &Arg,
11787 bool PartialOrdering,
11788 bool *MatchedPackOnParmToNonPackOnArg);
11789
11790 void NoteTemplateLocation(const NamedDecl &Decl,
11791 std::optional<SourceRange> ParamRange = {});
11792 void NoteTemplateParameterLocation(const NamedDecl &Decl);
11793
11794
11795
11796
11797
11798
11799
11800
11801 ExprResult BuildExpressionFromDeclTemplateArgument(
11802 const TemplateArgument &Arg, QualType ParamType, SourceLocation Loc,
11803 NamedDecl *TemplateParam = nullptr);
11804 ExprResult
11805 BuildExpressionFromNonTypeTemplateArgument(const TemplateArgument &Arg,
11806 SourceLocation Loc);
11807
11808
11809
11810 enum TemplateParameterListEqualKind {
11811
11812
11813
11814
11815
11816
11817
11818 TPL_TemplateMatch,
11819
11820
11821
11822
11823
11824
11825
11826
11827
11828 TPL_TemplateTemplateParmMatch,
11829
11830
11831
11832
11833
11834
11835
11836
11837
11838
11839 TPL_TemplateTemplateArgumentMatch,
11840
11841
11842
11843
11844
11845
11846
11847
11848
11849 TPL_TemplateParamsEquivalent,
11850 };
11851
11852
11853
11854
11855 class TemplateCompareNewDeclInfo {
11856 const NamedDecl *ND = nullptr;
11857 const DeclContext *DC = nullptr;
11858 const DeclContext *LexicalDC = nullptr;
11859 SourceLocation Loc;
11860
11861 public:
11862 TemplateCompareNewDeclInfo(const NamedDecl *ND) : ND(ND) {}
11863 TemplateCompareNewDeclInfo(const DeclContext *DeclCtx,
11864 const DeclContext *LexicalDeclCtx,
11865 SourceLocation Loc)
11866
11867 : DC(DeclCtx), LexicalDC(LexicalDeclCtx), Loc(Loc) {
11868 assert(DC && LexicalDC &&
11869 "Constructor only for cases where we have the information to put "
11870 "in here");
11871 }
11872
11873
11874
11875 bool isInvalid() const { return !ND && !DC; }
11876
11877 const NamedDecl *getDecl() const { return ND; }
11878
11879 bool ContainsDecl(const NamedDecl *ND) const { return this->ND == ND; }
11880
11881 const DeclContext *getLexicalDeclContext() const {
11882 return ND ? ND->getLexicalDeclContext() : LexicalDC;
11883 }
11884
11885 const DeclContext *getDeclContext() const {
11886 return ND ? ND->getDeclContext() : DC;
11887 }
11888
11889 SourceLocation getLocation() const { return ND ? ND->getLocation() : Loc; }
11890 };
11891
11892
11893
11894
11895
11896
11897
11898
11899
11900
11901
11902
11903
11904
11905
11906
11907
11908
11909
11910
11911
11912
11913
11914
11915 bool TemplateParameterListsAreEqual(
11916 const TemplateCompareNewDeclInfo &NewInstFrom, TemplateParameterList *New,
11917 const NamedDecl *OldInstFrom, TemplateParameterList *Old, bool Complain,
11918 TemplateParameterListEqualKind Kind,
11919 SourceLocation TemplateArgLoc = SourceLocation());
11920
11921 bool TemplateParameterListsAreEqual(
11922 TemplateParameterList *New, TemplateParameterList *Old, bool Complain,
11923 TemplateParameterListEqualKind Kind,
11924 SourceLocation TemplateArgLoc = SourceLocation()) {
11925 return TemplateParameterListsAreEqual(nullptr, New, nullptr, Old, Complain,
11926 Kind, TemplateArgLoc);
11927 }
11928
11929
11930
11931
11932
11933 bool CheckTemplateDeclScope(Scope *S, TemplateParameterList *TemplateParams);
11934
11935
11936
11937
11938
11939
11940
11941
11942
11943
11944 TypeResult ActOnTypenameType(
11945 Scope *S, SourceLocation TypenameLoc, const CXXScopeSpec &SS,
11946 const IdentifierInfo &II, SourceLocation IdLoc,
11947 ImplicitTypenameContext IsImplicitTypename = ImplicitTypenameContext::No);
11948
11949
11950
11951
11952
11953
11954
11955
11956
11957
11958
11959
11960
11961
11962
11963 TypeResult
11964 ActOnTypenameType(Scope *S, SourceLocation TypenameLoc,
11965 const CXXScopeSpec &SS, SourceLocation TemplateLoc,
11966 TemplateTy TemplateName, const IdentifierInfo *TemplateII,
11967 SourceLocation TemplateIILoc, SourceLocation LAngleLoc,
11968 ASTTemplateArgsPtr TemplateArgs, SourceLocation RAngleLoc);
11969
11970 QualType CheckTypenameType(ElaboratedTypeKeyword Keyword,
11971 SourceLocation KeywordLoc,
11972 NestedNameSpecifierLoc QualifierLoc,
11973 const IdentifierInfo &II, SourceLocation IILoc,
11974 TypeSourceInfo **TSI, bool DeducedTSTContext);
11975
11976 QualType CheckTypenameType(ElaboratedTypeKeyword Keyword,
11977 SourceLocation KeywordLoc,
11978 NestedNameSpecifierLoc QualifierLoc,
11979 const IdentifierInfo &II, SourceLocation IILoc,
11980 bool DeducedTSTContext = true);
11981
11982
11983
11984
11985
11986
11987
11988
11989
11990
11991
11992
11993
11994
11995
11996
11997
11998
11999
12000
12001
12002
12003
12004
12005
12006
12007
12008 TypeSourceInfo *RebuildTypeInCurrentInstantiation(TypeSourceInfo *T,
12009 SourceLocation Loc,
12010 DeclarationName Name);
12011 bool RebuildNestedNameSpecifierInCurrentInstantiation(CXXScopeSpec &SS);
12012
12013 ExprResult RebuildExprInCurrentInstantiation(Expr *E);
12014
12015
12016
12017 bool
12018 RebuildTemplateParamsInCurrentInstantiation(TemplateParameterList *Params);
12019
12020
12021
12022 std::string
12023 getTemplateArgumentBindingsText(const TemplateParameterList *Params,
12024 const TemplateArgumentList &Args);
12025
12026 std::string
12027 getTemplateArgumentBindingsText(const TemplateParameterList *Params,
12028 const TemplateArgument *Args,
12029 unsigned NumArgs);
12030
12031 void diagnoseExprIntendedAsTemplateName(Scope *S, ExprResult TemplateName,
12032 SourceLocation Less,
12033 SourceLocation Greater);
12034
12035
12036
12037
12038 ExprResult ActOnDependentIdExpression(
12039 const CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
12040 const DeclarationNameInfo &NameInfo, bool isAddressOfOperand,
12041 const TemplateArgumentListInfo *TemplateArgs);
12042
12043 ExprResult
12044 BuildDependentDeclRefExpr(const CXXScopeSpec &SS,
12045 SourceLocation TemplateKWLoc,
12046 const DeclarationNameInfo &NameInfo,
12047 const TemplateArgumentListInfo *TemplateArgs);
12048
12049
12050
12051
12052
12053
12054
12055
12056 bool
12057 ConstraintExpressionDependsOnEnclosingTemplate(const FunctionDecl *Friend,
12058 unsigned TemplateDepth,
12059 const Expr *Constraint);
12060
12061
12062
12063 std::pair<Expr *, std::string> findFailedBooleanCondition(Expr *Cond);
12064
12065 void CheckDeductionGuideTemplate(FunctionTemplateDecl *TD);
12066
12067 ConceptDecl *ActOnStartConceptDefinition(
12068 Scope *S, MultiTemplateParamsArg TemplateParameterLists,
12069 const IdentifierInfo *Name, SourceLocation NameLoc);
12070
12071 ConceptDecl *ActOnFinishConceptDefinition(Scope *S, ConceptDecl *C,
12072 Expr *ConstraintExpr,
12073 const ParsedAttributesView &Attrs);
12074
12075 void CheckConceptRedefinition(ConceptDecl *NewDecl, LookupResult &Previous,
12076 bool &AddToScope);
12077 bool CheckConceptUseInDefinition(ConceptDecl *Concept, SourceLocation Loc);
12078
12079 TypeResult ActOnDependentTag(Scope *S, unsigned TagSpec, TagUseKind TUK,
12080 const CXXScopeSpec &SS,
12081 const IdentifierInfo *Name,
12082 SourceLocation TagLoc, SourceLocation NameLoc);
12083
12084 void MarkAsLateParsedTemplate(FunctionDecl *FD, Decl *FnD,
12085 CachedTokens &Toks);
12086 void UnmarkAsLateParsedTemplate(FunctionDecl *FD);
12087 bool IsInsideALocalClassWithinATemplateFunction();
12088
12089
12090
12091
12092 void checkSpecializationVisibility(SourceLocation Loc, NamedDecl *Spec);
12093 void checkSpecializationReachability(SourceLocation Loc, NamedDecl *Spec);
12094
12095
12096
12097
12098
12099
12100
12101
12102
12103
12104
12105
12106
12107 public:
12108
12109
12110 bool AccessCheckingSFINAE;
12111
12112
12113
12114
12115 class SFINAETrap {
12116 Sema &SemaRef;
12117 unsigned PrevSFINAEErrors;
12118 bool PrevInNonInstantiationSFINAEContext;
12119 bool PrevAccessCheckingSFINAE;
12120 bool PrevLastDiagnosticIgnored;
12121
12122 public:
12123 explicit SFINAETrap(Sema &SemaRef, bool AccessCheckingSFINAE = false)
12124 : SemaRef(SemaRef), PrevSFINAEErrors(SemaRef.NumSFINAEErrors),
12125 PrevInNonInstantiationSFINAEContext(
12126 SemaRef.InNonInstantiationSFINAEContext),
12127 PrevAccessCheckingSFINAE(SemaRef.AccessCheckingSFINAE),
12128 PrevLastDiagnosticIgnored(
12129 SemaRef.getDiagnostics().isLastDiagnosticIgnored()) {
12130 if (!SemaRef.isSFINAEContext())
12131 SemaRef.InNonInstantiationSFINAEContext = true;
12132 SemaRef.AccessCheckingSFINAE = AccessCheckingSFINAE;
12133 }
12134
12135 ~SFINAETrap() {
12136 SemaRef.NumSFINAEErrors = PrevSFINAEErrors;
12137 SemaRef.InNonInstantiationSFINAEContext =
12138 PrevInNonInstantiationSFINAEContext;
12139 SemaRef.AccessCheckingSFINAE = PrevAccessCheckingSFINAE;
12140 SemaRef.getDiagnostics().setLastDiagnosticIgnored(
12141 PrevLastDiagnosticIgnored);
12142 }
12143
12144
12145 bool hasErrorOccurred() const {
12146 return SemaRef.NumSFINAEErrors > PrevSFINAEErrors;
12147 }
12148 };
12149
12150
12151
12152
12153
12154 class TentativeAnalysisScope {
12155 Sema &SemaRef;
12156
12157 SFINAETrap Trap;
12158 bool PrevDisableTypoCorrection;
12159
12160 public:
12161 explicit TentativeAnalysisScope(Sema &SemaRef)
12162 : SemaRef(SemaRef), Trap(SemaRef, true),
12163 PrevDisableTypoCorrection(SemaRef.DisableTypoCorrection) {
12164 SemaRef.DisableTypoCorrection = true;
12165 }
12166 ~TentativeAnalysisScope() {
12167 SemaRef.DisableTypoCorrection = PrevDisableTypoCorrection;
12168 }
12169 };
12170
12171
12172
12173
12174
12175
12176 typedef llvm::DenseMap<Decl *, SmallVector<PartialDiagnosticAt, 1>>
12177 SuppressedDiagnosticsMap;
12178 SuppressedDiagnosticsMap SuppressedDiagnostics;
12179
12180
12181
12182
12183
12184
12185
12186
12187 bool isSameOrCompatibleFunctionType(QualType Param, QualType Arg);
12188
12189
12190
12191
12192
12193
12194
12195
12196
12197
12198
12199
12200
12201
12202 TemplateArgumentLoc
12203 getTrivialTemplateArgumentLoc(const TemplateArgument &Arg, QualType NTTPType,
12204 SourceLocation Loc,
12205 NamedDecl *TemplateParam = nullptr);
12206
12207
12208
12209
12210 TemplateArgumentLoc getIdentityTemplateArgumentLoc(NamedDecl *Param,
12211 SourceLocation Location);
12212
12213
12214
12215
12216
12217 QualType adjustCCAndNoReturn(QualType ArgFunctionType, QualType FunctionType,
12218 bool AdjustExceptionSpec = false);
12219
12220 TemplateDeductionResult
12221 DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial,
12222 ArrayRef<TemplateArgument> TemplateArgs,
12223 sema::TemplateDeductionInfo &Info);
12224
12225 TemplateDeductionResult
12226 DeduceTemplateArguments(VarTemplatePartialSpecializationDecl *Partial,
12227 ArrayRef<TemplateArgument> TemplateArgs,
12228 sema::TemplateDeductionInfo &Info);
12229
12230
12231
12232
12233
12234
12235 TemplateDeductionResult
12236 DeduceTemplateArgumentsFromType(TemplateDecl *TD, QualType FromType,
12237 sema::TemplateDeductionInfo &Info);
12238
12239 TemplateDeductionResult DeduceTemplateArguments(
12240 TemplateParameterList *TemplateParams, ArrayRef<TemplateArgument> Ps,
12241 ArrayRef<TemplateArgument> As, sema::TemplateDeductionInfo &Info,
12242 SmallVectorImpl<DeducedTemplateArgument> &Deduced,
12243 bool NumberOfArgumentsMustMatch);
12244
12245
12246
12247
12248
12249
12250
12251
12252
12253
12254
12255
12256
12257
12258
12259
12260
12261
12262
12263
12264
12265
12266
12267
12268
12269 TemplateDeductionResult SubstituteExplicitTemplateArguments(
12270 FunctionTemplateDecl *FunctionTemplate,
12271 TemplateArgumentListInfo &ExplicitTemplateArgs,
12272 SmallVectorImpl<DeducedTemplateArgument> &Deduced,
12273 SmallVectorImpl<QualType> &ParamTypes, QualType *FunctionType,
12274 sema::TemplateDeductionInfo &Info);
12275
12276
12277
12278 struct OriginalCallArg {
12279 OriginalCallArg(QualType OriginalParamType, bool DecomposedParam,
12280 unsigned ArgIdx, QualType OriginalArgType)
12281 : OriginalParamType(OriginalParamType),
12282 DecomposedParam(DecomposedParam), ArgIdx(ArgIdx),
12283 OriginalArgType(OriginalArgType) {}
12284
12285 QualType OriginalParamType;
12286 bool DecomposedParam;
12287 unsigned ArgIdx;
12288 QualType OriginalArgType;
12289 };
12290
12291
12292
12293
12294
12295
12296
12297 TemplateDeductionResult FinishTemplateArgumentDeduction(
12298 FunctionTemplateDecl *FunctionTemplate,
12299 SmallVectorImpl<DeducedTemplateArgument> &Deduced,
12300 unsigned NumExplicitlySpecified, FunctionDecl *&Specialization,
12301 sema::TemplateDeductionInfo &Info,
12302 SmallVectorImpl<OriginalCallArg> const *OriginalCallArgs,
12303 bool PartialOverloading, bool PartialOrdering,
12304 llvm::function_ref<bool()> CheckNonDependent = [] { return false; });
12305
12306
12307
12308
12309
12310
12311
12312
12313
12314
12315
12316
12317
12318
12319
12320
12321
12322
12323
12324
12325
12326
12327
12328
12329
12330
12331
12332 TemplateDeductionResult DeduceTemplateArguments(
12333 FunctionTemplateDecl *FunctionTemplate,
12334 TemplateArgumentListInfo *ExplicitTemplateArgs, ArrayRef<Expr *> Args,
12335 FunctionDecl *&Specialization, sema::TemplateDeductionInfo &Info,
12336 bool PartialOverloading, bool AggregateDeductionCandidate,
12337 bool PartialOrdering, QualType ObjectType,
12338 Expr::Classification ObjectClassification,
12339 llvm::function_ref<bool(ArrayRef<QualType>)> CheckNonDependent);
12340
12341
12342
12343
12344
12345
12346
12347
12348
12349
12350
12351
12352
12353
12354
12355
12356
12357
12358
12359
12360
12361
12362
12363
12364
12365
12366
12367
12368
12369 TemplateDeductionResult DeduceTemplateArguments(
12370 FunctionTemplateDecl *FunctionTemplate,
12371 TemplateArgumentListInfo *ExplicitTemplateArgs, QualType ArgFunctionType,
12372 FunctionDecl *&Specialization, sema::TemplateDeductionInfo &Info,
12373 bool IsAddressOfFunction = false);
12374
12375
12376
12377
12378 TemplateDeductionResult DeduceTemplateArguments(
12379 FunctionTemplateDecl *FunctionTemplate, QualType ObjectType,
12380 Expr::Classification ObjectClassification, QualType ToType,
12381 CXXConversionDecl *&Specialization, sema::TemplateDeductionInfo &Info);
12382
12383
12384
12385
12386
12387
12388
12389
12390
12391
12392
12393
12394
12395
12396
12397
12398
12399
12400
12401
12402
12403
12404
12405
12406
12407 TemplateDeductionResult
12408 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
12409 TemplateArgumentListInfo *ExplicitTemplateArgs,
12410 FunctionDecl *&Specialization,
12411 sema::TemplateDeductionInfo &Info,
12412 bool IsAddressOfFunction = false);
12413
12414
12415 QualType SubstAutoType(QualType TypeWithAuto, QualType Replacement);
12416
12417 TypeSourceInfo *SubstAutoTypeSourceInfo(TypeSourceInfo *TypeWithAuto,
12418 QualType Replacement);
12419
12420
12421 QualType SubstAutoTypeDependent(QualType TypeWithAuto);
12422
12423
12424 TypeSourceInfo *
12425 SubstAutoTypeSourceInfoDependent(TypeSourceInfo *TypeWithAuto);
12426
12427
12428
12429 QualType ReplaceAutoType(QualType TypeWithAuto, QualType Replacement);
12430 TypeSourceInfo *ReplaceAutoTypeSourceInfo(TypeSourceInfo *TypeWithAuto,
12431 QualType Replacement);
12432
12433
12434
12435
12436
12437
12438
12439
12440
12441
12442
12443
12444
12445
12446
12447
12448
12449
12450
12451
12452 TemplateDeductionResult
12453 DeduceAutoType(TypeLoc AutoTypeLoc, Expr *Initializer, QualType &Result,
12454 sema::TemplateDeductionInfo &Info,
12455 bool DependentDeduction = false,
12456 bool IgnoreConstraints = false,
12457 TemplateSpecCandidateSet *FailedTSC = nullptr);
12458 void DiagnoseAutoDeductionFailure(const VarDecl *VDecl, const Expr *Init);
12459 bool DeduceReturnType(FunctionDecl *FD, SourceLocation Loc,
12460 bool Diagnose = true);
12461
12462 bool CheckIfFunctionSpecializationIsImmediate(FunctionDecl *FD,
12463 SourceLocation Loc);
12464
12465
12466
12467
12468
12469
12470
12471
12472
12473
12474
12475 ClassTemplatePartialSpecializationDecl *
12476 getMoreSpecializedPartialSpecialization(
12477 ClassTemplatePartialSpecializationDecl *PS1,
12478 ClassTemplatePartialSpecializationDecl *PS2, SourceLocation Loc);
12479
12480 bool isMoreSpecializedThanPrimary(ClassTemplatePartialSpecializationDecl *T,
12481 sema::TemplateDeductionInfo &Info);
12482
12483 VarTemplatePartialSpecializationDecl *getMoreSpecializedPartialSpecialization(
12484 VarTemplatePartialSpecializationDecl *PS1,
12485 VarTemplatePartialSpecializationDecl *PS2, SourceLocation Loc);
12486
12487 bool isMoreSpecializedThanPrimary(VarTemplatePartialSpecializationDecl *T,
12488 sema::TemplateDeductionInfo &Info);
12489
12490 bool isTemplateTemplateParameterAtLeastAsSpecializedAs(
12491 TemplateParameterList *PParam, TemplateDecl *PArg, TemplateDecl *AArg,
12492 const DefaultArguments &DefaultArgs, SourceLocation ArgLoc,
12493 bool PartialOrdering, bool *MatchedPackOnParmToNonPackOnArg);
12494
12495
12496
12497
12498
12499
12500
12501
12502 void MarkUsedTemplateParameters(const Expr *E, bool OnlyDeduced,
12503 unsigned Depth, llvm::SmallBitVector &Used);
12504
12505
12506
12507
12508
12509
12510
12511
12512
12513
12514 void MarkUsedTemplateParameters(const TemplateArgumentList &TemplateArgs,
12515 bool OnlyDeduced, unsigned Depth,
12516 llvm::SmallBitVector &Used);
12517 void
12518 MarkDeducedTemplateParameters(const FunctionTemplateDecl *FunctionTemplate,
12519 llvm::SmallBitVector &Deduced) {
12520 return MarkDeducedTemplateParameters(Context, FunctionTemplate, Deduced);
12521 }
12522
12523
12524
12525 static void
12526 MarkDeducedTemplateParameters(ASTContext &Ctx,
12527 const FunctionTemplateDecl *FunctionTemplate,
12528 llvm::SmallBitVector &Deduced);
12529
12530
12531
12532
12533
12534
12535
12536
12537
12538
12539
12540
12541
12542
12543
12544
12545
12546
12547
12548
12549
12550
12551
12552
12553
12554
12555
12556
12557
12558
12559 FunctionTemplateDecl *getMoreSpecializedTemplate(
12560 FunctionTemplateDecl *FT1, FunctionTemplateDecl *FT2, SourceLocation Loc,
12561 TemplatePartialOrderingContext TPOC, unsigned NumCallArguments1,
12562 QualType RawObj1Ty = {}, QualType RawObj2Ty = {}, bool Reversed = false);
12563
12564
12565
12566
12567
12568
12569
12570
12571
12572
12573
12574
12575
12576
12577
12578
12579
12580
12581
12582
12583
12584
12585
12586
12587
12588
12589
12590 UnresolvedSetIterator
12591 getMostSpecialized(UnresolvedSetIterator SBegin, UnresolvedSetIterator SEnd,
12592 TemplateSpecCandidateSet &FailedCandidates,
12593 SourceLocation Loc, const PartialDiagnostic &NoneDiag,
12594 const PartialDiagnostic &AmbigDiag,
12595 const PartialDiagnostic &CandidateDiag,
12596 bool Complain = true, QualType TargetType = QualType());
12597
12598
12599
12600
12601
12602
12603
12604
12605
12606
12607 FunctionDecl *getMoreConstrainedFunction(FunctionDecl *FD1,
12608 FunctionDecl *FD2);
12609
12610
12611
12612
12613
12614
12615
12616
12617
12618
12619
12620
12621
12622
12623
12624 void DeclareImplicitDeductionGuides(TemplateDecl *Template,
12625 SourceLocation Loc);
12626
12627 FunctionTemplateDecl *DeclareAggregateDeductionGuideFromInitList(
12628 TemplateDecl *Template, MutableArrayRef<QualType> ParamTypes,
12629 SourceLocation Loc);
12630
12631
12632
12633
12634
12635
12636
12637
12638
12639
12640
12641
12642
12643 public:
12644
12645 class ExtParameterInfoBuilder {
12646 SmallVector<FunctionProtoType::ExtParameterInfo, 16> Infos;
12647 bool HasInteresting = false;
12648
12649 public:
12650
12651
12652 void set(unsigned index, FunctionProtoType::ExtParameterInfo info) {
12653 assert(Infos.size() <= index);
12654 Infos.resize(index);
12655 Infos.push_back(info);
12656
12657 if (!HasInteresting)
12658 HasInteresting = (info != FunctionProtoType::ExtParameterInfo());
12659 }
12660
12661
12662
12663 const FunctionProtoType::ExtParameterInfo *
12664 getPointerOrNull(unsigned numParams) {
12665 if (!HasInteresting)
12666 return nullptr;
12667 Infos.resize(numParams);
12668 return Infos.data();
12669 }
12670 };
12671
12672
12673
12674 LocalInstantiationScope *CurrentInstantiationScope;
12675
12676 typedef llvm::DenseMap<ParmVarDecl *, llvm::TinyPtrVector<ParmVarDecl *>>
12677 UnparsedDefaultArgInstantiationsMap;
12678
12679
12680
12681
12682
12683
12684
12685
12686 UnparsedDefaultArgInstantiationsMap UnparsedDefaultArgInstantiations;
12687
12688
12689
12690
12691 struct CodeSynthesisContext {
12692
12693 enum SynthesisKind {
12694
12695
12696 TemplateInstantiation,
12697
12698
12699
12700
12701
12702
12703 DefaultTemplateArgumentInstantiation,
12704
12705
12706
12707
12708 DefaultFunctionArgumentInstantiation,
12709
12710
12711
12712 ExplicitTemplateArgumentSubstitution,
12713
12714
12715
12716
12717
12718
12719 DeducedTemplateArgumentSubstitution,
12720
12721
12722 LambdaExpressionSubstitution,
12723
12724
12725
12726
12727 PriorTemplateArgumentSubstitution,
12728
12729
12730
12731 DefaultTemplateArgumentChecking,
12732
12733
12734
12735 ExceptionSpecEvaluation,
12736
12737
12738
12739 ExceptionSpecInstantiation,
12740
12741
12742 RequirementInstantiation,
12743
12744
12745
12746 NestedRequirementConstraintsCheck,
12747
12748
12749 DeclaringSpecialMember,
12750
12751
12752
12753 DeclaringImplicitEqualityComparison,
12754
12755
12756
12757 DefiningSynthesizedFunction,
12758
12759
12760
12761
12762
12763 ConstraintsCheck,
12764
12765
12766 ConstraintSubstitution,
12767
12768
12769 ConstraintNormalization,
12770
12771
12772 RequirementParameterInstantiation,
12773
12774
12775
12776 ParameterMappingSubstitution,
12777
12778
12779 RewritingOperatorAsSpaceship,
12780
12781
12782 InitializingStructuredBinding,
12783
12784
12785 MarkingClassDllexported,
12786
12787
12788
12789 BuildingBuiltinDumpStructCall,
12790
12791
12792
12793
12794
12795 Memoization,
12796
12797
12798 BuildingDeductionGuides,
12799
12800
12801 TypeAliasTemplateInstantiation,
12802
12803
12804 PartialOrderingTTP,
12805 } Kind;
12806
12807
12808 bool SavedInNonInstantiationSFINAEContext;
12809
12810
12811 SourceLocation PointOfInstantiation;
12812
12813
12814 Decl *Entity;
12815
12816
12817
12818
12819 NamedDecl *Template;
12820
12821 union {
12822
12823
12824 const TemplateArgument *TemplateArgs;
12825
12826
12827 const Expr *const *CallArgs;
12828 };
12829
12830
12831
12832 union {
12833
12834 unsigned NumTemplateArgs;
12835
12836
12837 unsigned NumCallArgs;
12838
12839
12840 CXXSpecialMemberKind SpecialMember;
12841 };
12842
12843 ArrayRef<TemplateArgument> template_arguments() const {
12844 assert(Kind != DeclaringSpecialMember);
12845 return {TemplateArgs, NumTemplateArgs};
12846 }
12847
12848
12849
12850 sema::TemplateDeductionInfo *DeductionInfo;
12851
12852
12853
12854
12855 SourceRange InstantiationRange;
12856
12857 CodeSynthesisContext()
12858 : Kind(TemplateInstantiation),
12859 SavedInNonInstantiationSFINAEContext(false), Entity(nullptr),
12860 Template(nullptr), TemplateArgs(nullptr), NumTemplateArgs(0),
12861 DeductionInfo(nullptr) {}
12862
12863
12864
12865 bool isInstantiationRecord() const;
12866 };
12867
12868
12869
12870
12871
12872
12873
12874
12875
12876
12877
12878
12879 struct InstantiatingTemplate {
12880
12881
12882
12883 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
12884 Decl *Entity,
12885 SourceRange InstantiationRange = SourceRange());
12886
12887 struct ExceptionSpecification {};
12888
12889
12890 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
12891 FunctionDecl *Entity, ExceptionSpecification,
12892 SourceRange InstantiationRange = SourceRange());
12893
12894
12895 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
12896 TypeAliasTemplateDecl *Entity,
12897 ArrayRef<TemplateArgument> TemplateArgs,
12898 SourceRange InstantiationRange = SourceRange());
12899
12900
12901
12902 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
12903 TemplateParameter Param, TemplateDecl *Template,
12904 ArrayRef<TemplateArgument> TemplateArgs,
12905 SourceRange InstantiationRange = SourceRange());
12906
12907
12908
12909 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
12910 FunctionTemplateDecl *FunctionTemplate,
12911 ArrayRef<TemplateArgument> TemplateArgs,
12912 CodeSynthesisContext::SynthesisKind Kind,
12913 sema::TemplateDeductionInfo &DeductionInfo,
12914 SourceRange InstantiationRange = SourceRange());
12915
12916
12917
12918 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
12919 TemplateDecl *Template,
12920 ArrayRef<TemplateArgument> TemplateArgs,
12921 sema::TemplateDeductionInfo &DeductionInfo,
12922 SourceRange InstantiationRange = SourceRange());
12923
12924
12925
12926
12927 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
12928 ClassTemplatePartialSpecializationDecl *PartialSpec,
12929 ArrayRef<TemplateArgument> TemplateArgs,
12930 sema::TemplateDeductionInfo &DeductionInfo,
12931 SourceRange InstantiationRange = SourceRange());
12932
12933
12934
12935
12936 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
12937 VarTemplatePartialSpecializationDecl *PartialSpec,
12938 ArrayRef<TemplateArgument> TemplateArgs,
12939 sema::TemplateDeductionInfo &DeductionInfo,
12940 SourceRange InstantiationRange = SourceRange());
12941
12942
12943
12944 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
12945 ParmVarDecl *Param,
12946 ArrayRef<TemplateArgument> TemplateArgs,
12947 SourceRange InstantiationRange = SourceRange());
12948
12949
12950
12951 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
12952 NamedDecl *Template, NonTypeTemplateParmDecl *Param,
12953 ArrayRef<TemplateArgument> TemplateArgs,
12954 SourceRange InstantiationRange);
12955
12956
12957
12958 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
12959 NamedDecl *Template, TemplateTemplateParmDecl *Param,
12960 ArrayRef<TemplateArgument> TemplateArgs,
12961 SourceRange InstantiationRange);
12962
12963
12964
12965 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
12966 TemplateDecl *Template, NamedDecl *Param,
12967 ArrayRef<TemplateArgument> TemplateArgs,
12968 SourceRange InstantiationRange);
12969
12970 struct ConstraintsCheck {};
12971
12972
12973
12974 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
12975 ConstraintsCheck, NamedDecl *Template,
12976 ArrayRef<TemplateArgument> TemplateArgs,
12977 SourceRange InstantiationRange);
12978
12979 struct ConstraintSubstitution {};
12980
12981
12982
12983 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
12984 ConstraintSubstitution, NamedDecl *Template,
12985 sema::TemplateDeductionInfo &DeductionInfo,
12986 SourceRange InstantiationRange);
12987
12988 struct ConstraintNormalization {};
12989
12990 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
12991 ConstraintNormalization, NamedDecl *Template,
12992 SourceRange InstantiationRange);
12993
12994 struct ParameterMappingSubstitution {};
12995
12996
12997 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
12998 ParameterMappingSubstitution, NamedDecl *Template,
12999 SourceRange InstantiationRange);
13000
13001
13002
13003 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
13004 concepts::Requirement *Req,
13005 sema::TemplateDeductionInfo &DeductionInfo,
13006 SourceRange InstantiationRange = SourceRange());
13007
13008
13009
13010 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
13011 concepts::NestedRequirement *Req, ConstraintsCheck,
13012 SourceRange InstantiationRange = SourceRange());
13013
13014
13015 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
13016 const RequiresExpr *E,
13017 sema::TemplateDeductionInfo &DeductionInfo,
13018 SourceRange InstantiationRange);
13019
13020 struct BuildingDeductionGuidesTag {};
13021
13022 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
13023 TemplateDecl *Entity, BuildingDeductionGuidesTag,
13024 SourceRange InstantiationRange = SourceRange());
13025
13026 struct PartialOrderingTTP {};
13027
13028 InstantiatingTemplate(Sema &SemaRef, SourceLocation ArgLoc,
13029 PartialOrderingTTP, TemplateDecl *PArg,
13030 SourceRange InstantiationRange = SourceRange());
13031
13032
13033 void Clear();
13034
13035 ~InstantiatingTemplate() { Clear(); }
13036
13037
13038
13039 bool isInvalid() const { return Invalid; }
13040
13041
13042
13043 bool isAlreadyInstantiating() const { return AlreadyInstantiating; }
13044
13045 private:
13046 Sema &SemaRef;
13047 bool Invalid;
13048 bool AlreadyInstantiating;
13049 bool CheckInstantiationDepth(SourceLocation PointOfInstantiation,
13050 SourceRange InstantiationRange);
13051
13052 InstantiatingTemplate(Sema &SemaRef,
13053 CodeSynthesisContext::SynthesisKind Kind,
13054 SourceLocation PointOfInstantiation,
13055 SourceRange InstantiationRange, Decl *Entity,
13056 NamedDecl *Template = nullptr,
13057 ArrayRef<TemplateArgument> TemplateArgs = {},
13058 sema::TemplateDeductionInfo *DeductionInfo = nullptr);
13059
13060 InstantiatingTemplate(const InstantiatingTemplate &) = delete;
13061
13062 InstantiatingTemplate &operator=(const InstantiatingTemplate &) = delete;
13063 };
13064
13065 bool SubstTemplateArgument(const TemplateArgumentLoc &Input,
13066 const MultiLevelTemplateArgumentList &TemplateArgs,
13067 TemplateArgumentLoc &Output,
13068 SourceLocation Loc = {},
13069 const DeclarationName &Entity = {});
13070 bool
13071 SubstTemplateArguments(ArrayRef<TemplateArgumentLoc> Args,
13072 const MultiLevelTemplateArgumentList &TemplateArgs,
13073 TemplateArgumentListInfo &Outputs);
13074
13075
13076
13077
13078
13079
13080
13081
13082
13083
13084
13085
13086
13087
13088
13089
13090
13091
13092
13093
13094
13095
13096
13097
13098
13099
13100
13101
13102
13103
13104
13105
13106
13107
13108 MultiLevelTemplateArgumentList getTemplateInstantiationArgs(
13109 const NamedDecl *D, const DeclContext *DC = nullptr, bool Final = false,
13110 std::optional<ArrayRef<TemplateArgument>> Innermost = std::nullopt,
13111 bool RelativeToPrimary = false, const FunctionDecl *Pattern = nullptr,
13112 bool ForConstraintInstantiation = false,
13113 bool SkipForSpecialization = false,
13114 bool ForDefaultArgumentSubstitution = false);
13115
13116
13117
13118 class SynthesizedFunctionScope {
13119 Sema &S;
13120 Sema::ContextRAII SavedContext;
13121 bool PushedCodeSynthesisContext = false;
13122
13123 public:
13124 SynthesizedFunctionScope(Sema &S, DeclContext *DC)
13125 : S(S), SavedContext(S, DC) {
13126 auto *FD = dyn_cast<FunctionDecl>(DC);
13127 S.PushFunctionScope();
13128 S.PushExpressionEvaluationContext(
13129 (FD && FD->isImmediateFunction())
13130 ? ExpressionEvaluationContext::ImmediateFunctionContext
13131 : ExpressionEvaluationContext::PotentiallyEvaluated);
13132 if (FD) {
13133 auto &Current = S.currentEvaluationContext();
13134 const auto &Parent = S.parentEvaluationContext();
13135
13136 FD->setWillHaveBody(true);
13137 Current.InImmediateFunctionContext =
13138 FD->isImmediateFunction() ||
13139 (isLambdaMethod(FD) && (Parent.isConstantEvaluated() ||
13140 Parent.isImmediateFunctionContext()));
13141
13142 Current.InImmediateEscalatingFunctionContext =
13143 S.getLangOpts().CPlusPlus20 && FD->isImmediateEscalating();
13144 } else
13145 assert(isa<ObjCMethodDecl>(DC));
13146 }
13147
13148 void addContextNote(SourceLocation UseLoc) {
13149 assert(!PushedCodeSynthesisContext);
13150
13151 Sema::CodeSynthesisContext Ctx;
13152 Ctx.Kind = Sema::CodeSynthesisContext::DefiningSynthesizedFunction;
13153 Ctx.PointOfInstantiation = UseLoc;
13154 Ctx.Entity = cast<Decl>(S.CurContext);
13155 S.pushCodeSynthesisContext(Ctx);
13156
13157 PushedCodeSynthesisContext = true;
13158 }
13159
13160 ~SynthesizedFunctionScope() {
13161 if (PushedCodeSynthesisContext)
13162 S.popCodeSynthesisContext();
13163 if (auto *FD = dyn_cast<FunctionDecl>(S.CurContext)) {
13164 FD->setWillHaveBody(false);
13165 S.CheckImmediateEscalatingFunctionDefinition(FD, S.getCurFunction());
13166 }
13167 S.PopExpressionEvaluationContext();
13168 S.PopFunctionScopeInfo();
13169 }
13170 };
13171
13172
13173
13174
13175
13176 SmallVector<CodeSynthesisContext, 16> CodeSynthesisContexts;
13177
13178
13179 llvm::DenseSet<std::pair<Decl *, unsigned>> InstantiatingSpecializations;
13180
13181
13182
13183 llvm::DenseSet<QualType> InstantiatedNonDependentTypes;
13184
13185
13186
13187 SmallVector<Module *, 16> CodeSynthesisContextLookupModules;
13188
13189
13190
13191
13192 llvm::DenseSet<Module *> LookupModulesCache;
13193
13194
13195
13196 llvm::DenseMap<NamedDecl *, NamedDecl *> VisibleNamespaceCache;
13197
13198
13199
13200
13201
13202
13203 bool InNonInstantiationSFINAEContext;
13204
13205
13206
13207
13208
13209
13210
13211
13212 unsigned NonInstantiationEntries;
13213
13214
13215
13216
13217
13218
13219
13220 unsigned LastEmittedCodeSynthesisContextDepth = 0;
13221
13222
13223
13224
13225
13226
13227 std::vector<std::unique_ptr<TemplateInstantiationCallback>>
13228 TemplateInstCallbacks;
13229
13230
13231
13232
13233
13234
13235
13236 int ArgumentPackSubstitutionIndex;
13237
13238
13239
13240
13241
13242 class ArgumentPackSubstitutionIndexRAII {
13243 Sema &Self;
13244 int OldSubstitutionIndex;
13245
13246 public:
13247 ArgumentPackSubstitutionIndexRAII(Sema &Self, int NewSubstitutionIndex)
13248 : Self(Self), OldSubstitutionIndex(Self.ArgumentPackSubstitutionIndex) {
13249 Self.ArgumentPackSubstitutionIndex = NewSubstitutionIndex;
13250 }
13251
13252 ~ArgumentPackSubstitutionIndexRAII() {
13253 Self.ArgumentPackSubstitutionIndex = OldSubstitutionIndex;
13254 }
13255 };
13256
13257 friend class ArgumentPackSubstitutionRAII;
13258
13259 void pushCodeSynthesisContext(CodeSynthesisContext Ctx);
13260 void popCodeSynthesisContext();
13261
13262 void PrintContextStack() {
13263 if (!CodeSynthesisContexts.empty() &&
13264 CodeSynthesisContexts.size() != LastEmittedCodeSynthesisContextDepth) {
13265 PrintInstantiationStack();
13266 LastEmittedCodeSynthesisContextDepth = CodeSynthesisContexts.size();
13267 }
13268 if (PragmaAttributeCurrentTargetDecl)
13269 PrintPragmaAttributeInstantiationPoint();
13270 }
13271
13272
13273 void PrintInstantiationStack();
13274
13275
13276
13277
13278
13279
13280
13281
13282
13283 std::optional<sema::TemplateDeductionInfo *> isSFINAEContext() const;
13284
13285
13286
13287
13288
13289
13290
13291
13292
13293
13294
13295
13296
13297
13298
13299
13300
13301
13302
13303
13304
13305
13306
13307
13308
13309
13310
13311
13312
13313
13314
13315
13316
13317
13318
13319 TypeSourceInfo *SubstType(TypeSourceInfo *T,
13320 const MultiLevelTemplateArgumentList &TemplateArgs,
13321 SourceLocation Loc, DeclarationName Entity,
13322 bool AllowDeducedTST = false);
13323
13324 QualType SubstType(QualType T,
13325 const MultiLevelTemplateArgumentList &TemplateArgs,
13326 SourceLocation Loc, DeclarationName Entity,
13327 bool *IsIncompleteSubstitution = nullptr);
13328
13329 TypeSourceInfo *SubstType(TypeLoc TL,
13330 const MultiLevelTemplateArgumentList &TemplateArgs,
13331 SourceLocation Loc, DeclarationName Entity);
13332
13333
13334
13335
13336
13337 TypeSourceInfo *SubstFunctionDeclType(
13338 TypeSourceInfo *T, const MultiLevelTemplateArgumentList &TemplateArgs,
13339 SourceLocation Loc, DeclarationName Entity, CXXRecordDecl *ThisContext,
13340 Qualifiers ThisTypeQuals, bool EvaluateConstraints = true);
13341 void SubstExceptionSpec(FunctionDecl *New, const FunctionProtoType *Proto,
13342 const MultiLevelTemplateArgumentList &Args);
13343 bool SubstExceptionSpec(SourceLocation Loc,
13344 FunctionProtoType::ExceptionSpecInfo &ESI,
13345 SmallVectorImpl<QualType> &ExceptionStorage,
13346 const MultiLevelTemplateArgumentList &Args);
13347 ParmVarDecl *
13348 SubstParmVarDecl(ParmVarDecl *D,
13349 const MultiLevelTemplateArgumentList &TemplateArgs,
13350 int indexAdjustment, std::optional<unsigned> NumExpansions,
13351 bool ExpectParameterPack, bool EvaluateConstraints = true);
13352
13353
13354
13355
13356 bool SubstParmTypes(SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
13357 const FunctionProtoType::ExtParameterInfo *ExtParamInfos,
13358 const MultiLevelTemplateArgumentList &TemplateArgs,
13359 SmallVectorImpl<QualType> &ParamTypes,
13360 SmallVectorImpl<ParmVarDecl *> *OutParams,
13361 ExtParameterInfoBuilder &ParamInfos);
13362
13363
13364 bool SubstDefaultArgument(SourceLocation Loc, ParmVarDecl *Param,
13365 const MultiLevelTemplateArgumentList &TemplateArgs,
13366 bool ForCallExpr = false);
13367 ExprResult SubstExpr(Expr *E,
13368 const MultiLevelTemplateArgumentList &TemplateArgs);
13369
13370
13371
13372 template <typename InstTy> struct ConstraintEvalRAII {
13373 InstTy &TI;
13374 bool OldValue;
13375
13376 ConstraintEvalRAII(InstTy &TI)
13377 : TI(TI), OldValue(TI.getEvaluateConstraints()) {
13378 TI.setEvaluateConstraints(false);
13379 }
13380 ~ConstraintEvalRAII() { TI.setEvaluateConstraints(OldValue); }
13381 };
13382
13383
13384 ExprResult
13385 SubstConstraintExpr(Expr *E,
13386 const MultiLevelTemplateArgumentList &TemplateArgs);
13387
13388 ExprResult SubstConstraintExprWithoutSatisfaction(
13389 Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs);
13390
13391
13392
13393
13394
13395
13396
13397
13398
13399
13400
13401
13402
13403
13404 bool SubstExprs(ArrayRef<Expr *> Exprs, bool IsCall,
13405 const MultiLevelTemplateArgumentList &TemplateArgs,
13406 SmallVectorImpl<Expr *> &Outputs);
13407
13408 StmtResult SubstStmt(Stmt *S,
13409 const MultiLevelTemplateArgumentList &TemplateArgs);
13410
13411 ExprResult
13412 SubstInitializer(Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs,
13413 bool CXXDirectInit);
13414
13415
13416
13417
13418
13419
13420
13421 bool SubstBaseSpecifiers(CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern,
13422 const MultiLevelTemplateArgumentList &TemplateArgs);
13423
13424
13425
13426
13427
13428
13429
13430
13431
13432
13433
13434
13435
13436
13437
13438
13439
13440
13441
13442
13443
13444
13445
13446 bool InstantiateClass(SourceLocation PointOfInstantiation,
13447 CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern,
13448 const MultiLevelTemplateArgumentList &TemplateArgs,
13449 TemplateSpecializationKind TSK, bool Complain = true);
13450
13451
13452
13453
13454
13455
13456
13457
13458
13459
13460
13461
13462
13463
13464
13465
13466 bool InstantiateEnum(SourceLocation PointOfInstantiation,
13467 EnumDecl *Instantiation, EnumDecl *Pattern,
13468 const MultiLevelTemplateArgumentList &TemplateArgs,
13469 TemplateSpecializationKind TSK);
13470
13471
13472
13473
13474
13475
13476
13477
13478
13479
13480
13481
13482
13483
13484
13485 bool InstantiateInClassInitializer(
13486 SourceLocation PointOfInstantiation, FieldDecl *Instantiation,
13487 FieldDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs);
13488
13489 bool usesPartialOrExplicitSpecialization(
13490 SourceLocation Loc, ClassTemplateSpecializationDecl *ClassTemplateSpec);
13491
13492 bool InstantiateClassTemplateSpecialization(
13493 SourceLocation PointOfInstantiation,
13494 ClassTemplateSpecializationDecl *ClassTemplateSpec,
13495 TemplateSpecializationKind TSK, bool Complain,
13496 bool PrimaryHasMatchedPackOnParmToNonPackOnArg);
13497
13498
13499
13500
13501 void
13502 InstantiateClassMembers(SourceLocation PointOfInstantiation,
13503 CXXRecordDecl *Instantiation,
13504 const MultiLevelTemplateArgumentList &TemplateArgs,
13505 TemplateSpecializationKind TSK);
13506
13507
13508
13509
13510 void InstantiateClassTemplateSpecializationMembers(
13511 SourceLocation PointOfInstantiation,
13512 ClassTemplateSpecializationDecl *ClassTemplateSpec,
13513 TemplateSpecializationKind TSK);
13514
13515 NestedNameSpecifierLoc SubstNestedNameSpecifierLoc(
13516 NestedNameSpecifierLoc NNS,
13517 const MultiLevelTemplateArgumentList &TemplateArgs);
13518
13519
13520 DeclarationNameInfo
13521 SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
13522 const MultiLevelTemplateArgumentList &TemplateArgs);
13523 TemplateName
13524 SubstTemplateName(NestedNameSpecifierLoc QualifierLoc, TemplateName Name,
13525 SourceLocation Loc,
13526 const MultiLevelTemplateArgumentList &TemplateArgs);
13527
13528 bool SubstTypeConstraint(TemplateTypeParmDecl *Inst, const TypeConstraint *TC,
13529 const MultiLevelTemplateArgumentList &TemplateArgs,
13530 bool EvaluateConstraint);
13531
13532
13533 bool inTemplateInstantiation() const {
13534 return CodeSynthesisContexts.size() > NonInstantiationEntries;
13535 }
13536
13537 using EntityPrinter = llvm::function_ref<void(llvm::raw_ostream &)>;
13538
13539
13540
13541 concepts::Requirement::SubstitutionDiagnostic *
13542 createSubstDiagAt(SourceLocation Location, EntityPrinter Printer);
13543
13544
13545
13546
13547
13548
13549
13550
13551
13552
13553
13554
13555
13556 public:
13557
13558
13559
13560
13561
13562
13563
13564
13565 typedef std::pair<ValueDecl *, SourceLocation> PendingImplicitInstantiation;
13566
13567
13568
13569 std::deque<PendingImplicitInstantiation> PendingInstantiations;
13570
13571
13572
13573 SmallVector<PendingImplicitInstantiation, 1> LateParsedInstantiations;
13574
13575 SmallVector<SmallVector<VTableUse, 16>, 8> SavedVTableUses;
13576 SmallVector<std::deque<PendingImplicitInstantiation>, 8>
13577 SavedPendingInstantiations;
13578
13579
13580
13581
13582
13583
13584
13585
13586 std::deque<PendingImplicitInstantiation> PendingLocalImplicitInstantiations;
13587
13588 class LocalEagerInstantiationScope {
13589 public:
13590 LocalEagerInstantiationScope(Sema &S) : S(S) {
13591 SavedPendingLocalImplicitInstantiations.swap(
13592 S.PendingLocalImplicitInstantiations);
13593 }
13594
13595 void perform() { S.PerformPendingInstantiations(true); }
13596
13597 ~LocalEagerInstantiationScope() {
13598 assert(S.PendingLocalImplicitInstantiations.empty() &&
13599 "there shouldn't be any pending local implicit instantiations");
13600 SavedPendingLocalImplicitInstantiations.swap(
13601 S.PendingLocalImplicitInstantiations);
13602 }
13603
13604 private:
13605 Sema &S;
13606 std::deque<PendingImplicitInstantiation>
13607 SavedPendingLocalImplicitInstantiations;
13608 };
13609
13610
13611
13612 class FPFeaturesStateRAII {
13613 public:
13614 FPFeaturesStateRAII(Sema &S);
13615 ~FPFeaturesStateRAII();
13616 FPOptionsOverride getOverrides() { return OldOverrides; }
13617
13618 private:
13619 Sema &S;
13620 FPOptions OldFPFeaturesState;
13621 FPOptionsOverride OldOverrides;
13622 LangOptions::FPEvalMethodKind OldEvalMethod;
13623 SourceLocation OldFPPragmaLocation;
13624 };
13625
13626 class GlobalEagerInstantiationScope {
13627 public:
13628 GlobalEagerInstantiationScope(Sema &S, bool Enabled)
13629 : S(S), Enabled(Enabled) {
13630 if (!Enabled)
13631 return;
13632
13633 S.SavedPendingInstantiations.emplace_back();
13634 S.SavedPendingInstantiations.back().swap(S.PendingInstantiations);
13635
13636 S.SavedVTableUses.emplace_back();
13637 S.SavedVTableUses.back().swap(S.VTableUses);
13638 }
13639
13640 void perform() {
13641 if (Enabled) {
13642 S.DefineUsedVTables();
13643 S.PerformPendingInstantiations();
13644 }
13645 }
13646
13647 ~GlobalEagerInstantiationScope() {
13648 if (!Enabled)
13649 return;
13650
13651
13652 assert(S.VTableUses.empty() &&
13653 "VTableUses should be empty before it is discarded.");
13654 S.VTableUses.swap(S.SavedVTableUses.back());
13655 S.SavedVTableUses.pop_back();
13656
13657
13658 if (S.TUKind != TU_Prefix || !S.LangOpts.PCHInstantiateTemplates) {
13659 assert(S.PendingInstantiations.empty() &&
13660 "PendingInstantiations should be empty before it is discarded.");
13661 S.PendingInstantiations.swap(S.SavedPendingInstantiations.back());
13662 S.SavedPendingInstantiations.pop_back();
13663 } else {
13664
13665 S.PendingInstantiations.swap(S.SavedPendingInstantiations.back());
13666 S.PendingInstantiations.insert(
13667 S.PendingInstantiations.end(),
13668 S.SavedPendingInstantiations.back().begin(),
13669 S.SavedPendingInstantiations.back().end());
13670 S.SavedPendingInstantiations.pop_back();
13671 }
13672 }
13673
13674 private:
13675 Sema &S;
13676 bool Enabled;
13677 };
13678
13679 ExplicitSpecifier instantiateExplicitSpecifier(
13680 const MultiLevelTemplateArgumentList &TemplateArgs, ExplicitSpecifier ES);
13681
13682 struct LateInstantiatedAttribute {
13683 const Attr *TmplAttr;
13684 LocalInstantiationScope *Scope;
13685 Decl *NewDecl;
13686
13687 LateInstantiatedAttribute(const Attr *A, LocalInstantiationScope *S,
13688 Decl *D)
13689 : TmplAttr(A), Scope(S), NewDecl(D) {}
13690 };
13691 typedef SmallVector<LateInstantiatedAttribute, 16> LateInstantiatedAttrVec;
13692
13693 void InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs,
13694 const Decl *Pattern, Decl *Inst,
13695 LateInstantiatedAttrVec *LateAttrs = nullptr,
13696 LocalInstantiationScope *OuterMostScope = nullptr);
13697
13698
13699
13700
13701
13702
13703
13704 void updateAttrsForLateParsedTemplate(const Decl *Pattern, Decl *Inst);
13705
13706 void
13707 InstantiateAttrsForDecl(const MultiLevelTemplateArgumentList &TemplateArgs,
13708 const Decl *Pattern, Decl *Inst,
13709 LateInstantiatedAttrVec *LateAttrs = nullptr,
13710 LocalInstantiationScope *OuterMostScope = nullptr);
13711
13712
13713
13714
13715
13716 void InstantiateDefaultCtorDefaultArgs(CXXConstructorDecl *Ctor);
13717
13718 bool InstantiateDefaultArgument(SourceLocation CallLoc, FunctionDecl *FD,
13719 ParmVarDecl *Param);
13720 void InstantiateExceptionSpec(SourceLocation PointOfInstantiation,
13721 FunctionDecl *Function);
13722
13723
13724
13725
13726
13727
13728 FunctionDecl *InstantiateFunctionDeclaration(
13729 FunctionTemplateDecl *FTD, const TemplateArgumentList *Args,
13730 SourceLocation Loc,
13731 CodeSynthesisContext::SynthesisKind CSC =
13732 CodeSynthesisContext::ExplicitTemplateArgumentSubstitution);
13733
13734
13735
13736
13737
13738
13739
13740
13741
13742
13743
13744
13745
13746
13747
13748
13749
13750
13751 void InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
13752 FunctionDecl *Function,
13753 bool Recursive = false,
13754 bool DefinitionRequired = false,
13755 bool AtEndOfTU = false);
13756 VarTemplateSpecializationDecl *BuildVarTemplateInstantiation(
13757 VarTemplateDecl *VarTemplate, VarDecl *FromVar,
13758 const TemplateArgumentList *PartialSpecArgs,
13759 const TemplateArgumentListInfo &TemplateArgsInfo,
13760 SmallVectorImpl<TemplateArgument> &Converted,
13761 SourceLocation PointOfInstantiation,
13762 LateInstantiatedAttrVec *LateAttrs = nullptr,
13763 LocalInstantiationScope *StartingScope = nullptr);
13764
13765
13766
13767 VarTemplateSpecializationDecl *CompleteVarTemplateSpecializationDecl(
13768 VarTemplateSpecializationDecl *VarSpec, VarDecl *PatternDecl,
13769 const MultiLevelTemplateArgumentList &TemplateArgs);
13770
13771
13772
13773
13774 void
13775 BuildVariableInstantiation(VarDecl *NewVar, VarDecl *OldVar,
13776 const MultiLevelTemplateArgumentList &TemplateArgs,
13777 LateInstantiatedAttrVec *LateAttrs,
13778 DeclContext *Owner,
13779 LocalInstantiationScope *StartingScope,
13780 bool InstantiatingVarTemplate = false,
13781 VarTemplateSpecializationDecl *PrevVTSD = nullptr);
13782
13783
13784 void InstantiateVariableInitializer(
13785 VarDecl *Var, VarDecl *OldVar,
13786 const MultiLevelTemplateArgumentList &TemplateArgs);
13787
13788
13789
13790
13791
13792
13793
13794
13795
13796
13797
13798
13799
13800
13801
13802
13803 void InstantiateVariableDefinition(SourceLocation PointOfInstantiation,
13804 VarDecl *Var, bool Recursive = false,
13805 bool DefinitionRequired = false,
13806 bool AtEndOfTU = false);
13807
13808 void InstantiateMemInitializers(
13809 CXXConstructorDecl *New, const CXXConstructorDecl *Tmpl,
13810 const MultiLevelTemplateArgumentList &TemplateArgs);
13811
13812
13813
13814
13815
13816
13817
13818
13819
13820
13821
13822
13823
13824
13825
13826
13827
13828
13829
13830
13831
13832
13833
13834
13835
13836
13837
13838
13839 NamedDecl *
13840 FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D,
13841 const MultiLevelTemplateArgumentList &TemplateArgs,
13842 bool FindingInstantiatedContext = false);
13843
13844
13845
13846
13847
13848 DeclContext *
13849 FindInstantiatedContext(SourceLocation Loc, DeclContext *DC,
13850 const MultiLevelTemplateArgumentList &TemplateArgs);
13851
13852 Decl *SubstDecl(Decl *D, DeclContext *Owner,
13853 const MultiLevelTemplateArgumentList &TemplateArgs);
13854
13855
13856
13857 FunctionDecl *SubstSpaceshipAsEqualEqual(CXXRecordDecl *RD,
13858 FunctionDecl *Spaceship);
13859
13860
13861
13862 void PerformPendingInstantiations(bool LocalOnly = false);
13863
13864 TemplateParameterList *
13865 SubstTemplateParams(TemplateParameterList *Params, DeclContext *Owner,
13866 const MultiLevelTemplateArgumentList &TemplateArgs,
13867 bool EvaluateConstraints = true);
13868
13869 void PerformDependentDiagnostics(
13870 const DeclContext *Pattern,
13871 const MultiLevelTemplateArgumentList &TemplateArgs);
13872
13873 private:
13874
13875
13876 void addInstantiatedLocalVarsToScope(FunctionDecl *Function,
13877 const FunctionDecl *PatternDecl,
13878 LocalInstantiationScope &Scope);
13879
13880
13881
13882 bool addInstantiatedParametersToScope(
13883 FunctionDecl *Function, const FunctionDecl *PatternDecl,
13884 LocalInstantiationScope &Scope,
13885 const MultiLevelTemplateArgumentList &TemplateArgs);
13886
13887
13888
13889 bool addInstantiatedCapturesToScope(
13890 FunctionDecl *Function, const FunctionDecl *PatternDecl,
13891 LocalInstantiationScope &Scope,
13892 const MultiLevelTemplateArgumentList &TemplateArgs);
13893
13894 int ParsingClassDepth = 0;
13895
13896 class SavePendingParsedClassStateRAII {
13897 public:
13898 SavePendingParsedClassStateRAII(Sema &S) : S(S) { swapSavedState(); }
13899
13900 ~SavePendingParsedClassStateRAII() {
13901 assert(S.DelayedOverridingExceptionSpecChecks.empty() &&
13902 "there shouldn't be any pending delayed exception spec checks");
13903 assert(S.DelayedEquivalentExceptionSpecChecks.empty() &&
13904 "there shouldn't be any pending delayed exception spec checks");
13905 swapSavedState();
13906 }
13907
13908 private:
13909 Sema &S;
13910 decltype(DelayedOverridingExceptionSpecChecks)
13911 SavedOverridingExceptionSpecChecks;
13912 decltype(DelayedEquivalentExceptionSpecChecks)
13913 SavedEquivalentExceptionSpecChecks;
13914
13915 void swapSavedState() {
13916 SavedOverridingExceptionSpecChecks.swap(
13917 S.DelayedOverridingExceptionSpecChecks);
13918 SavedEquivalentExceptionSpecChecks.swap(
13919 S.DelayedEquivalentExceptionSpecChecks);
13920 }
13921 };
13922
13923
13924
13925
13926
13927
13928
13929
13930
13931
13932
13933
13934
13935 public:
13936
13937
13938 bool isUnexpandedParameterPackPermitted();
13939
13940
13941
13942
13943
13944
13945 enum UnexpandedParameterPackContext {
13946
13947 UPPC_Expression = 0,
13948
13949
13950 UPPC_BaseType,
13951
13952
13953 UPPC_DeclarationType,
13954
13955
13956 UPPC_DataMemberType,
13957
13958
13959 UPPC_BitFieldWidth,
13960
13961
13962 UPPC_StaticAssertExpression,
13963
13964
13965 UPPC_FixedUnderlyingType,
13966
13967
13968 UPPC_EnumeratorValue,
13969
13970
13971 UPPC_UsingDeclaration,
13972
13973
13974 UPPC_FriendDeclaration,
13975
13976
13977 UPPC_DeclarationQualifier,
13978
13979
13980 UPPC_Initializer,
13981
13982
13983 UPPC_DefaultArgument,
13984
13985
13986 UPPC_NonTypeTemplateParameterType,
13987
13988
13989 UPPC_ExceptionType,
13990
13991
13992 UPPC_ExplicitSpecialization,
13993
13994
13995 UPPC_PartialSpecialization,
13996
13997
13998 UPPC_IfExists,
13999
14000
14001 UPPC_IfNotExists,
14002
14003
14004 UPPC_Lambda,
14005
14006
14007 UPPC_Block,
14008
14009
14010 UPPC_TypeConstraint,
14011
14012
14013 UPPC_Requirement,
14014
14015
14016 UPPC_RequiresClause,
14017 };
14018
14019
14020
14021
14022
14023
14024
14025
14026
14027
14028
14029 bool DiagnoseUnexpandedParameterPacks(
14030 SourceLocation Loc, UnexpandedParameterPackContext UPPC,
14031 ArrayRef<UnexpandedParameterPack> Unexpanded);
14032
14033
14034
14035
14036
14037
14038
14039
14040
14041
14042 bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, TypeSourceInfo *T,
14043 UnexpandedParameterPackContext UPPC);
14044
14045
14046
14047
14048
14049
14050
14051
14052 bool DiagnoseUnexpandedParameterPack(
14053 Expr *E, UnexpandedParameterPackContext UPPC = UPPC_Expression);
14054
14055
14056
14057
14058
14059
14060
14061
14062 bool DiagnoseUnexpandedParameterPackInRequiresExpr(RequiresExpr *RE);
14063
14064
14065
14066
14067
14068
14069
14070
14071 bool DiagnoseUnexpandedParameterPack(const CXXScopeSpec &SS,
14072 UnexpandedParameterPackContext UPPC);
14073
14074
14075
14076
14077
14078
14079
14080
14081 bool DiagnoseUnexpandedParameterPack(const DeclarationNameInfo &NameInfo,
14082 UnexpandedParameterPackContext UPPC);
14083
14084
14085
14086
14087
14088
14089
14090
14091
14092
14093 bool DiagnoseUnexpandedParameterPack(SourceLocation Loc,
14094 TemplateName Template,
14095 UnexpandedParameterPackContext UPPC);
14096
14097
14098
14099
14100
14101
14102
14103
14104 bool DiagnoseUnexpandedParameterPack(TemplateArgumentLoc Arg,
14105 UnexpandedParameterPackContext UPPC);
14106
14107
14108
14109
14110
14111
14112 void collectUnexpandedParameterPacks(
14113 TemplateArgument Arg,
14114 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded);
14115
14116
14117
14118
14119
14120
14121 void collectUnexpandedParameterPacks(
14122 TemplateArgumentLoc Arg,
14123 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded);
14124
14125
14126
14127
14128
14129
14130 void collectUnexpandedParameterPacks(
14131 QualType T, SmallVectorImpl<UnexpandedParameterPack> &Unexpanded);
14132
14133
14134
14135
14136
14137
14138 void collectUnexpandedParameterPacks(
14139 TypeLoc TL, SmallVectorImpl<UnexpandedParameterPack> &Unexpanded);
14140
14141
14142
14143
14144
14145
14146 void collectUnexpandedParameterPacks(
14147 NestedNameSpecifierLoc NNS,
14148 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded);
14149
14150
14151
14152
14153
14154
14155 void collectUnexpandedParameterPacks(
14156 const DeclarationNameInfo &NameInfo,
14157 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded);
14158
14159
14160
14161 static void collectUnexpandedParameterPacks(
14162 Expr *E, SmallVectorImpl<UnexpandedParameterPack> &Unexpanded);
14163
14164
14165
14166
14167
14168
14169
14170
14171 ParsedTemplateArgument ActOnPackExpansion(const ParsedTemplateArgument &Arg,
14172 SourceLocation EllipsisLoc);
14173
14174
14175
14176
14177
14178
14179
14180
14181 TypeResult ActOnPackExpansion(ParsedType Type, SourceLocation EllipsisLoc);
14182
14183
14184
14185 TypeSourceInfo *CheckPackExpansion(TypeSourceInfo *Pattern,
14186 SourceLocation EllipsisLoc,
14187 std::optional<unsigned> NumExpansions);
14188
14189
14190
14191 QualType CheckPackExpansion(QualType Pattern, SourceRange PatternRange,
14192 SourceLocation EllipsisLoc,
14193 std::optional<unsigned> NumExpansions);
14194
14195
14196
14197
14198
14199
14200
14201
14202 ExprResult ActOnPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc);
14203
14204
14205
14206
14207
14208
14209
14210
14211 ExprResult CheckPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
14212 std::optional<unsigned> NumExpansions);
14213
14214
14215
14216
14217
14218
14219
14220
14221
14222
14223
14224
14225
14226
14227
14228
14229
14230
14231
14232
14233
14234
14235
14236
14237
14238
14239
14240
14241
14242
14243
14244
14245
14246
14247
14248 bool CheckParameterPacksForExpansion(
14249 SourceLocation EllipsisLoc, SourceRange PatternRange,
14250 ArrayRef<UnexpandedParameterPack> Unexpanded,
14251 const MultiLevelTemplateArgumentList &TemplateArgs, bool &ShouldExpand,
14252 bool &RetainExpansion, std::optional<unsigned> &NumExpansions);
14253
14254
14255
14256
14257
14258
14259
14260
14261 std::optional<unsigned> getNumArgumentsInExpansion(
14262 QualType T, const MultiLevelTemplateArgumentList &TemplateArgs);
14263
14264 std::optional<unsigned> getNumArgumentsInExpansionFromUnexpanded(
14265 llvm::ArrayRef<UnexpandedParameterPack> Unexpanded,
14266 const MultiLevelTemplateArgumentList &TemplateArgs);
14267
14268
14269
14270
14271
14272
14273
14274
14275
14276
14277
14278
14279
14280
14281
14282
14283 bool containsUnexpandedParameterPacks(Declarator &D);
14284
14285
14286
14287
14288
14289
14290
14291
14292
14293 TemplateArgumentLoc getTemplateArgumentPackExpansionPattern(
14294 TemplateArgumentLoc OrigLoc, SourceLocation &Ellipsis,
14295 std::optional<unsigned> &NumExpansions) const;
14296
14297
14298
14299
14300
14301
14302
14303 std::optional<unsigned> getFullyPackExpandedSize(TemplateArgument Arg);
14304
14305
14306
14307
14308
14309
14310
14311
14312
14313
14314
14315
14316
14317
14318
14319 ExprResult ActOnSizeofParameterPackExpr(Scope *S, SourceLocation OpLoc,
14320 IdentifierInfo &Name,
14321 SourceLocation NameLoc,
14322 SourceLocation RParenLoc);
14323
14324 ExprResult ActOnPackIndexingExpr(Scope *S, Expr *PackExpression,
14325 SourceLocation EllipsisLoc,
14326 SourceLocation LSquareLoc, Expr *IndexExpr,
14327 SourceLocation RSquareLoc);
14328
14329 ExprResult BuildPackIndexingExpr(Expr *PackExpression,
14330 SourceLocation EllipsisLoc, Expr *IndexExpr,
14331 SourceLocation RSquareLoc,
14332 ArrayRef<Expr *> ExpandedExprs = {},
14333 bool FullySubstituted = false);
14334
14335
14336 ExprResult ActOnCXXFoldExpr(Scope *S, SourceLocation LParenLoc, Expr *LHS,
14337 tok::TokenKind Operator,
14338 SourceLocation EllipsisLoc, Expr *RHS,
14339 SourceLocation RParenLoc);
14340 ExprResult BuildCXXFoldExpr(UnresolvedLookupExpr *Callee,
14341 SourceLocation LParenLoc, Expr *LHS,
14342 BinaryOperatorKind Operator,
14343 SourceLocation EllipsisLoc, Expr *RHS,
14344 SourceLocation RParenLoc,
14345 std::optional<unsigned> NumExpansions);
14346 ExprResult BuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
14347 BinaryOperatorKind Operator);
14348
14349
14350
14351
14352
14353
14354
14355
14356
14357
14358
14359
14360
14361 public:
14362 void PushSatisfactionStackEntry(const NamedDecl *D,
14363 const llvm::FoldingSetNodeID &ID) {
14364 const NamedDecl *Can = cast<NamedDecl>(D->getCanonicalDecl());
14365 SatisfactionStack.emplace_back(Can, ID);
14366 }
14367
14368 void PopSatisfactionStackEntry() { SatisfactionStack.pop_back(); }
14369
14370 bool SatisfactionStackContains(const NamedDecl *D,
14371 const llvm::FoldingSetNodeID &ID) const {
14372 const NamedDecl *Can = cast<NamedDecl>(D->getCanonicalDecl());
14373 return llvm::find(SatisfactionStack, SatisfactionStackEntryTy{Can, ID}) !=
14374 SatisfactionStack.end();
14375 }
14376
14377 using SatisfactionStackEntryTy =
14378 std::pair<const NamedDecl *, llvm::FoldingSetNodeID>;
14379
14380
14381
14382
14383 class SatisfactionStackResetRAII {
14384 llvm::SmallVector<SatisfactionStackEntryTy, 10> BackupSatisfactionStack;
14385 Sema &SemaRef;
14386
14387 public:
14388 SatisfactionStackResetRAII(Sema &S) : SemaRef(S) {
14389 SemaRef.SwapSatisfactionStack(BackupSatisfactionStack);
14390 }
14391
14392 ~SatisfactionStackResetRAII() {
14393 SemaRef.SwapSatisfactionStack(BackupSatisfactionStack);
14394 }
14395 };
14396
14397 void SwapSatisfactionStack(
14398 llvm::SmallVectorImpl<SatisfactionStackEntryTy> &NewSS) {
14399 SatisfactionStack.swap(NewSS);
14400 }
14401
14402
14403
14404
14405
14406 bool CheckConstraintExpression(const Expr *CE, Token NextToken = Token(),
14407 bool *PossibleNonPrimary = nullptr,
14408 bool IsTrailingRequiresClause = false);
14409
14410
14411
14412
14413
14414
14415
14416
14417
14418
14419
14420
14421
14422
14423
14424
14425 bool CheckConstraintSatisfaction(
14426 const NamedDecl *Template, ArrayRef<const Expr *> ConstraintExprs,
14427 const MultiLevelTemplateArgumentList &TemplateArgLists,
14428 SourceRange TemplateIDRange, ConstraintSatisfaction &Satisfaction) {
14429 llvm::SmallVector<Expr *, 4> Converted;
14430 return CheckConstraintSatisfaction(Template, ConstraintExprs, Converted,
14431 TemplateArgLists, TemplateIDRange,
14432 Satisfaction);
14433 }
14434
14435
14436
14437
14438
14439
14440
14441
14442
14443
14444
14445
14446
14447
14448
14449
14450
14451
14452
14453
14454
14455
14456
14457 bool CheckConstraintSatisfaction(
14458 const NamedDecl *Template, ArrayRef<const Expr *> ConstraintExprs,
14459 llvm::SmallVectorImpl<Expr *> &ConvertedConstraints,
14460 const MultiLevelTemplateArgumentList &TemplateArgList,
14461 SourceRange TemplateIDRange, ConstraintSatisfaction &Satisfaction);
14462
14463
14464
14465
14466
14467
14468
14469 bool CheckConstraintSatisfaction(const Expr *ConstraintExpr,
14470 ConstraintSatisfaction &Satisfaction);
14471
14472
14473
14474
14475
14476
14477
14478 bool CheckFunctionConstraints(const FunctionDecl *FD,
14479 ConstraintSatisfaction &Satisfaction,
14480 SourceLocation UsageLoc = SourceLocation(),
14481 bool ForOverloadResolution = false);
14482
14483
14484
14485
14486
14487
14488
14489 bool AreConstraintExpressionsEqual(const NamedDecl *Old,
14490 const Expr *OldConstr,
14491 const TemplateCompareNewDeclInfo &New,
14492 const Expr *NewConstr);
14493
14494
14495
14496 bool FriendConstraintsDependOnEnclosingTemplate(const FunctionDecl *FD);
14497
14498
14499
14500
14501
14502
14503
14504
14505
14506
14507
14508
14509
14510
14511 bool EnsureTemplateArgumentListConstraints(
14512 TemplateDecl *Template,
14513 const MultiLevelTemplateArgumentList &TemplateArgs,
14514 SourceRange TemplateIDRange);
14515
14516 bool CheckInstantiatedFunctionTemplateConstraints(
14517 SourceLocation PointOfInstantiation, FunctionDecl *Decl,
14518 ArrayRef<TemplateArgument> TemplateArgs,
14519 ConstraintSatisfaction &Satisfaction);
14520
14521
14522
14523
14524
14525 void DiagnoseUnsatisfiedConstraint(const ConstraintSatisfaction &Satisfaction,
14526 bool First = true);
14527
14528
14529
14530 void
14531 DiagnoseUnsatisfiedConstraint(const ASTConstraintSatisfaction &Satisfaction,
14532 bool First = true);
14533
14534 const NormalizedConstraint *getNormalizedAssociatedConstraints(
14535 NamedDecl *ConstrainedDecl, ArrayRef<const Expr *> AssociatedConstraints);
14536
14537
14538
14539
14540
14541
14542
14543
14544
14545 bool IsAtLeastAsConstrained(NamedDecl *D1, MutableArrayRef<const Expr *> AC1,
14546 NamedDecl *D2, MutableArrayRef<const Expr *> AC2,
14547 bool &Result);
14548
14549
14550
14551
14552
14553 bool MaybeEmitAmbiguousAtomicConstraintsDiagnostic(
14554 NamedDecl *D1, ArrayRef<const Expr *> AC1, NamedDecl *D2,
14555 ArrayRef<const Expr *> AC2);
14556
14557 private:
14558
14559
14560
14561 llvm::DenseMap<std::pair<NamedDecl *, NamedDecl *>, bool> SubsumptionCache;
14562
14563
14564
14565
14566 llvm::DenseMap<NamedDecl *, NormalizedConstraint *> NormalizationCache;
14567
14568 llvm::ContextualFoldingSet<ConstraintSatisfaction, const ASTContext &>
14569 SatisfactionCache;
14570
14571
14572 llvm::SmallVector<SatisfactionStackEntryTy, 10> SatisfactionStack;
14573
14574
14575
14576
14577 bool
14578 SetupConstraintScope(FunctionDecl *FD,
14579 std::optional<ArrayRef<TemplateArgument>> TemplateArgs,
14580 const MultiLevelTemplateArgumentList &MLTAL,
14581 LocalInstantiationScope &Scope);
14582
14583
14584
14585
14586 std::optional<MultiLevelTemplateArgumentList>
14587 SetupConstraintCheckingTemplateArgumentsAndScope(
14588 FunctionDecl *FD, std::optional<ArrayRef<TemplateArgument>> TemplateArgs,
14589 LocalInstantiationScope &Scope);
14590
14591
14592
14593
14594
14595
14596
14597
14598
14599
14600
14601
14602
14603 public:
14604
14605 FileNullabilityMap NullabilityMap;
14606
14607 static int getPrintable(int I) { return I; }
14608 static unsigned getPrintable(unsigned I) { return I; }
14609 static bool getPrintable(bool B) { return B; }
14610 static const char *getPrintable(const char *S) { return S; }
14611 static StringRef getPrintable(StringRef S) { return S; }
14612 static const std::string &getPrintable(const std::string &S) { return S; }
14613 static const IdentifierInfo *getPrintable(const IdentifierInfo *II) {
14614 return II;
14615 }
14616 static DeclarationName getPrintable(DeclarationName N) { return N; }
14617 static QualType getPrintable(QualType T) { return T; }
14618 static SourceRange getPrintable(SourceRange R) { return R; }
14619 static SourceRange getPrintable(SourceLocation L) { return L; }
14620 static SourceRange getPrintable(const Expr *E) { return E->getSourceRange(); }
14621 static SourceRange getPrintable(TypeLoc TL) { return TL.getSourceRange(); }
14622
14623 enum class CompleteTypeKind {
14624
14625
14626 Normal,
14627
14628
14629
14630 AcceptSizeless,
14631
14632
14633
14634 Default = AcceptSizeless
14635 };
14636
14637 QualType BuildQualifiedType(QualType T, SourceLocation Loc, Qualifiers Qs,
14638 const DeclSpec *DS = nullptr);
14639 QualType BuildQualifiedType(QualType T, SourceLocation Loc, unsigned CVRA,
14640 const DeclSpec *DS = nullptr);
14641
14642
14643
14644
14645
14646
14647
14648
14649
14650
14651
14652
14653
14654
14655 QualType BuildPointerType(QualType T, SourceLocation Loc,
14656 DeclarationName Entity);
14657
14658
14659
14660
14661
14662
14663
14664
14665
14666
14667
14668
14669
14670
14671 QualType BuildReferenceType(QualType T, bool LValueRef, SourceLocation Loc,
14672 DeclarationName Entity);
14673
14674
14675
14676
14677
14678
14679
14680
14681
14682
14683
14684
14685
14686
14687
14688
14689 QualType BuildArrayType(QualType T, ArraySizeModifier ASM, Expr *ArraySize,
14690 unsigned Quals, SourceRange Brackets,
14691 DeclarationName Entity);
14692 QualType BuildVectorType(QualType T, Expr *VecSize, SourceLocation AttrLoc);
14693
14694
14695
14696
14697 QualType BuildExtVectorType(QualType T, Expr *ArraySize,
14698 SourceLocation AttrLoc);
14699 QualType BuildMatrixType(QualType T, Expr *NumRows, Expr *NumColumns,
14700 SourceLocation AttrLoc);
14701
14702 QualType BuildCountAttributedArrayOrPointerType(QualType WrappedTy,
14703 Expr *CountExpr,
14704 bool CountInBytes,
14705 bool OrNull);
14706
14707
14708
14709
14710
14711
14712 QualType BuildAddressSpaceAttr(QualType &T, LangAS ASIdx, Expr *AddrSpace,
14713 SourceLocation AttrLoc);
14714
14715
14716 QualType BuildAddressSpaceAttr(QualType &T, Expr *AddrSpace,
14717 SourceLocation AttrLoc);
14718
14719 bool CheckQualifiedFunctionForTypeId(QualType T, SourceLocation Loc);
14720
14721 bool CheckFunctionReturnType(QualType T, SourceLocation Loc);
14722
14723
14724
14725
14726
14727
14728
14729
14730
14731
14732
14733
14734
14735
14736
14737
14738
14739
14740
14741
14742
14743
14744
14745
14746
14747
14748
14749
14750 QualType BuildFunctionType(QualType T, MutableArrayRef<QualType> ParamTypes,
14751 SourceLocation Loc, DeclarationName Entity,
14752 const FunctionProtoType::ExtProtoInfo &EPI);
14753
14754
14755
14756
14757
14758
14759
14760
14761
14762
14763
14764 QualType BuildMemberPointerType(QualType T, QualType Class,
14765 SourceLocation Loc, DeclarationName Entity);
14766
14767
14768
14769
14770
14771
14772
14773
14774
14775
14776
14777
14778 QualType BuildBlockPointerType(QualType T, SourceLocation Loc,
14779 DeclarationName Entity);
14780
14781
14782 QualType BuildParenType(QualType T);
14783 QualType BuildAtomicType(QualType T, SourceLocation Loc);
14784
14785
14786
14787
14788
14789
14790
14791
14792
14793 QualType BuildReadPipeType(QualType T, SourceLocation Loc);
14794
14795
14796
14797
14798
14799
14800
14801
14802
14803 QualType BuildWritePipeType(QualType T, SourceLocation Loc);
14804
14805
14806
14807
14808
14809
14810
14811
14812
14813 QualType BuildBitIntType(bool IsUnsigned, Expr *BitWidth, SourceLocation Loc);
14814
14815
14816
14817
14818
14819
14820 TypeSourceInfo *GetTypeForDeclarator(Declarator &D);
14821 TypeSourceInfo *GetTypeForDeclaratorCast(Declarator &D, QualType FromTy);
14822
14823
14824 ParsedType CreateParsedType(QualType T, TypeSourceInfo *TInfo);
14825 static QualType GetTypeFromParser(ParsedType Ty,
14826 TypeSourceInfo **TInfo = nullptr);
14827
14828 TypeResult ActOnTypeName(Declarator &D);
14829
14830
14831
14832 bool checkArrayElementAlignment(QualType EltTy, SourceLocation Loc);
14833
14834 void
14835 diagnoseIgnoredQualifiers(unsigned DiagID, unsigned Quals,
14836 SourceLocation FallbackLoc,
14837 SourceLocation ConstQualLoc = SourceLocation(),
14838 SourceLocation VolatileQualLoc = SourceLocation(),
14839 SourceLocation RestrictQualLoc = SourceLocation(),
14840 SourceLocation AtomicQualLoc = SourceLocation(),
14841 SourceLocation UnalignedQualLoc = SourceLocation());
14842
14843
14844 IdentifierInfo *getNullabilityKeyword(NullabilityKind nullability);
14845
14846
14847
14848
14849 void adjustMemberFunctionCC(QualType &T, bool HasThisPointer,
14850 bool IsCtorOrDtor, SourceLocation Loc);
14851
14852
14853
14854
14855 bool hasExplicitCallingConv(QualType T);
14856
14857
14858
14859
14860
14861
14862
14863
14864
14865
14866
14867
14868
14869
14870
14871
14872
14873
14874 bool CheckImplicitNullabilityTypeSpecifier(QualType &Type,
14875 NullabilityKind Nullability,
14876 SourceLocation DiagLoc,
14877 bool AllowArrayTypes,
14878 bool OverrideExisting);
14879
14880
14881
14882
14883
14884
14885
14886
14887
14888 QualType getCompletedType(Expr *E);
14889
14890 void completeExprArrayBound(Expr *E);
14891
14892
14893
14894
14895
14896
14897
14898
14899
14900
14901
14902
14903
14904
14905
14906
14907 bool RequireCompleteExprType(Expr *E, CompleteTypeKind Kind,
14908 TypeDiagnoser &Diagnoser);
14909 bool RequireCompleteExprType(Expr *E, unsigned DiagID);
14910
14911 template <typename... Ts>
14912 bool RequireCompleteExprType(Expr *E, unsigned DiagID, const Ts &...Args) {
14913 BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...);
14914 return RequireCompleteExprType(E, CompleteTypeKind::Default, Diagnoser);
14915 }
14916
14917
14918
14919
14920
14921 QualType getElaboratedType(ElaboratedTypeKeyword Keyword,
14922 const CXXScopeSpec &SS, QualType T,
14923 TagDecl *OwnedTagDecl = nullptr);
14924
14925
14926 QualType getDecltypeForExpr(Expr *E);
14927
14928 QualType BuildTypeofExprType(Expr *E, TypeOfKind Kind);
14929
14930
14931 QualType BuildDecltypeType(Expr *E, bool AsUnevaluated = true);
14932
14933 QualType ActOnPackIndexingType(QualType Pattern, Expr *IndexExpr,
14934 SourceLocation Loc,
14935 SourceLocation EllipsisLoc);
14936 QualType BuildPackIndexingType(QualType Pattern, Expr *IndexExpr,
14937 SourceLocation Loc, SourceLocation EllipsisLoc,
14938 bool FullySubstituted = false,
14939 ArrayRef<QualType> Expansions = {});
14940
14941 using UTTKind = UnaryTransformType::UTTKind;
14942 QualType BuildUnaryTransformType(QualType BaseType, UTTKind UKind,
14943 SourceLocation Loc);
14944 QualType BuiltinEnumUnderlyingType(QualType BaseType, SourceLocation Loc);
14945 QualType BuiltinAddPointer(QualType BaseType, SourceLocation Loc);
14946 QualType BuiltinRemovePointer(QualType BaseType, SourceLocation Loc);
14947 QualType BuiltinDecay(QualType BaseType, SourceLocation Loc);
14948 QualType BuiltinAddReference(QualType BaseType, UTTKind UKind,
14949 SourceLocation Loc);
14950 QualType BuiltinRemoveExtent(QualType BaseType, UTTKind UKind,
14951 SourceLocation Loc);
14952 QualType BuiltinRemoveReference(QualType BaseType, UTTKind UKind,
14953 SourceLocation Loc);
14954 QualType BuiltinChangeCVRQualifiers(QualType BaseType, UTTKind UKind,
14955 SourceLocation Loc);
14956 QualType BuiltinChangeSignedness(QualType BaseType, UTTKind UKind,
14957 SourceLocation Loc);
14958
14959
14960
14961
14962
14963
14964
14965
14966
14967
14968
14969
14970
14971
14972
14973
14974
14975
14976
14977 bool RequireLiteralType(SourceLocation Loc, QualType T,
14978 TypeDiagnoser &Diagnoser);
14979 bool RequireLiteralType(SourceLocation Loc, QualType T, unsigned DiagID);
14980
14981 template <typename... Ts>
14982 bool RequireLiteralType(SourceLocation Loc, QualType T, unsigned DiagID,
14983 const Ts &...Args) {
14984 BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...);
14985 return RequireLiteralType(Loc, T, Diagnoser);
14986 }
14987
14988 bool isCompleteType(SourceLocation Loc, QualType T,
14989 CompleteTypeKind Kind = CompleteTypeKind::Default) {
14990 return !RequireCompleteTypeImpl(Loc, T, Kind, nullptr);
14991 }
14992
14993
14994
14995
14996
14997
14998
14999
15000
15001
15002
15003
15004
15005
15006
15007
15008
15009
15010
15011
15012 bool RequireCompleteType(SourceLocation Loc, QualType T,
15013 CompleteTypeKind Kind, TypeDiagnoser &Diagnoser);
15014 bool RequireCompleteType(SourceLocation Loc, QualType T,
15015 CompleteTypeKind Kind, unsigned DiagID);
15016
15017 bool RequireCompleteType(SourceLocation Loc, QualType T,
15018 TypeDiagnoser &Diagnoser) {
15019 return RequireCompleteType(Loc, T, CompleteTypeKind::Default, Diagnoser);
15020 }
15021 bool RequireCompleteType(SourceLocation Loc, QualType T, unsigned DiagID) {
15022 return RequireCompleteType(Loc, T, CompleteTypeKind::Default, DiagID);
15023 }
15024
15025 template <typename... Ts>
15026 bool RequireCompleteType(SourceLocation Loc, QualType T, unsigned DiagID,
15027 const Ts &...Args) {
15028 BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...);
15029 return RequireCompleteType(Loc, T, Diagnoser);
15030 }
15031
15032
15033 bool isVisible(const NamedDecl *D) {
15034 return D->isUnconditionallyVisible() ||
15035 isAcceptableSlow(D, AcceptableKind::Visible);
15036 }
15037
15038
15039 bool isReachable(const NamedDecl *D) {
15040
15041 return D->isUnconditionallyVisible() ||
15042 isAcceptableSlow(D, AcceptableKind::Reachable);
15043 }
15044
15045
15046 bool isAcceptable(const NamedDecl *D, AcceptableKind Kind) {
15047 return Kind == AcceptableKind::Visible ? isVisible(D) : isReachable(D);
15048 }
15049
15050
15051
15052 bool hasStructuralCompatLayout(Decl *D, Decl *Suggested);
15053
15054
15055
15056 bool hasVisibleDefinition(NamedDecl *D, NamedDecl **Suggested,
15057 bool OnlyNeedComplete = false);
15058 bool hasVisibleDefinition(const NamedDecl *D) {
15059 NamedDecl *Hidden;
15060 return hasVisibleDefinition(const_cast<NamedDecl *>(D), &Hidden);
15061 }
15062
15063
15064
15065 bool hasReachableDefinition(NamedDecl *D, NamedDecl **Suggested,
15066 bool OnlyNeedComplete = false);
15067 bool hasReachableDefinition(NamedDecl *D) {
15068 NamedDecl *Hidden;
15069 return hasReachableDefinition(D, &Hidden);
15070 }
15071
15072 bool hasAcceptableDefinition(NamedDecl *D, NamedDecl **Suggested,
15073 AcceptableKind Kind,
15074 bool OnlyNeedComplete = false);
15075 bool hasAcceptableDefinition(NamedDecl *D, AcceptableKind Kind) {
15076 NamedDecl *Hidden;
15077 return hasAcceptableDefinition(D, &Hidden, Kind);
15078 }
15079
15080
15081
15082
15083 std::optional<FunctionEffectMode>
15084 ActOnEffectExpression(Expr *CondExpr, StringRef AttributeName);
15085
15086 private:
15087
15088 bool RequireCompleteTypeImpl(SourceLocation Loc, QualType T,
15089 CompleteTypeKind Kind, TypeDiagnoser *Diagnoser);
15090
15091
15092 IdentifierInfo *Ident__Nonnull = nullptr;
15093 IdentifierInfo *Ident__Nullable = nullptr;
15094 IdentifierInfo *Ident__Nullable_result = nullptr;
15095 IdentifierInfo *Ident__Null_unspecified = nullptr;
15096
15097
15098
15099
15100
15101
15102
15103
15104
15105
15106
15107
15108
15109 public:
15110
15111 std::string getFixItZeroInitializerForType(QualType T,
15112 SourceLocation Loc) const;
15113 std::string getFixItZeroLiteralForType(QualType T, SourceLocation Loc) const;
15114
15115
15116
15117
15118
15119
15120
15121
15122
15123
15124
15125
15126 public:
15127 struct FunctionEffectDiff {
15128 enum class Kind { Added, Removed, ConditionMismatch };
15129
15130 FunctionEffect::Kind EffectKind;
15131 Kind DiffKind;
15132 std::optional<FunctionEffectWithCondition>
15133 Old;
15134 std::optional<FunctionEffectWithCondition>
15135 New;
15136
15137 StringRef effectName() const {
15138 if (Old)
15139 return Old.value().Effect.name();
15140 return New.value().Effect.name();
15141 }
15142
15143
15144
15145 enum class OverrideResult {
15146 NoAction,
15147 Warn,
15148 Merge
15149 };
15150
15151
15152
15153 bool shouldDiagnoseConversion(QualType SrcType,
15154 const FunctionEffectsRef &SrcFX,
15155 QualType DstType,
15156 const FunctionEffectsRef &DstFX) const;
15157
15158
15159
15160 bool shouldDiagnoseRedeclaration(const FunctionDecl &OldFunction,
15161 const FunctionEffectsRef &OldFX,
15162 const FunctionDecl &NewFunction,
15163 const FunctionEffectsRef &NewFX) const;
15164
15165
15166
15167 OverrideResult shouldDiagnoseMethodOverride(
15168 const CXXMethodDecl &OldMethod, const FunctionEffectsRef &OldFX,
15169 const CXXMethodDecl &NewMethod, const FunctionEffectsRef &NewFX) const;
15170 };
15171
15172 struct FunctionEffectDiffVector : public SmallVector<FunctionEffectDiff> {
15173
15174 FunctionEffectDiffVector(const FunctionEffectsRef &Old,
15175 const FunctionEffectsRef &New);
15176 };
15177
15178
15179
15180 SmallVector<const Decl *> DeclsWithEffectsToVerify;
15181
15182
15183
15184 FunctionEffectKindSet AllEffectsToVerify;
15185
15186 public:
15187
15188
15189 bool diagnoseConflictingFunctionEffect(const FunctionEffectsRef &FX,
15190 const FunctionEffectWithCondition &EC,
15191 SourceLocation NewAttrLoc);
15192
15193
15194
15195 void
15196 diagnoseFunctionEffectMergeConflicts(const FunctionEffectSet::Conflicts &Errs,
15197 SourceLocation NewLoc,
15198 SourceLocation OldLoc);
15199
15200
15201
15202 template <class FuncOrBlockDecl>
15203 void maybeAddDeclWithEffects(FuncOrBlockDecl *D) {
15204 if (Context.hasAnyFunctionEffects())
15205 if (FunctionEffectsRef FX = D->getFunctionEffects(); !FX.empty())
15206 maybeAddDeclWithEffects(D, FX);
15207 }
15208
15209
15210 void maybeAddDeclWithEffects(const Decl *D, const FunctionEffectsRef &FX);
15211
15212
15213 void addDeclWithEffects(const Decl *D, const FunctionEffectsRef &FX);
15214
15215 void performFunctionEffectAnalysis(TranslationUnitDecl *TU);
15216
15217
15218 };
15219
15220 DeductionFailureInfo
15221 MakeDeductionFailureInfo(ASTContext &Context, TemplateDeductionResult TDK,
15222 sema::TemplateDeductionInfo &Info);
15223
15224
15225
15226 struct LateParsedTemplate {
15227 CachedTokens Toks;
15228
15229 Decl *D;
15230
15231 FPOptions FPO;
15232 };
15233
15234 template <>
15235 void Sema::PragmaStack<Sema::AlignPackInfo>::Act(SourceLocation PragmaLocation,
15236 PragmaMsStackAction Action,
15237 llvm::StringRef StackSlotLabel,
15238 AlignPackInfo Value);
15239 }
15240
15241 #endif