[PATCH] D134859: [clang][Interp] Implement basic support for floating point values

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Dec 17 22:02:31 PST 2022


tbaeder marked 5 inline comments as done.
tbaeder added inline comments.


================
Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:607
+    if (*LT == PT_Float) {
+      if (!this->emitAddf(getRoundingMode(E), E))
+        return false;
----------------
sepavloff wrote:
> As discussed previously, compound assign operator cannot be implemented with the same function as corresponding binary operator in general case.
I left this in so at least one of the test cases in `const-fpfeatures.cpp` would work. But it seems like using `res = res + y` instead works as well and breaks if the `#pragma` before is commented-out, so I can use that instead.


================
Comment at: clang/lib/AST/Interp/Interp.h:1243
+    // T's bit width.
+    if (!T::canRepresent(Result)) {
+      const Expr *E = S.Current->getExpr(OpPC);
----------------
sepavloff wrote:
> sepavloff wrote:
> > `Integral::canRepresent` is suitable only for integral-to-intergal conversions. With loss of precision the floating-point numbers can represent wider range of integers.
> I was wrong, this is float-to-integer conversion. Would it be easier to detect overflow (as well as other cases, like NaN) by checking that `Status==opInvalidOp && F.isFinite()`? 
That seems to work, yes. I switched to that and added an overflow test case to`floats.cpp`.


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

https://reviews.llvm.org/D134859



More information about the cfe-commits mailing list