[PATCH] D88664: [AST] do not error on APFloat invalidOp in default mode

Sanjay Patel via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 1 08:39:00 PDT 2020


spatel created this revision.
spatel added reviewers: rjmccall, efriedma, sepavloff.
Herald added a subscriber: mcrosier.
spatel requested review of this revision.

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 <https://reviews.llvm.org/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);


https://reviews.llvm.org/D88664

Files:
  clang/lib/AST/ExprConstant.cpp


Index: clang/lib/AST/ExprConstant.cpp
===================================================================
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -2439,7 +2439,8 @@
     return false;
   }
 
-  if (St & APFloat::opStatus::opInvalidOp) {
+  if ((St & APFloat::opStatus::opInvalidOp) &&
+      FPO.getFPExceptionMode() != LangOptions::FPE_Ignore) {
     // There is no usefully definable result.
     Info.FFDiag(E);
     return false;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88664.295575.patch
Type: text/x-patch
Size: 467 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201001/d7606da3/attachment.bin>


More information about the cfe-commits mailing list