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

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 25 10:55:31 PDT 2023


aaron.ballman added a comment.

In D155356#4513303 <https://reviews.llvm.org/D155356#4513303>, @tbaeder wrote:

> One thing I'm wondering though is:
>
>   constexpr char A[] = {'1', '2', '3'};
>   constexpr double d = __builtin_nans(A);
>
> what's expected here? The given char array is not null-terminated.

The builtin expects a null terminated string, so that should be an invalid constant expression due to reading off the end of the array.

> Should the interpreter ignore the null byte at the end if it's there? `StringRef::getAsInteger()` always returns an error if it encounters one, so the currentcode in `InterpBuiltin.cpp` ignores the last byte and will pass `12` along for the example above.

Yeah, we should not do that. :-D In GCC, this builtin exists to support the `nans()` function from https://www.open-std.org/jtc1/sc22/wg14/www/docs/n965.htm (which was proposed but never adopted); Clang's support is for parity with GCC.


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

https://reviews.llvm.org/D155356



More information about the cfe-commits mailing list