[clang] [Clang] Allow __builtin_fma/fmaf/fmal to be used in a constant expression (PR #158048)
Chaitanya Koparkar via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 11 05:06:40 PDT 2025
================
@@ -199,7 +199,7 @@ def FloorF16F128 : Builtin, F16F128MathTemplate {
def FmaF16F128 : Builtin, F16F128MathTemplate {
let Spellings = ["__builtin_fma"];
- let Attributes = [FunctionWithBuiltinPrefix, NoThrow, ConstIgnoringErrnoAndExceptions];
+ let Attributes = [FunctionWithBuiltinPrefix, NoThrow, ConstIgnoringErrnoAndExceptions, Constexpr];
----------------
ckoparkar wrote:
With this edit I get the following `Builtins.inc`:
```
Builtin::Info{Builtin::Info::StrOffsets{10959 /* __builtin_fmaf */, 10974 /* ffff */, 2289 /* Fne */, 0}, HeaderDesc::NO_HEADER, ALL_LANGUAGES},
Builtin::Info{Builtin::Info::StrOffsets{10979 /* fmaf */, 10974 /* ffff */, 2299 /* fne */, 0}, HeaderDesc::MATH_H, ALL_LANGUAGES},
Builtin::Info{Builtin::Info::StrOffsets{10984 /* __builtin_fma */, 10998 /* dddd */, 2289 /* Fne */, 0}, HeaderDesc::NO_HEADER, ALL_LANGUAGES},
Builtin::Info{Builtin::Info::StrOffsets{11003 /* fma */, 10998 /* dddd */, 2299 /* fne */, 0}, HeaderDesc::MATH_H, ALL_LANGUAGES},
Builtin::Info{Builtin::Info::StrOffsets{11007 /* __builtin_fmal */, 11022 /* LdLdLdLd */, 2289 /* Fne */, 0}, HeaderDesc::NO_HEADER, ALL_LANGUAGES},
Builtin::Info{Builtin::Info::StrOffsets{11031 /* fmal */, 11022 /* LdLdLdLd */, 2299 /* fne */, 0}, HeaderDesc::MATH_H, ALL_LANGUAGES},
Builtin::Info{Builtin::Info::StrOffsets{11036 /* __builtin_fmaf16 */, 11053 /* hhhh */, 11058 /* FneE */, 0}, HeaderDesc::NO_HEADER, ALL_LANGUAGES},
Builtin::Info{Builtin::Info::StrOffsets{11063 /* __builtin_fmaf128 */, 11081 /* LLdLLdLLdLLd */, 11058 /* FneE */, 0}, HeaderDesc::NO_HEADER, ALL_LANGUAGES},
```
Only `__builtin_fmaf16` and `__builtin_fmaf128` get the `// E -> this function can be constant evaluated by Clang frontend` attribute; so these can be used in constexpr but others raise an error. Also, I think the class `F16F128MathTemplate` is generating `f16` and `f128` versions but I'm not sure how are the other versions `f`, `l`, etc. being generated.
What am I missing?
https://github.com/llvm/llvm-project/pull/158048
More information about the cfe-commits
mailing list