[PATCH] D155356: [clang][Interp] Implement __builtin_nan family of functions

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 18 21:02:51 PDT 2023


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


================
Comment at: clang/lib/AST/Interp/InterpBuiltin.cpp:106
+    // 2008 revisions, MIPS interpreted sNaN-2008 as qNan and qNaN-2008 as
+    // sNaN. This is now known as "legacy NaN" encoding.
+    if (Signaling)
----------------
aaron.ballman wrote:
> LOL, thank you for this comment and wow. :-D
That's just copy/paste from `ExprConst.cpp` :)


================
Comment at: clang/test/AST/Interp/builtin-functions.cpp:44
+
+  constexpr float Nan2 = __builtin_nans([](){return "0xAE98";}()); // ref-error {{must be initialized by a constant expression}}
+}
----------------
aaron.ballman wrote:
> tbaeder wrote:
> > aaron.ballman wrote:
> > > Probably worth a comment here mentioning that the ref-error is a rejects-valid issue that the experimental compiler accepts correctly.
> > I thought you said on Discord that the current interpreter is correct? I made the new one reject anything but string literals in https://reviews.llvm.org/D155545.
> Oops, crossing streams as I just mentioned this in another review of yours in the same area.
> 
> I think I misunderstood the question on Discord when we were chatting. I was thinking the situation was more that Sema was allowing through something like `__builtin_nan(12);` and diagnosing it later during CodeGen. I think constexpr builtins should generally behave the same as regular constexpr functions the user could write.
> 
> I'm really sorry if I made extra work for you with this confusion!
No problem, passing the `CallExpr` along still makes sense.


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

https://reviews.llvm.org/D155356



More information about the cfe-commits mailing list