[PATCH] D87822: [FPEnv] Evaluate constant expressions under non-default rounding modes

John McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 17 22:56:17 PDT 2020


rjmccall added inline comments.


================
Comment at: clang/lib/AST/ExprConstant.cpp:2427
+    FPOptions FPFeatures = Cast->getFPFeaturesInEffect(Info.Ctx.getLangOpts());
+    RM = FPFeatures.getRoundingMode();
+  }
----------------
I think the options really need to be passed in or else correctness is somewhat doomed here.

For example, the call to CompoundAssignSubobjectHandler needs to propagate this down from the operator expression.


================
Comment at: clang/lib/AST/ExprConstant.cpp:2678
+    // operation. If the result is exact, it does not depend on rounding mode.
+    RM = llvm::RoundingMode::NearestTiesToEven;
+  APFloat::opStatus St;
----------------
Feels like you should have a helper function like `getActiveRoundingMode(Info, FPFeatures)`


================
Comment at: clang/lib/AST/ExprConstant.cpp:2712
+  //   initializer,
+  // the evaluation probably need to be rejected.
+
----------------
Is this processing something you can extract meaningfully into a common function that works with an opStatus, so that you can just write `if (!checkFloatingPointFailure(Info, E, status, fpFeatures)) return false;` in all these places?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87822/new/

https://reviews.llvm.org/D87822



More information about the cfe-commits mailing list