Skip to content

Commit c61e699

Browse files
committed
Make all fma variants constexpr, add tests
1 parent 7665f0d commit c61e699

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

clang/include/clang/Basic/Builtins.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3885,7 +3885,7 @@ def Floor : FPMathTemplate, LibBuiltin<"math.h"> {
38853885

38863886
def Fma : FPMathTemplate, LibBuiltin<"math.h"> {
38873887
let Spellings = ["fma"];
3888-
let Attributes = [NoThrow, ConstIgnoringErrnoAndExceptions];
3888+
let Attributes = [NoThrow, ConstIgnoringErrnoAndExceptions, Constexpr];
38893889
let Prototype = "T(T, T, T)";
38903890
let AddBuiltinPrefixedAlias = 1;
38913891
}

clang/test/AST/ByteCode/builtin-functions.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,6 +1742,19 @@ namespace Invalid {
17421742
// both-note {{in call to}}
17431743
}
17441744

1745+
namespace Fma {
1746+
static_assert(__builtin_fma(2.0, 3.0, 4.0) == 10.0);
1747+
static_assert(__builtin_fma(200.0, 300.0, 400.0) == 60400.0);
1748+
static_assert(__builtin_fmal(2.0, 3.0, 4.0) == 10.0);
1749+
static_assert(__builtin_fmal(200.0, 300.0, 400.0) == 60400.0);
1750+
static_assert(__builtin_fmaf(2.0, 3.0, 4.0) == 10.0);
1751+
static_assert(__builtin_fmaf(200.0, 300.0, 400.0) == 60400.0);
1752+
static_assert(__builtin_fmaf16(2.0, 3.0, 4.0) == 10.0);
1753+
static_assert(__builtin_fmaf16(200.0, 300.0, 400.0) == 60416.0);
1754+
static_assert(__builtin_fmaf128(2.0, 3.0, 4.0) == 10.0);
1755+
static_assert(__builtin_fmaf128(200.0, 300.0, 400.0) == 60400.0);
1756+
}
1757+
17451758
#if __cplusplus >= 202002L
17461759
namespace WithinLifetime {
17471760
constexpr int a = 10;

0 commit comments

Comments
 (0)