[clang] 3ee1ec0 - LangOptions cannot depend on ASTContext, make it not use ASTContext directly
Benjamin Kramer via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 16 02:46:51 PDT 2020
Author: Benjamin Kramer
Date: 2020-04-16T11:46:35+02:00
New Revision: 3ee1ec0b9dd6ee2350f39ae8a418bf3ce28d06cf
URL: https://github.com/llvm/llvm-project/commit/3ee1ec0b9dd6ee2350f39ae8a418bf3ce28d06cf
DIFF: https://github.com/llvm/llvm-project/commit/3ee1ec0b9dd6ee2350f39ae8a418bf3ce28d06cf.diff
LOG: LangOptions cannot depend on ASTContext, make it not use ASTContext directly
Fixes a layering violation introduced in 2ba4e3a4598b165245c581c506a813cd4a7dce33.
Added:
Modified:
clang/include/clang/AST/Expr.h
clang/include/clang/Basic/LangOptions.h
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/Expr.cpp
clang/lib/Basic/LangOptions.cpp
clang/lib/CodeGen/CGExprScalar.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/TreeTransform.h
Removed:
################################################################################
diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 1fdfe926eb71..fab84f6a6ecd 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -3494,19 +3494,7 @@ class BinaryOperator : public Expr {
/// 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 @@ class BinaryOperator : public Expr {
// 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 c33f8bf8c8ef..76ddd7051fd3 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 @@ class FPOptions {
/// 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 e303701cf5d3..5cdf1de4c96a 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 a5c634e298de..bc6fadc71609 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 6e12bda65a42..a74efdc460bf 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 75be18e23e2f..97e96941ec2f 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 1fe1515bed10..0761f02066fe 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 de7892f64257..e79969e9a87a 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -10267,7 +10267,7 @@ TreeTransform<Derived>::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<Derived>::TransformCompoundAssignOperator(
CompoundAssignOperator *E) {
Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
- getSema().FPFeatures = E->getFPFeatures(getSema().getASTContext());
+ getSema().FPFeatures = E->getFPFeatures(getSema().getLangOpts());
return getDerived().TransformBinaryOperator(E);
}
More information about the cfe-commits
mailing list