Skip to content

Commit 686eb0d

Browse files
committed
[AST] do not error on APFloat invalidOp in default mode
If FP exceptions are ignored, we should not error out of compilation just because APFloat indicated an exception. This is required as a preliminary step for D88238 which changes APFloat behavior for signaling NaN convert() to set the opInvalidOp exception status. Currently, there is no way to trigger this error because convert() never sets opInvalidOp. FP binops that set opInvalidOp also create a NaN, so the path to checkFloatingPointResult() is blocked by a different diagnostic: // [expr.pre]p4: // If during the evaluation of an expression, the result is not // mathematically defined [...], the behavior is undefined. // FIXME: C++ rules require us to not conform to IEEE 754 here. if (LHS.isNaN()) { Info.CCEDiag(E, diag::note_constexpr_float_arithmetic) << LHS.isNaN(); return Info.noteUndefinedBehavior(); } return checkFloatingPointResult(Info, E, St); Differential Revision: https://reviews.llvm.org/D88664
1 parent 114e964 commit 686eb0d

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

clang/lib/AST/ExprConstant.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2439,7 +2439,8 @@ static bool checkFloatingPointResult(EvalInfo &Info, const Expr *E,
24392439
return false;
24402440
}
24412441

2442-
if (St & APFloat::opStatus::opInvalidOp) {
2442+
if ((St & APFloat::opStatus::opInvalidOp) &&
2443+
FPO.getFPExceptionMode() != LangOptions::FPE_Ignore) {
24432444
// There is no usefully definable result.
24442445
Info.FFDiag(E);
24452446
return false;

0 commit comments

Comments
 (0)