Author: Vlad Serebrennikov Date: 2023-11-05T16:38:45+03:00 New Revision: a9070f22a29e28f7d6f83c24a8dd88f3a94969ae
URL: https://github.com/llvm/llvm-project/commit/a9070f22a29e28f7d6f83c24a8dd88f3a94969ae DIFF: https://github.com/llvm/llvm-project/commit/a9070f22a29e28f7d6f83c24a8dd88f3a94969ae.diff LOG: [clang][NFC] Refactor `CXXConstructExpr::ConstructionKind` This patch converts `CXXConstructExpr::ConstructionKind` into a scoped enum in namespace scope, making it eligible for forward declaring. This is useful in cases like annotating bit-fields with `preferred_type`. Added: Modified: clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp clang/include/clang/AST/ExprCXX.h clang/include/clang/Sema/Sema.h clang/lib/AST/ExprCXX.cpp clang/lib/AST/JSONNodeDumper.cpp clang/lib/CodeGen/CGExprCXX.cpp clang/lib/Sema/SemaDeclCXX.cpp clang/lib/Sema/SemaExprCXX.cpp clang/lib/Sema/SemaInit.cpp clang/lib/Sema/TreeTransform.h clang/lib/Serialization/ASTWriterStmt.cpp clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp clang/lib/StaticAnalyzer/Core/CoreEngine.cpp clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp clang/www/analyzer/open_projects.html Removed: ################################################################################ diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp index c92bd8afa6add82..e7e01bab0e9d523 100644 --- a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp +++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp @@ -174,7 +174,7 @@ const Expr *digThroughConstructorsConversions(const Expr *E) { // The initial constructor must take exactly one parameter, but base class // and deferred constructors can take more. if (ConstructExpr->getNumArgs() != 1 || - ConstructExpr->getConstructionKind() != CXXConstructExpr::CK_Complete) + ConstructExpr->getConstructionKind() != CXXConstructionKind::Complete) return nullptr; E = ConstructExpr->getArg(0); if (const auto *Temp = dyn_cast<MaterializeTemporaryExpr>(E)) diff --git a/clang/include/clang/AST/ExprCXX.h b/clang/include/clang/AST/ExprCXX.h index 020dcfd86ad67ea..a106bafcfa3e021 100644 --- a/clang/include/clang/AST/ExprCXX.h +++ b/clang/include/clang/AST/ExprCXX.h @@ -1519,19 +1519,17 @@ class CXXBindTemporaryExpr : public Expr { } }; +enum class CXXConstructionKind { + Complete, + NonVirtualBase, + VirtualBase, + Delegating +}; + /// Represents a call to a C++ constructor. class CXXConstructExpr : public Expr { friend class ASTStmtReader; -public: - enum ConstructionKind { - CK_Complete, - CK_NonVirtualBase, - CK_VirtualBase, - CK_Delegating - }; - -private: /// A pointer to the constructor which will be ultimately called. CXXConstructorDecl *Constructor; @@ -1567,7 +1565,7 @@ class CXXConstructExpr : public Expr { CXXConstructorDecl *Ctor, bool Elidable, ArrayRef<Expr *> Args, bool HadMultipleCandidates, bool ListInitialization, bool StdInitListInitialization, - bool ZeroInitialization, ConstructionKind ConstructKind, + bool ZeroInitialization, CXXConstructionKind ConstructKind, SourceRange ParenOrBraceRange); /// Build an empty C++ construction expression. @@ -1586,7 +1584,7 @@ class CXXConstructExpr : public Expr { CXXConstructorDecl *Ctor, bool Elidable, ArrayRef<Expr *> Args, bool HadMultipleCandidates, bool ListInitialization, bool StdInitListInitialization, bool ZeroInitialization, - ConstructionKind ConstructKind, SourceRange ParenOrBraceRange); + CXXConstructionKind ConstructKind, SourceRange ParenOrBraceRange); /// Create an empty C++ construction expression. static CXXConstructExpr *CreateEmpty(const ASTContext &Ctx, unsigned NumArgs); @@ -1640,11 +1638,12 @@ class CXXConstructExpr : public Expr { /// Determine whether this constructor is actually constructing /// a base class (rather than a complete object). - ConstructionKind getConstructionKind() const { - return static_cast<ConstructionKind>(CXXConstructExprBits.ConstructionKind); + CXXConstructionKind getConstructionKind() const { + return static_cast<CXXConstructionKind>( + CXXConstructExprBits.ConstructionKind); } - void setConstructionKind(ConstructionKind CK) { - CXXConstructExprBits.ConstructionKind = CK; + void setConstructionKind(CXXConstructionKind CK) { + CXXConstructExprBits.ConstructionKind = llvm::to_underlying(CK); } using arg_iterator = ExprIterator; @@ -1761,9 +1760,9 @@ class CXXInheritedCtorInitExpr : public Expr { /// Determine whether this constructor is actually constructing /// a base class (rather than a complete object). bool constructsVBase() const { return ConstructsVirtualBase; } - CXXConstructExpr::ConstructionKind getConstructionKind() const { - return ConstructsVirtualBase ? CXXConstructExpr::CK_VirtualBase - : CXXConstructExpr::CK_NonVirtualBase; + CXXConstructionKind getConstructionKind() const { + return ConstructsVirtualBase ? CXXConstructionKind::VirtualBase + : CXXConstructionKind::NonVirtualBase; } /// Determine whether the inherited constructor is inherited from a diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 24f209e95736a67..831972495d38ff0 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -6323,36 +6323,30 @@ class Sema final { /// including handling of its default argument expressions. /// /// \param ConstructKind - a CXXConstructExpr::ConstructionKind - ExprResult - BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, - NamedDecl *FoundDecl, - CXXConstructorDecl *Constructor, MultiExprArg Exprs, - bool HadMultipleCandidates, bool IsListInitialization, - bool IsStdInitListInitialization, - bool RequiresZeroInit, unsigned ConstructKind, - SourceRange ParenRange); + ExprResult BuildCXXConstructExpr( + SourceLocation ConstructLoc, QualType DeclInitType, NamedDecl *FoundDecl, + CXXConstructorDecl *Constructor, MultiExprArg Exprs, + bool HadMultipleCandidates, bool IsListInitialization, + bool IsStdInitListInitialization, bool RequiresZeroInit, + CXXConstructionKind ConstructKind, SourceRange ParenRange); /// Build a CXXConstructExpr whose constructor has already been resolved if /// it denotes an inherited constructor. - ExprResult - BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, - CXXConstructorDecl *Constructor, bool Elidable, - MultiExprArg Exprs, - bool HadMultipleCandidates, bool IsListInitialization, - bool IsStdInitListInitialization, - bool RequiresZeroInit, unsigned ConstructKind, - SourceRange ParenRange); + ExprResult BuildCXXConstructExpr( + SourceLocation ConstructLoc, QualType DeclInitType, + CXXConstructorDecl *Constructor, bool Elidable, MultiExprArg Exprs, + bool HadMultipleCandidates, bool IsListInitialization, + bool IsStdInitListInitialization, bool RequiresZeroInit, + CXXConstructionKind ConstructKind, SourceRange ParenRange); // FIXME: Can we remove this and have the above BuildCXXConstructExpr check if // the constructor can be elidable? - ExprResult - BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, - NamedDecl *FoundDecl, - CXXConstructorDecl *Constructor, bool Elidable, - MultiExprArg Exprs, bool HadMultipleCandidates, - bool IsListInitialization, - bool IsStdInitListInitialization, bool RequiresZeroInit, - unsigned ConstructKind, SourceRange ParenRange); + ExprResult BuildCXXConstructExpr( + SourceLocation ConstructLoc, QualType DeclInitType, NamedDecl *FoundDecl, + CXXConstructorDecl *Constructor, bool Elidable, MultiExprArg Exprs, + bool HadMultipleCandidates, bool IsListInitialization, + bool IsStdInitListInitialization, bool RequiresZeroInit, + CXXConstructionKind ConstructKind, SourceRange ParenRange); ExprResult ConvertMemberDefaultInitExpression(FieldDecl *FD, Expr *InitExpr, SourceLocation InitLoc); diff --git a/clang/lib/AST/ExprCXX.cpp b/clang/lib/AST/ExprCXX.cpp index b9a004acc5ad06f..4d2e0e9a945a781 100644 --- a/clang/lib/AST/ExprCXX.cpp +++ b/clang/lib/AST/ExprCXX.cpp @@ -1063,7 +1063,7 @@ CXXTemporaryObjectExpr::CXXTemporaryObjectExpr( CXXTemporaryObjectExprClass, Ty, TSI->getTypeLoc().getBeginLoc(), Cons, /* Elidable=*/false, Args, HadMultipleCandidates, ListInitialization, StdInitListInitialization, ZeroInitialization, - CXXConstructExpr::CK_Complete, ParenOrBraceRange), + CXXConstructionKind::Complete, ParenOrBraceRange), TSI(TSI) { setDependence(computeDependence(this)); } @@ -1111,7 +1111,7 @@ CXXConstructExpr *CXXConstructExpr::Create( CXXConstructorDecl *Ctor, bool Elidable, ArrayRef<Expr *> Args, bool HadMultipleCandidates, bool ListInitialization, bool StdInitListInitialization, bool ZeroInitialization, - ConstructionKind ConstructKind, SourceRange ParenOrBraceRange) { + CXXConstructionKind ConstructKind, SourceRange ParenOrBraceRange) { unsigned SizeOfTrailingObjects = sizeOfTrailingObjects(Args.size()); void *Mem = Ctx.Allocate(sizeof(CXXConstructExpr) + SizeOfTrailingObjects, alignof(CXXConstructExpr)); @@ -1134,7 +1134,7 @@ CXXConstructExpr::CXXConstructExpr( StmtClass SC, QualType Ty, SourceLocation Loc, CXXConstructorDecl *Ctor, bool Elidable, ArrayRef<Expr *> Args, bool HadMultipleCandidates, bool ListInitialization, bool StdInitListInitialization, - bool ZeroInitialization, ConstructionKind ConstructKind, + bool ZeroInitialization, CXXConstructionKind ConstructKind, SourceRange ParenOrBraceRange) : Expr(SC, Ty, VK_PRValue, OK_Ordinary), Constructor(Ctor), ParenOrBraceRange(ParenOrBraceRange), NumArgs(Args.size()) { @@ -1143,7 +1143,7 @@ CXXConstructExpr::CXXConstructExpr( CXXConstructExprBits.ListInitialization = ListInitialization; CXXConstructExprBits.StdInitListInitialization = StdInitListInitialization; CXXConstructExprBits.ZeroInitialization = ZeroInitialization; - CXXConstructExprBits.ConstructionKind = ConstructKind; + CXXConstructExprBits.ConstructionKind = llvm::to_underlying(ConstructKind); CXXConstructExprBits.IsImmediateEscalating = false; CXXConstructExprBits.Loc = Loc; diff --git a/clang/lib/AST/JSONNodeDumper.cpp b/clang/lib/AST/JSONNodeDumper.cpp index dc82e05528d8f42..1a013b45c615d1b 100644 --- a/clang/lib/AST/JSONNodeDumper.cpp +++ b/clang/lib/AST/JSONNodeDumper.cpp @@ -1462,16 +1462,16 @@ void JSONNodeDumper::VisitCXXConstructExpr(const CXXConstructExpr *CE) { attributeOnlyIfTrue("isImmediateEscalating", CE->isImmediateEscalating()); switch (CE->getConstructionKind()) { - case CXXConstructExpr::CK_Complete: + case CXXConstructionKind::Complete: JOS.attribute("constructionKind", "complete"); break; - case CXXConstructExpr::CK_Delegating: + case CXXConstructionKind::Delegating: JOS.attribute("constructionKind", "delegating"); break; - case CXXConstructExpr::CK_NonVirtualBase: + case CXXConstructionKind::NonVirtualBase: JOS.attribute("constructionKind", "non-virtual base"); break; - case CXXConstructExpr::CK_VirtualBase: + case CXXConstructionKind::VirtualBase: JOS.attribute("constructionKind", "virtual base"); break; } diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp index 4bd8462ab5f8be6..98ae56e2df88184 100644 --- a/clang/lib/CodeGen/CGExprCXX.cpp +++ b/clang/lib/CodeGen/CGExprCXX.cpp @@ -600,12 +600,12 @@ CodeGenFunction::EmitCXXConstructExpr(const CXXConstructExpr *E, // already zeroed. if (E->requiresZeroInitialization() && !Dest.isZeroed()) { switch (E->getConstructionKind()) { - case CXXConstructExpr::CK_Delegating: - case CXXConstructExpr::CK_Complete: + case CXXConstructionKind::Delegating: + case CXXConstructionKind::Complete: EmitNullInitialization(Dest.getAddress(), E->getType()); break; - case CXXConstructExpr::CK_VirtualBase: - case CXXConstructExpr::CK_NonVirtualBase: + case CXXConstructionKind::VirtualBase: + case CXXConstructionKind::NonVirtualBase: EmitNullBaseClassInitialization(*this, Dest.getAddress(), CD->getParent()); break; @@ -641,21 +641,21 @@ CodeGenFunction::EmitCXXConstructExpr(const CXXConstructExpr *E, bool Delegating = false; switch (E->getConstructionKind()) { - case CXXConstructExpr::CK_Delegating: + case CXXConstructionKind::Delegating: // We should be emitting a constructor; GlobalDecl will assert this Type = CurGD.getCtorType(); Delegating = true; break; - case CXXConstructExpr::CK_Complete: + case CXXConstructionKind::Complete: Type = Ctor_Complete; break; - case CXXConstructExpr::CK_VirtualBase: + case CXXConstructionKind::VirtualBase: ForVirtualBase = true; [[fallthrough]]; - case CXXConstructExpr::CK_NonVirtualBase: + case CXXConstructionKind::NonVirtualBase: Type = Ctor_Base; } diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 397b7a00e453126..60786a880b9d3fd 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -15994,17 +15994,12 @@ static bool hasOneRealArgument(MultiExprArg Args) { return false; } -ExprResult -Sema::BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, - NamedDecl *FoundDecl, - CXXConstructorDecl *Constructor, - MultiExprArg ExprArgs, - bool HadMultipleCandidates, - bool IsListInitialization, - bool IsStdInitListInitialization, - bool RequiresZeroInit, - unsigned ConstructKind, - SourceRange ParenRange) { +ExprResult Sema::BuildCXXConstructExpr( + SourceLocation ConstructLoc, QualType DeclInitType, NamedDecl *FoundDecl, + CXXConstructorDecl *Constructor, MultiExprArg ExprArgs, + bool HadMultipleCandidates, bool IsListInitialization, + bool IsStdInitListInitialization, bool RequiresZeroInit, + CXXConstructionKind ConstructKind, SourceRange ParenRange) { bool Elidable = false; // C++0x [class.copy]p34: @@ -16017,7 +16012,7 @@ Sema::BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, // with the same cv-unqualified type, the copy/move operation // can be omitted by constructing the temporary object // directly into the target of the omitted copy/move - if (ConstructKind == CXXConstructExpr::CK_Complete && Constructor && + if (ConstructKind == CXXConstructionKind::Complete && Constructor && // FIXME: Converting constructors should also be accepted. // But to fix this, the logic that digs down into a CXXConstructExpr // to find the source object needs to handle it. @@ -16041,18 +16036,12 @@ Sema::BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, ConstructKind, ParenRange); } -ExprResult -Sema::BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, - NamedDecl *FoundDecl, - CXXConstructorDecl *Constructor, - bool Elidable, - MultiExprArg ExprArgs, - bool HadMultipleCandidates, - bool IsListInitialization, - bool IsStdInitListInitialization, - bool RequiresZeroInit, - unsigned ConstructKind, - SourceRange ParenRange) { +ExprResult Sema::BuildCXXConstructExpr( + SourceLocation ConstructLoc, QualType DeclInitType, NamedDecl *FoundDecl, + CXXConstructorDecl *Constructor, bool Elidable, MultiExprArg ExprArgs, + bool HadMultipleCandidates, bool IsListInitialization, + bool IsStdInitListInitialization, bool RequiresZeroInit, + CXXConstructionKind ConstructKind, SourceRange ParenRange) { if (auto *Shadow = dyn_cast<ConstructorUsingShadowDecl>(FoundDecl)) { Constructor = findInheritingConstructor(ConstructLoc, Constructor, Shadow); // The only way to get here is if we did overlaod resolution to find the @@ -16070,17 +16059,12 @@ Sema::BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, /// BuildCXXConstructExpr - Creates a complete call to a constructor, /// including handling of its default argument expressions. -ExprResult -Sema::BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, - CXXConstructorDecl *Constructor, - bool Elidable, - MultiExprArg ExprArgs, - bool HadMultipleCandidates, - bool IsListInitialization, - bool IsStdInitListInitialization, - bool RequiresZeroInit, - unsigned ConstructKind, - SourceRange ParenRange) { +ExprResult Sema::BuildCXXConstructExpr( + SourceLocation ConstructLoc, QualType DeclInitType, + CXXConstructorDecl *Constructor, bool Elidable, MultiExprArg ExprArgs, + bool HadMultipleCandidates, bool IsListInitialization, + bool IsStdInitListInitialization, bool RequiresZeroInit, + CXXConstructionKind ConstructKind, SourceRange ParenRange) { assert(declaresSameEntity( Constructor->getParent(), DeclInitType->getBaseElementTypeUnsafe()->getAsCXXRecordDecl()) && @@ -16094,8 +16078,7 @@ Sema::BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, Context, DeclInitType, ConstructLoc, Constructor, Elidable, ExprArgs, HadMultipleCandidates, IsListInitialization, IsStdInitListInitialization, RequiresZeroInit, - static_cast<CXXConstructExpr::ConstructionKind>(ConstructKind), - ParenRange), + static_cast<CXXConstructionKind>(ConstructKind), ParenRange), Constructor); } diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index db3be4816a211ba..25d7759cc168dd4 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -4157,7 +4157,7 @@ static ExprResult BuildCXXCastArgument(Sema &S, CastLoc, Ty, FoundDecl, cast<CXXConstructorDecl>(Method), ConstructorArgs, HadMultipleCandidates, /*ListInit*/ false, /*StdInitListInit*/ false, /*ZeroInit*/ false, - CXXConstructExpr::CK_Complete, SourceRange()); + CXXConstructionKind::Complete, SourceRange()); if (Result.isInvalid()) return ExprError(); @@ -4320,17 +4320,17 @@ Sema::PerformImplicitConversion(Expr *From, QualType ToType, return ExprError(); return BuildCXXConstructExpr( /*FIXME:ConstructLoc*/ SourceLocation(), ToType, - SCS.FoundCopyConstructor, SCS.CopyConstructor, - ConstructorArgs, /*HadMultipleCandidates*/ false, + SCS.FoundCopyConstructor, SCS.CopyConstructor, ConstructorArgs, + /*HadMultipleCandidates*/ false, /*ListInit*/ false, /*StdInitListInit*/ false, /*ZeroInit*/ false, - CXXConstructExpr::CK_Complete, SourceRange()); + CXXConstructionKind::Complete, SourceRange()); } return BuildCXXConstructExpr( /*FIXME:ConstructLoc*/ SourceLocation(), ToType, - SCS.FoundCopyConstructor, SCS.CopyConstructor, - From, /*HadMultipleCandidates*/ false, + SCS.FoundCopyConstructor, SCS.CopyConstructor, From, + /*HadMultipleCandidates*/ false, /*ListInit*/ false, /*StdInitListInit*/ false, /*ZeroInit*/ false, - CXXConstructExpr::CK_Complete, SourceRange()); + CXXConstructionKind::Complete, SourceRange()); } // Resolve overloaded function references. diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index 7bec15c895c7a8f..80b51b09bf5445f 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -6880,15 +6880,12 @@ static ExprResult CopyObject(Sema &S, CurInitExpr->getType()); // Actually perform the constructor call. - CurInit = S.BuildCXXConstructExpr(Loc, T, Best->FoundDecl, Constructor, - Elidable, - ConstructorArgs, - HadMultipleCandidates, - /*ListInit*/ false, - /*StdInitListInit*/ false, - /*ZeroInit*/ false, - CXXConstructExpr::CK_Complete, - SourceRange()); + CurInit = S.BuildCXXConstructExpr( + Loc, T, Best->FoundDecl, Constructor, Elidable, ConstructorArgs, + HadMultipleCandidates, + /*ListInit*/ false, + /*StdInitListInit*/ false, + /*ZeroInit*/ false, CXXConstructionKind::Complete, SourceRange()); // If we're supposed to bind temporaries, do so. if (!CurInit.isInvalid() && shouldBindAsTemporary(Entity)) @@ -7082,15 +7079,14 @@ PerformConstructorInitialization(Sema &S, ConstructorInitRequiresZeroInit), CalleeDecl); } else { - CXXConstructExpr::ConstructionKind ConstructKind = - CXXConstructExpr::CK_Complete; + CXXConstructionKind ConstructKind = CXXConstructionKind::Complete; if (Entity.getKind() == InitializedEntity::EK_Base) { - ConstructKind = Entity.getBaseSpecifier()->isVirtual() ? - CXXConstructExpr::CK_VirtualBase : - CXXConstructExpr::CK_NonVirtualBase; + ConstructKind = Entity.getBaseSpecifier()->isVirtual() + ? CXXConstructionKind::VirtualBase + : CXXConstructionKind::NonVirtualBase; } else if (Entity.getKind() == InitializedEntity::EK_Delegating) { - ConstructKind = CXXConstructExpr::CK_Delegating; + ConstructKind = CXXConstructionKind::Delegating; } // Only get the parenthesis or brace range if it is a list initialization or @@ -8871,15 +8867,12 @@ ExprResult InitializationSequence::Perform(Sema &S, return ExprError(); // Build an expression that constructs a temporary. - CurInit = S.BuildCXXConstructExpr(Loc, Step->Type, - FoundFn, Constructor, - ConstructorArgs, - HadMultipleCandidates, - /*ListInit*/ false, - /*StdInitListInit*/ false, - /*ZeroInit*/ false, - CXXConstructExpr::CK_Complete, - SourceRange()); + CurInit = S.BuildCXXConstructExpr( + Loc, Step->Type, FoundFn, Constructor, ConstructorArgs, + HadMultipleCandidates, + /*ListInit*/ false, + /*StdInitListInit*/ false, + /*ZeroInit*/ false, CXXConstructionKind::Complete, SourceRange()); if (CurInit.isInvalid()) return ExprError(); diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index 279bc29815980ec..e24f710fdedd4e2 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -3449,17 +3449,12 @@ class TreeTransform { /// /// By default, performs semantic analysis to build the new expression. /// Subclasses may override this routine to provide diff erent behavior. - ExprResult RebuildCXXConstructExpr(QualType T, - SourceLocation Loc, - CXXConstructorDecl *Constructor, - bool IsElidable, - MultiExprArg Args, - bool HadMultipleCandidates, - bool ListInitialization, - bool StdInitListInitialization, - bool RequiresZeroInit, - CXXConstructExpr::ConstructionKind ConstructKind, - SourceRange ParenRange) { + ExprResult RebuildCXXConstructExpr( + QualType T, SourceLocation Loc, CXXConstructorDecl *Constructor, + bool IsElidable, MultiExprArg Args, bool HadMultipleCandidates, + bool ListInitialization, bool StdInitListInitialization, + bool RequiresZeroInit, CXXConstructionKind ConstructKind, + SourceRange ParenRange) { // Reconstruct the constructor we originally found, which might be // diff erent if this is a call to an inherited constructor. CXXConstructorDecl *FoundCtor = Constructor; diff --git a/clang/lib/Serialization/ASTWriterStmt.cpp b/clang/lib/Serialization/ASTWriterStmt.cpp index 78b1df3748ad8ae..59be6828fafabf6 100644 --- a/clang/lib/Serialization/ASTWriterStmt.cpp +++ b/clang/lib/Serialization/ASTWriterStmt.cpp @@ -1602,7 +1602,8 @@ void ASTStmtWriter::VisitCXXConstructExpr(CXXConstructExpr *E) { Record.push_back(E->isListInitialization()); Record.push_back(E->isStdInitListInitialization()); Record.push_back(E->requiresZeroInitialization()); - Record.push_back(E->getConstructionKind()); // FIXME: stable encoding + Record.push_back( + llvm::to_underlying(E->getConstructionKind())); // FIXME: stable encoding Record.push_back(E->isImmediateEscalating()); Record.AddSourceLocation(E->getLocation()); Record.AddDeclRef(E->getConstructor()); diff --git a/clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp b/clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp index eda8302595ba4fb..034774a252b1180 100644 --- a/clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp @@ -268,12 +268,12 @@ void DynamicTypePropagation::checkPreCall(const CallEvent &Call, // a more-derived class. switch (Ctor->getOriginExpr()->getConstructionKind()) { - case CXXConstructExpr::CK_Complete: - case CXXConstructExpr::CK_Delegating: + case CXXConstructionKind::Complete: + case CXXConstructionKind::Delegating: // No additional type info necessary. return; - case CXXConstructExpr::CK_NonVirtualBase: - case CXXConstructExpr::CK_VirtualBase: + case CXXConstructionKind::NonVirtualBase: + case CXXConstructionKind::VirtualBase: if (const MemRegion *Target = Ctor->getCXXThisVal().getAsRegion()) recordFixedType(Target, Ctor->getDecl(), C); return; @@ -360,16 +360,16 @@ void DynamicTypePropagation::checkPostCall(const CallEvent &Call, if (const CXXConstructorCall *Ctor = dyn_cast<CXXConstructorCall>(&Call)) { // We may need to undo the effects of our pre-call check. switch (Ctor->getOriginExpr()->getConstructionKind()) { - case CXXConstructExpr::CK_Complete: - case CXXConstructExpr::CK_Delegating: + case CXXConstructionKind::Complete: + case CXXConstructionKind::Delegating: // No additional work necessary. // Note: This will leave behind the actual type of the object for // complete constructors, but arguably that's a good thing, since it // means the dynamic type info will be correct even for objects // constructed with operator new. return; - case CXXConstructExpr::CK_NonVirtualBase: - case CXXConstructExpr::CK_VirtualBase: + case CXXConstructionKind::NonVirtualBase: + case CXXConstructionKind::VirtualBase: if (const MemRegion *Target = Ctor->getCXXThisVal().getAsRegion()) { // We just finished a base constructor. Now we can use the subclass's // type when resolving virtual calls. diff --git a/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp b/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp index 386a34f6cd4aa22..d3499e7a917d34d 100644 --- a/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp +++ b/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp @@ -503,8 +503,8 @@ void CoreEngine::HandleVirtualBaseBranch(const CFGBlock *B, if (const auto *CallerCtor = dyn_cast_or_null<CXXConstructExpr>( LCtx->getStackFrame()->getCallSite())) { switch (CallerCtor->getConstructionKind()) { - case CXXConstructExpr::CK_NonVirtualBase: - case CXXConstructExpr::CK_VirtualBase: { + case CXXConstructionKind::NonVirtualBase: + case CXXConstructionKind::VirtualBase: { BlockEdge Loc(B, *B->succ_begin(), LCtx); HandleBlockEdge(Loc, Pred); return; diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp index 7ee7c1394a670a5..504fd7f05e0f99b 100644 --- a/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp +++ b/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp @@ -612,10 +612,10 @@ void ExprEngine::handleConstructor(const Expr *E, assert(C || getCurrentCFGElement().getAs<CFGStmt>()); const ConstructionContext *CC = C ? C->getConstructionContext() : nullptr; - const CXXConstructExpr::ConstructionKind CK = + const CXXConstructionKind CK = CE ? CE->getConstructionKind() : CIE->getConstructionKind(); switch (CK) { - case CXXConstructExpr::CK_Complete: { + case CXXConstructionKind::Complete: { // Inherited constructors are always base class constructors. assert(CE && !CIE && "A complete constructor is inherited?!"); @@ -666,21 +666,21 @@ void ExprEngine::handleConstructor(const Expr *E, CE, State, currBldrCtx, LCtx, CC, CallOpts, Idx); break; } - case CXXConstructExpr::CK_VirtualBase: { + case CXXConstructionKind::VirtualBase: { // Make sure we are not calling virtual base class initializers twice. // Only the most-derived object should initialize virtual base classes. const auto *OuterCtor = dyn_cast_or_null<CXXConstructExpr>( LCtx->getStackFrame()->getCallSite()); assert( (!OuterCtor || - OuterCtor->getConstructionKind() == CXXConstructExpr::CK_Complete || - OuterCtor->getConstructionKind() == CXXConstructExpr::CK_Delegating) && + OuterCtor->getConstructionKind() == CXXConstructionKind::Complete || + OuterCtor->getConstructionKind() == CXXConstructionKind::Delegating) && ("This virtual base should have already been initialized by " "the most derived class!")); (void)OuterCtor; [[fallthrough]]; } - case CXXConstructExpr::CK_NonVirtualBase: + case CXXConstructionKind::NonVirtualBase: // In C++17, classes with non-virtual bases may be aggregates, so they would // be initialized as aggregates without a constructor call, so we may have // a base class constructed directly into an initializer list without @@ -699,17 +699,17 @@ void ExprEngine::handleConstructor(const Expr *E, break; } [[fallthrough]]; - case CXXConstructExpr::CK_Delegating: { + case CXXConstructionKind::Delegating: { const CXXMethodDecl *CurCtor = cast<CXXMethodDecl>(LCtx->getDecl()); Loc ThisPtr = getSValBuilder().getCXXThis(CurCtor, LCtx->getStackFrame()); SVal ThisVal = State->getSVal(ThisPtr); - if (CK == CXXConstructExpr::CK_Delegating) { + if (CK == CXXConstructionKind::Delegating) { Target = ThisVal; } else { // Cast to the base type. - bool IsVirtual = (CK == CXXConstructExpr::CK_VirtualBase); + bool IsVirtual = (CK == CXXConstructionKind::VirtualBase); SVal BaseVal = getStoreManager().evalDerivedToBase(ThisVal, E->getType(), IsVirtual); Target = BaseVal; diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp index b987ce27893652c..4755b6bfa6dc0ab 100644 --- a/clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp +++ b/clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp @@ -888,7 +888,7 @@ ExprEngine::mayInlineCallKind(const CallEvent &Call, const ExplodedNode *Pred, if (!Opts.mayInlineCXXMemberFunction(CIMK_Destructors)) return CIP_DisallowedAlways; - if (CtorExpr->getConstructionKind() == CXXConstructExpr::CK_Complete) { + if (CtorExpr->getConstructionKind() == CXXConstructionKind::Complete) { // If we don't handle temporary destructors, we shouldn't inline // their constructors. if (CallOpts.IsTemporaryCtorOrDtor && diff --git a/clang/www/analyzer/open_projects.html b/clang/www/analyzer/open_projects.html index 8f8c36997291d93..8e06ce2cb528845 100644 --- a/clang/www/analyzer/open_projects.html +++ b/clang/www/analyzer/open_projects.html @@ -83,7 +83,7 @@ <h1>Open Projects</h1> One can start untangling this problem by trying to replace the current ad-hoc <code><a href="https://clang.llvm.org/doxygen/classclang_1_1ParentMap.html"> ParentMap</a></code> lookup in <a href="https://clang.llvm.org/doxygen/ExprEngineCXX_8cpp_source.html#l00430"> - <code>CXXConstructExpr::CK_NonVirtualBase</code></a> branch of + <code>CXXConstructionKind::NonVirtualBase</code></a> branch of <code>ExprEngine::VisitCXXConstructExpr()</code> with proper support for the feature. <p><i>(Difficulty: Medium) </i></p></p> _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits