[clang] [llvm] [C++23] [CLANG] Adding C++23 constexpr math functions: fmin, fmax and frexp. (PR #88978)

Hubert Tong via llvm-commits llvm-commits at lists.llvm.org
Sat May 18 20:12:32 PDT 2024


================
@@ -3452,9 +3452,10 @@ def Fmod : FPMathTemplate, LibBuiltin<"math.h"> {
 
 def Frexp : FPMathTemplate, LibBuiltin<"math.h"> {
   let Spellings = ["frexp"];
-  let Attributes = [NoThrow];
+  let Attributes = [NoThrow, Constexpr];
----------------
hubert-reinterpretcast wrote:

The `Constexpr` here makes the non-`__builtin_`-prefixed version of the function `constexpr` under all language levels.
I checked the code: The `OnlyBuiltinPrefixedAliasIsConstexpr` flag can _add_ `constexpr`-ness; it does not _restrict_ it.

For reference:
https://github.com/llvm/llvm-project/blob/702198fc9ac5dba392f9d9ba7c56467996343c0a/clang/utils/TableGen/ClangBuiltinsEmitter.cpp#L225-L226

We may need a new builtin attribute that expresses `constexpr` for the non-prefixed functions only for C++23 and up (but we might end up with C++26-and-up, etc. in the future). However, it seems making the non-prefixed functions actually non-`constexpr` (as opposed to simply failing to evaluate) is only a QoI concern (see https://github.com/llvm/llvm-project/pull/88978#issuecomment-2119080104 for more context).

@philnik777, thoughts?

https://github.com/llvm/llvm-project/pull/88978


More information about the llvm-commits mailing list