Skip to content

Commit 7f60acb

Browse files
committed
add constexpr evaluation tests in Sema
1 parent 9c8d237 commit 7f60acb

File tree

2 files changed

+110
-0
lines changed

2 files changed

+110
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify %s
2+
// FIXME: %clang_cc1 -std=c++17 -fsyntax-only -verify -fexperimental-new-constant-interpreter %s
3+
// expected-no-diagnostics
4+
5+
constexpr double NaN = __builtin_nan("");
6+
constexpr double Inf = __builtin_inf();
7+
constexpr double NegInf = -__builtin_inf();
8+
9+
#define FMAXIMUMNUM_TEST_SIMPLE(T, FUNC) \
10+
static_assert(T(6.7890) == FUNC(T(1.2345), T(6.7890))); \
11+
static_assert(T(6.7890) == FUNC(T(6.7890), T(1.2345)));
12+
13+
#define FMAXIMUMNUM_TEST_NAN(T, FUNC) \
14+
static_assert(Inf == FUNC(NaN, Inf)); \
15+
static_assert(NegInf == FUNC(NegInf, NaN)); \
16+
static_assert(0.0 == FUNC(NaN, 0.0)); \
17+
static_assert(-0.0 == FUNC(-0.0, NaN)); \
18+
static_assert(T(-1.2345) == FUNC(NaN, T(-1.2345))); \
19+
static_assert(T(1.2345) == FUNC(T(1.2345), NaN)); \
20+
static_assert(__builtin_isnan(FUNC(NaN, NaN)));
21+
22+
#define FMAXIMUMNUM_TEST_INF(T, FUNC) \
23+
static_assert(Inf == FUNC(NegInf, Inf)); \
24+
static_assert(Inf == FUNC(Inf, 0.0)); \
25+
static_assert(Inf == FUNC(-0.0, Inf)); \
26+
static_assert(Inf == FUNC(Inf, T(1.2345))); \
27+
static_assert(Inf == FUNC(T(-1.2345), Inf));
28+
29+
#define FMAXIMUMNUM_TEST_NEG_INF(T, FUNC) \
30+
static_assert(Inf == FUNC(Inf, NegInf)); \
31+
static_assert(0.0 == FUNC(NegInf, 0.0)); \
32+
static_assert(-0.0 == FUNC(-0.0, NegInf)); \
33+
static_assert(T(-1.2345) == FUNC(NegInf, T(-1.2345))); \
34+
static_assert(T(1.2345) == FUNC(T(1.2345), NegInf));
35+
36+
#define FMAXIMUMNUM_TEST_BOTH_ZERO(T, FUNC) \
37+
static_assert(__builtin_copysign(1.0, FUNC(0.0, 0.0)) == 1.0); \
38+
static_assert(__builtin_copysign(1.0, FUNC(-0.0, 0.0)) == 1.0); \
39+
static_assert(__builtin_copysign(1.0, FUNC(0.0, -0.0)) == 1.0); \
40+
static_assert(__builtin_copysign(1.0, FUNC(-0.0, -0.0)) == -1.0);
41+
42+
#define LIST_FMAXIMUMNUM_TESTS(T, FUNC) \
43+
FMAXIMUMNUM_TEST_SIMPLE(T, FUNC) \
44+
FMAXIMUMNUM_TEST_NAN(T, FUNC) \
45+
FMAXIMUMNUM_TEST_INF(T, FUNC) \
46+
FMAXIMUMNUM_TEST_NEG_INF(T, FUNC) \
47+
FMAXIMUMNUM_TEST_BOTH_ZERO(T, FUNC)
48+
49+
LIST_FMAXIMUMNUM_TESTS(double, __builtin_fmaximum_num)
50+
LIST_FMAXIMUMNUM_TESTS(float, __builtin_fmaximum_numf)
51+
LIST_FMAXIMUMNUM_TESTS((long double), __builtin_fmaximum_numl)
52+
LIST_FMAXIMUMNUM_TESTS(__fp16, __builtin_fmaximum_numf16)
53+
#ifdef __FLOAT128__
54+
LIST_FMAXIMUMNUM_TESTS(__float128, __builtin_fmaximum_numf128)
55+
#endif
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify %s
2+
// FIXME: %clang_cc1 -std=c++17 -fsyntax-only -verify -fexperimental-new-constant-interpreter %s
3+
// expected-no-diagnostics
4+
5+
constexpr double NaN = __builtin_nan("");
6+
constexpr double Inf = __builtin_inf();
7+
constexpr double NegInf = -__builtin_inf();
8+
9+
#define FMAXIMUMNUM_TEST_SIMPLE(T, FUNC) \
10+
static_assert(T(1.2345) == FUNC(T(1.2345), T(6.7890))); \
11+
static_assert(T(1.2345) == FUNC(T(6.7890), T(1.2345)));
12+
13+
#define FMAXIMUMNUM_TEST_NAN(T, FUNC) \
14+
static_assert(Inf == FUNC(NaN, Inf)); \
15+
static_assert(NegInf == FUNC(NegInf, NaN)); \
16+
static_assert(0.0 == FUNC(NaN, 0.0)); \
17+
static_assert(-0.0 == FUNC(-0.0, NaN)); \
18+
static_assert(T(-1.2345) == FUNC(NaN, T(-1.2345))); \
19+
static_assert(T(1.2345) == FUNC(T(1.2345), NaN)); \
20+
static_assert(__builtin_isnan(FUNC(NaN, NaN)));
21+
22+
#define FMAXIMUMNUM_TEST_INF(T, FUNC) \
23+
static_assert(NegInf == FUNC(NegInf, Inf)); \
24+
static_assert(0.0 == FUNC(Inf, 0.0)); \
25+
static_assert(-0.0 == FUNC(-0.0, Inf)); \
26+
static_assert(T(1.2345) == FUNC(Inf, T(1.2345))); \
27+
static_assert(T(-1.2345) == FUNC(T(-1.2345), Inf));
28+
29+
#define FMAXIMUMNUM_TEST_NEG_INF(T, FUNC) \
30+
static_assert(NegInf == FUNC(Inf, NegInf)); \
31+
static_assert(NegInf == FUNC(NegInf, 0.0)); \
32+
static_assert(NegInf == FUNC(-0.0, NegInf)); \
33+
static_assert(NegInf == FUNC(NegInf, T(-1.2345))); \
34+
static_assert(NegInf == FUNC(T(1.2345), NegInf));
35+
36+
#define FMAXIMUMNUM_TEST_BOTH_ZERO(T, FUNC) \
37+
static_assert(__builtin_copysign(1.0, FUNC(0.0, 0.0)) == 1.0); \
38+
static_assert(__builtin_copysign(1.0, FUNC(-0.0, 0.0)) == -1.0); \
39+
static_assert(__builtin_copysign(1.0, FUNC(0.0, -0.0)) == -1.0); \
40+
static_assert(__builtin_copysign(1.0, FUNC(-0.0, -0.0)) == -1.0);
41+
42+
#define LIST_FMAXIMUMNUM_TESTS(T, FUNC) \
43+
FMAXIMUMNUM_TEST_SIMPLE(T, FUNC) \
44+
FMAXIMUMNUM_TEST_NAN(T, FUNC) \
45+
FMAXIMUMNUM_TEST_INF(T, FUNC) \
46+
FMAXIMUMNUM_TEST_NEG_INF(T, FUNC) \
47+
FMAXIMUMNUM_TEST_BOTH_ZERO(T, FUNC)
48+
49+
LIST_FMAXIMUMNUM_TESTS(double, __builtin_fminimum_num)
50+
LIST_FMAXIMUMNUM_TESTS(float, __builtin_fminimum_numf)
51+
LIST_FMAXIMUMNUM_TESTS((long double), __builtin_fminimum_numl)
52+
LIST_FMAXIMUMNUM_TESTS(__fp16, __builtin_fminimum_numf16)
53+
#ifdef __FLOAT128__
54+
LIST_FMAXIMUMNUM_TESTS(__float128, __builtin_fminimum_numf128)
55+
#endif

0 commit comments

Comments
 (0)