From: Benjamin Kramer Date: Thu, 16 Apr 2020 09:45:02 +0000 (+0200) Subject: LangOptions cannot depend on ASTContext, make it not use ASTContext directly X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3ee1ec0b9dd6ee2350f39ae8a418bf3ce28d06cf;p=platform%2Fupstream%2Fllvm.git LangOptions cannot depend on ASTContext, make it not use ASTContext directly Fixes a layering violation introduced in 2ba4e3a4598b165245c581c506a813cd4a7dce33. --- diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h index 1fdfe92..fab84f6 100644 --- a/clang/include/clang/AST/Expr.h +++ b/clang/include/clang/AST/Expr.h @@ -3494,19 +3494,7 @@ protected: /// allocated for the trailing objects when needed. BinaryOperator(const ASTContext &Ctx, Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, ExprValueKind VK, ExprObjectKind OK, - SourceLocation opLoc, FPOptions FPFeatures) - : Expr(BinaryOperatorClass, ResTy, VK, OK) { - BinaryOperatorBits.Opc = opc; - assert(!isCompoundAssignmentOp() && - "Use CompoundAssignOperator for compound assignments"); - BinaryOperatorBits.OpLoc = opLoc; - SubExprs[LHS] = lhs; - SubExprs[RHS] = rhs; - BinaryOperatorBits.HasFPFeatures = FPFeatures.requiresTrailingStorage(Ctx); - if (BinaryOperatorBits.HasFPFeatures) - *getTrailingFPFeatures() = FPFeatures; - setDependence(computeDependence(this)); - } + SourceLocation opLoc, FPOptions FPFeatures); /// Construct an empty binary operator. explicit BinaryOperator(EmptyShell Empty) : Expr(BinaryOperatorClass, Empty) { @@ -3678,40 +3666,28 @@ public: // Get the FP features status of this operator. Only meaningful for // operations on floating point types. - FPOptions getFPFeatures(const ASTContext &C) const { + FPOptions getFPFeatures(const LangOptions &LO) const { if (BinaryOperatorBits.HasFPFeatures) return getStoredFPFeatures(); - return FPOptions::defaultWithoutTrailingStorage(C); + return FPOptions::defaultWithoutTrailingStorage(LO); } // Get the FP contractability status of this operator. Only meaningful for // operations on floating point types. - bool isFPContractableWithinStatement(const ASTContext &C) const { - return getFPFeatures(C).allowFPContractWithinStatement(); + bool isFPContractableWithinStatement(const LangOptions &LO) const { + return getFPFeatures(LO).allowFPContractWithinStatement(); } // Get the FENV_ACCESS status of this operator. Only meaningful for // operations on floating point types. - bool isFEnvAccessOn(const ASTContext &C) const { - return getFPFeatures(C).allowFEnvAccess(); + bool isFEnvAccessOn(const LangOptions &LO) const { + return getFPFeatures(LO).allowFEnvAccess(); } protected: BinaryOperator(const ASTContext &Ctx, Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, ExprValueKind VK, ExprObjectKind OK, - SourceLocation opLoc, FPOptions FPFeatures, bool dead2) - : Expr(CompoundAssignOperatorClass, ResTy, VK, OK) { - BinaryOperatorBits.Opc = opc; - assert(isCompoundAssignmentOp() && - "Use CompoundAssignOperator for compound assignments"); - BinaryOperatorBits.OpLoc = opLoc; - SubExprs[LHS] = lhs; - SubExprs[RHS] = rhs; - BinaryOperatorBits.HasFPFeatures = FPFeatures.requiresTrailingStorage(Ctx); - if (BinaryOperatorBits.HasFPFeatures) - *getTrailingFPFeatures() = FPFeatures; - setDependence(computeDependence(this)); - } + SourceLocation opLoc, FPOptions FPFeatures, bool dead2); /// Construct an empty BinaryOperator, SC is CompoundAssignOperator. BinaryOperator(StmtClass SC, EmptyShell Empty) : Expr(SC, Empty) { diff --git a/clang/include/clang/Basic/LangOptions.h b/clang/include/clang/Basic/LangOptions.h index c33f8bf..76ddd70 100644 --- a/clang/include/clang/Basic/LangOptions.h +++ b/clang/include/clang/Basic/LangOptions.h @@ -27,8 +27,6 @@ namespace clang { -class ASTContext; - /// Bitfields of LangOptions, split out from LangOptions in order to ensure that /// this large collection of bitfields is a trivial class type. class LangOptionsBase { @@ -403,11 +401,11 @@ public: /// Return the default value of FPOptions that's used when trailing /// storage isn't required. - static FPOptions defaultWithoutTrailingStorage(const ASTContext &C); + static FPOptions defaultWithoutTrailingStorage(const LangOptions &LO); /// Does this FPOptions require trailing storage when stored in various /// AST nodes, or can it be recreated using `defaultWithoutTrailingStorage`? - bool requiresTrailingStorage(const ASTContext &C); + bool requiresTrailingStorage(const LangOptions &LO); bool allowFPContractWithinStatement() const { return fp_contract == LangOptions::FPC_On; diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index e303701..5cdf1de 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -6703,10 +6703,10 @@ ExpectedStmt ASTNodeImporter::VisitBinaryOperator(BinaryOperator *E) { if (Err) return std::move(Err); - return BinaryOperator::Create(Importer.getToContext(), ToLHS, ToRHS, - E->getOpcode(), ToType, E->getValueKind(), - E->getObjectKind(), ToOperatorLoc, - E->getFPFeatures(Importer.getFromContext())); + return BinaryOperator::Create( + Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType, + E->getValueKind(), E->getObjectKind(), ToOperatorLoc, + E->getFPFeatures(Importer.getFromContext().getLangOpts())); } ExpectedStmt ASTNodeImporter::VisitConditionalOperator(ConditionalOperator *E) { @@ -6817,7 +6817,7 @@ ASTNodeImporter::VisitCompoundAssignOperator(CompoundAssignOperator *E) { return CompoundAssignOperator::Create( Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType, E->getValueKind(), E->getObjectKind(), ToOperatorLoc, - E->getFPFeatures(Importer.getFromContext()), + E->getFPFeatures(Importer.getFromContext().getLangOpts()), importChecked(Err, ToComputationLHSType), importChecked(Err, ToComputationResultType)); } diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index a5c634e..bc6fadc 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -4347,6 +4347,42 @@ ParenListExpr *ParenListExpr::CreateEmpty(const ASTContext &Ctx, return new (Mem) ParenListExpr(EmptyShell(), NumExprs); } +BinaryOperator::BinaryOperator(const ASTContext &Ctx, Expr *lhs, Expr *rhs, + Opcode opc, QualType ResTy, ExprValueKind VK, + ExprObjectKind OK, SourceLocation opLoc, + FPOptions FPFeatures) + : Expr(BinaryOperatorClass, ResTy, VK, OK) { + BinaryOperatorBits.Opc = opc; + assert(!isCompoundAssignmentOp() && + "Use CompoundAssignOperator for compound assignments"); + BinaryOperatorBits.OpLoc = opLoc; + SubExprs[LHS] = lhs; + SubExprs[RHS] = rhs; + BinaryOperatorBits.HasFPFeatures = + FPFeatures.requiresTrailingStorage(Ctx.getLangOpts()); + if (BinaryOperatorBits.HasFPFeatures) + *getTrailingFPFeatures() = FPFeatures; + setDependence(computeDependence(this)); +} + +BinaryOperator::BinaryOperator(const ASTContext &Ctx, Expr *lhs, Expr *rhs, + Opcode opc, QualType ResTy, ExprValueKind VK, + ExprObjectKind OK, SourceLocation opLoc, + FPOptions FPFeatures, bool dead2) + : Expr(CompoundAssignOperatorClass, ResTy, VK, OK) { + BinaryOperatorBits.Opc = opc; + assert(isCompoundAssignmentOp() && + "Use CompoundAssignOperator for compound assignments"); + BinaryOperatorBits.OpLoc = opLoc; + SubExprs[LHS] = lhs; + SubExprs[RHS] = rhs; + BinaryOperatorBits.HasFPFeatures = + FPFeatures.requiresTrailingStorage(Ctx.getLangOpts()); + if (BinaryOperatorBits.HasFPFeatures) + *getTrailingFPFeatures() = FPFeatures; + setDependence(computeDependence(this)); +} + BinaryOperator *BinaryOperator::CreateEmpty(const ASTContext &C, bool HasFPFeatures) { unsigned Extra = sizeOfTrailingObjects(HasFPFeatures); @@ -4360,7 +4396,7 @@ BinaryOperator *BinaryOperator::Create(const ASTContext &C, Expr *lhs, ExprValueKind VK, ExprObjectKind OK, SourceLocation opLoc, FPOptions FPFeatures) { - bool HasFPFeatures = FPFeatures.requiresTrailingStorage(C); + bool HasFPFeatures = FPFeatures.requiresTrailingStorage(C.getLangOpts()); unsigned Extra = sizeOfTrailingObjects(HasFPFeatures); void *Mem = C.Allocate(sizeof(BinaryOperator) + Extra, alignof(BinaryOperator)); @@ -4380,7 +4416,7 @@ CompoundAssignOperator *CompoundAssignOperator::Create( const ASTContext &C, Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, ExprValueKind VK, ExprObjectKind OK, SourceLocation opLoc, FPOptions FPFeatures, QualType CompLHSType, QualType CompResultType) { - bool HasFPFeatures = FPFeatures.requiresTrailingStorage(C); + bool HasFPFeatures = FPFeatures.requiresTrailingStorage(C.getLangOpts()); unsigned Extra = sizeOfTrailingObjects(HasFPFeatures); void *Mem = C.Allocate(sizeof(CompoundAssignOperator) + Extra, alignof(CompoundAssignOperator)); diff --git a/clang/lib/Basic/LangOptions.cpp b/clang/lib/Basic/LangOptions.cpp index 6e12bda..a74efdc 100644 --- a/clang/lib/Basic/LangOptions.cpp +++ b/clang/lib/Basic/LangOptions.cpp @@ -11,7 +11,6 @@ //===----------------------------------------------------------------------===// #include "clang/Basic/LangOptions.h" -#include "clang/AST/ASTContext.h" using namespace clang; @@ -49,11 +48,11 @@ VersionTuple LangOptions::getOpenCLVersionTuple() const { return VersionTuple(Ver / 100, (Ver % 100) / 10); } -FPOptions FPOptions::defaultWithoutTrailingStorage(const ASTContext &C) { - FPOptions result(C.getLangOpts()); +FPOptions FPOptions::defaultWithoutTrailingStorage(const LangOptions &LO) { + FPOptions result(LO); return result; } -bool FPOptions::requiresTrailingStorage(const ASTContext &C) { - return getAsOpaqueInt() != defaultWithoutTrailingStorage(C).getAsOpaqueInt(); +bool FPOptions::requiresTrailingStorage(const LangOptions &LO) { + return getAsOpaqueInt() != defaultWithoutTrailingStorage(LO).getAsOpaqueInt(); } diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index 75be18e..97e9694 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -2929,7 +2929,7 @@ BinOpInfo ScalarExprEmitter::EmitBinOps(const BinaryOperator *E) { Result.RHS = Visit(E->getRHS()); Result.Ty = E->getType(); Result.Opcode = E->getOpcode(); - Result.FPFeatures = E->getFPFeatures(CGF.getContext()); + Result.FPFeatures = E->getFPFeatures(CGF.getLangOpts()); Result.E = E; return Result; } @@ -2949,7 +2949,7 @@ LValue ScalarExprEmitter::EmitCompoundAssignLValue( OpInfo.RHS = Visit(E->getRHS()); OpInfo.Ty = E->getComputationResultType(); OpInfo.Opcode = E->getOpcode(); - OpInfo.FPFeatures = E->getFPFeatures(CGF.getContext()); + OpInfo.FPFeatures = E->getFPFeatures(CGF.getLangOpts()); OpInfo.E = E; // Load/convert the LHS. LValue LHSLV = EmitCheckedLValue(E->getLHS(), CodeGenFunction::TCK_Store); diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index 1fe1515..0761f02 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -6994,7 +6994,7 @@ ExprResult Sema::ActOnDecltypeExpression(Expr *E) { return BinaryOperator::Create(Context, BO->getLHS(), RHS.get(), BO_Comma, BO->getType(), BO->getValueKind(), BO->getObjectKind(), BO->getOperatorLoc(), - BO->getFPFeatures(getASTContext())); + BO->getFPFeatures(getLangOpts())); } } diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index de7892f..e79969e 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -10267,7 +10267,7 @@ TreeTransform::TransformBinaryOperator(BinaryOperator *E) { return getDerived().RebuildBinaryOperator( E->getOperatorLoc(), E->getOpcode(), LHS.get(), RHS.get()); Sema::FPFeaturesStateRAII FPFeaturesState(getSema()); - getSema().FPFeatures = E->getFPFeatures(getSema().getASTContext()); + getSema().FPFeatures = E->getFPFeatures(getSema().getLangOpts()); return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), LHS.get(), RHS.get()); @@ -10322,7 +10322,7 @@ ExprResult TreeTransform::TransformCompoundAssignOperator( CompoundAssignOperator *E) { Sema::FPFeaturesStateRAII FPFeaturesState(getSema()); - getSema().FPFeatures = E->getFPFeatures(getSema().getASTContext()); + getSema().FPFeatures = E->getFPFeatures(getSema().getLangOpts()); return getDerived().TransformBinaryOperator(E); }