Reland D81869 "Modify FPFeatures to use delta not absolute settings"
This reverts commit defd43a5b393bb63a902042adf578081b03b171d.
with correction to solve msan report
To solve https://bugs.llvm.org/show_bug.cgi?id=46166 where the
floating point settings in PCH files aren't compatible, rewrite
FPFeatures to use a delta in the settings rather than absolute settings.
With this patch, these floating point options can be benign.
Reviewers: rjmccall
Differential Revision: https://reviews.llvm.org/D81869
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp
index f48f718..1bbfc27 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -2389,7 +2389,7 @@
if (!E->canOverflow())
return Builder.CreateNSWAdd(InVal, Amount, Name);
return EmitOverflowCheckedBinOp(createBinOpInfoFromIncDec(
- E, InVal, IsInc, E->getFPFeatures(CGF.getLangOpts())));
+ E, InVal, IsInc, E->getFPFeaturesInEffect(CGF.getLangOpts())));
}
llvm_unreachable("Unknown SignedOverflowBehaviorTy");
}
@@ -2536,7 +2536,7 @@
} else if (E->canOverflow() && type->isUnsignedIntegerType() &&
CGF.SanOpts.has(SanitizerKind::UnsignedIntegerOverflow)) {
value = EmitOverflowCheckedBinOp(createBinOpInfoFromIncDec(
- E, value, isInc, E->getFPFeatures(CGF.getLangOpts())));
+ E, value, isInc, E->getFPFeaturesInEffect(CGF.getLangOpts())));
} else {
llvm::Value *amt = llvm::ConstantInt::get(value->getType(), amount, true);
value = Builder.CreateAdd(value, amt, isInc ? "inc" : "dec");
@@ -2736,7 +2736,7 @@
BinOp.LHS = llvm::Constant::getNullValue(BinOp.RHS->getType());
BinOp.Ty = E->getType();
BinOp.Opcode = BO_Sub;
- BinOp.FPFeatures = E->getFPFeatures(CGF.getLangOpts());
+ BinOp.FPFeatures = E->getFPFeaturesInEffect(CGF.getLangOpts());
BinOp.E = E;
return EmitSub(BinOp);
}
@@ -2757,7 +2757,7 @@
Value *Result;
if (Oper->getType()->isFPOrFPVectorTy()) {
CodeGenFunction::CGFPOptionsRAII FPOptsRAII(
- CGF, E->getFPFeatures(CGF.getLangOpts()));
+ CGF, E->getFPFeaturesInEffect(CGF.getLangOpts()));
Result = Builder.CreateFCmp(llvm::CmpInst::FCMP_OEQ, Oper, Zero, "cmp");
} else
Result = Builder.CreateICmp(llvm::CmpInst::ICMP_EQ, Oper, Zero, "cmp");
@@ -2960,7 +2960,7 @@
Result.RHS = Visit(E->getRHS());
Result.Ty = E->getType();
Result.Opcode = E->getOpcode();
- Result.FPFeatures = E->getFPFeatures(CGF.getLangOpts());
+ Result.FPFeatures = E->getFPFeaturesInEffect(CGF.getLangOpts());
Result.E = E;
return Result;
}
@@ -2980,7 +2980,7 @@
OpInfo.RHS = Visit(E->getRHS());
OpInfo.Ty = E->getComputationResultType();
OpInfo.Opcode = E->getOpcode();
- OpInfo.FPFeatures = E->getFPFeatures(CGF.getLangOpts());
+ OpInfo.FPFeatures = E->getFPFeaturesInEffect(CGF.getLangOpts());
OpInfo.E = E;
// Load/convert the LHS.
LValue LHSLV = EmitCheckedLValue(E->getLHS(), CodeGenFunction::TCK_Store);
@@ -4214,7 +4214,7 @@
Value *Zero = llvm::ConstantAggregateZero::get(LHS->getType());
if (LHS->getType()->isFPOrFPVectorTy()) {
CodeGenFunction::CGFPOptionsRAII FPOptsRAII(
- CGF, E->getFPFeatures(CGF.getLangOpts()));
+ CGF, E->getFPFeaturesInEffect(CGF.getLangOpts()));
LHS = Builder.CreateFCmp(llvm::CmpInst::FCMP_UNE, LHS, Zero, "cmp");
RHS = Builder.CreateFCmp(llvm::CmpInst::FCMP_UNE, RHS, Zero, "cmp");
} else {
@@ -4300,7 +4300,7 @@
Value *Zero = llvm::ConstantAggregateZero::get(LHS->getType());
if (LHS->getType()->isFPOrFPVectorTy()) {
CodeGenFunction::CGFPOptionsRAII FPOptsRAII(
- CGF, E->getFPFeatures(CGF.getLangOpts()));
+ CGF, E->getFPFeaturesInEffect(CGF.getLangOpts()));
LHS = Builder.CreateFCmp(llvm::CmpInst::FCMP_UNE, LHS, Zero, "cmp");
RHS = Builder.CreateFCmp(llvm::CmpInst::FCMP_UNE, RHS, Zero, "cmp");
} else {
diff --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp
index 4c5311c..158a548 100644
--- a/clang/lib/CodeGen/CGObjC.cpp
+++ b/clang/lib/CodeGen/CGObjC.cpp
@@ -1493,8 +1493,7 @@
BinaryOperator *assign = BinaryOperator::Create(
getContext(), &ivarRef, finalArg, BO_Assign, ivarRef.getType(), VK_RValue,
- OK_Ordinary, SourceLocation(),
- FPOptions(getContext().getLangOpts()));
+ OK_Ordinary, SourceLocation(), FPOptionsOverride());
EmitStmt(assign);
}
@@ -3556,18 +3555,18 @@
DeclRefExpr DstExpr(C, &DstDecl, false, DestTy, VK_RValue, SourceLocation());
UnaryOperator *DST = UnaryOperator::Create(
C, &DstExpr, UO_Deref, DestTy->getPointeeType(), VK_LValue, OK_Ordinary,
- SourceLocation(), false, FPOptions(C.getLangOpts()));
+ SourceLocation(), false, FPOptionsOverride());
DeclRefExpr SrcExpr(C, &SrcDecl, false, SrcTy, VK_RValue, SourceLocation());
UnaryOperator *SRC = UnaryOperator::Create(
C, &SrcExpr, UO_Deref, SrcTy->getPointeeType(), VK_LValue, OK_Ordinary,
- SourceLocation(), false, FPOptions(C.getLangOpts()));
+ SourceLocation(), false, FPOptionsOverride());
Expr *Args[2] = {DST, SRC};
CallExpr *CalleeExp = cast<CallExpr>(PID->getSetterCXXAssignment());
CXXOperatorCallExpr *TheCall = CXXOperatorCallExpr::Create(
C, OO_Equal, CalleeExp->getCallee(), Args, DestTy->getPointeeType(),
- VK_LValue, SourceLocation(), FPOptions(C.getLangOpts()));
+ VK_LValue, SourceLocation(), FPOptionsOverride());
EmitStmt(TheCall);
@@ -3641,7 +3640,7 @@
UnaryOperator *SRC = UnaryOperator::Create(
C, &SrcExpr, UO_Deref, SrcTy->getPointeeType(), VK_LValue, OK_Ordinary,
- SourceLocation(), false, FPOptions(C.getLangOpts()));
+ SourceLocation(), false, FPOptionsOverride());
CXXConstructExpr *CXXConstExpr =
cast<CXXConstructExpr>(PID->getGetterCXXConstructor());
diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp
index b380143..7904d4a 100644
--- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -3328,11 +3328,11 @@
// Generate condition for loop.
BinaryOperator *Cond = BinaryOperator::Create(
C, &IVRefExpr, &UBRefExpr, BO_LE, C.BoolTy, VK_RValue, OK_Ordinary,
- S.getBeginLoc(), FPOptions(C.getLangOpts()));
+ S.getBeginLoc(), FPOptionsOverride());
// Increment for loop counter.
UnaryOperator *Inc = UnaryOperator::Create(
C, &IVRefExpr, UO_PreInc, KmpInt32Ty, VK_RValue, OK_Ordinary,
- S.getBeginLoc(), true, FPOptions(C.getLangOpts()));
+ S.getBeginLoc(), true, FPOptionsOverride());
auto &&BodyGen = [CapturedStmt, CS, &S, &IV](CodeGenFunction &CGF) {
// Iterate through all sections and emit a switch construct:
// switch (IV) {
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp
index 23208b2..cfd32d1 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -117,12 +117,12 @@
void CodeGenFunction::SetFastMathFlags(FPOptions FPFeatures) {
llvm::FastMathFlags FMF;
- FMF.setAllowReassoc(FPFeatures.allowAssociativeMath());
- FMF.setNoNaNs(FPFeatures.noHonorNaNs());
- FMF.setNoInfs(FPFeatures.noHonorInfs());
- FMF.setNoSignedZeros(FPFeatures.noSignedZeros());
- FMF.setAllowReciprocal(FPFeatures.allowReciprocalMath());
- FMF.setApproxFunc(FPFeatures.allowApproximateFunctions());
+ FMF.setAllowReassoc(FPFeatures.getAllowFPReassociate());
+ FMF.setNoNaNs(FPFeatures.getNoHonorNaNs());
+ FMF.setNoInfs(FPFeatures.getNoHonorInfs());
+ FMF.setNoSignedZeros(FPFeatures.getNoSignedZero());
+ FMF.setAllowReciprocal(FPFeatures.getAllowReciprocal());
+ FMF.setApproxFunc(FPFeatures.getAllowApproxFunc());
FMF.setAllowContract(FPFeatures.allowFPContractAcrossStatement());
Builder.setFastMathFlags(FMF);
}
@@ -137,10 +137,12 @@
FMFGuard.emplace(CGF.Builder);
- auto NewRoundingBehavior = FPFeatures.getRoundingMode();
+ llvm::RoundingMode NewRoundingBehavior =
+ static_cast<llvm::RoundingMode>(FPFeatures.getRoundingMode());
CGF.Builder.setDefaultConstrainedRounding(NewRoundingBehavior);
auto NewExceptionBehavior =
- ToConstrainedExceptMD(FPFeatures.getExceptionMode());
+ ToConstrainedExceptMD(static_cast<LangOptions::FPExceptionModeKind>(
+ FPFeatures.getFPExceptionMode()));
CGF.Builder.setDefaultConstrainedExcept(NewExceptionBehavior);
CGF.SetFastMathFlags(FPFeatures);
@@ -159,13 +161,13 @@
if (OldValue != NewValue)
CGF.CurFn->addFnAttr(Name, llvm::toStringRef(NewValue));
};
- mergeFnAttrValue("no-infs-fp-math", FPFeatures.noHonorInfs());
- mergeFnAttrValue("no-nans-fp-math", FPFeatures.noHonorNaNs());
- mergeFnAttrValue("no-signed-zeros-fp-math", FPFeatures.noSignedZeros());
- mergeFnAttrValue(
- "unsafe-fp-math",
- FPFeatures.allowAssociativeMath() && FPFeatures.allowReciprocalMath() &&
- FPFeatures.allowApproximateFunctions() && FPFeatures.noSignedZeros());
+ mergeFnAttrValue("no-infs-fp-math", FPFeatures.getNoHonorInfs());
+ mergeFnAttrValue("no-nans-fp-math", FPFeatures.getNoHonorNaNs());
+ mergeFnAttrValue("no-signed-zeros-fp-math", FPFeatures.getNoSignedZero());
+ mergeFnAttrValue("unsafe-fp-math", FPFeatures.getAllowFPReassociate() &&
+ FPFeatures.getAllowReciprocal() &&
+ FPFeatures.getAllowApproxFunc() &&
+ FPFeatures.getNoSignedZero());
}
CodeGenFunction::CGFPOptionsRAII::~CGFPOptionsRAII() {