Skip to content

Commit 3542dd8

Browse files
committed
[clang][Interp][NFC] Move int128 tests to their own file
1 parent f5031c6 commit 3542dd8

File tree

2 files changed

+79
-75
lines changed

2 files changed

+79
-75
lines changed

clang/test/AST/Interp/intap.cpp

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -fms-extensions -std=c++11 -verify %s
2+
// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -fms-extensions -std=c++20 -verify %s
3+
// RUN: %clang_cc1 -std=c++11 -fms-extensions -verify=ref %s
4+
// RUN: %clang_cc1 -std=c++20 -fms-extensions -verify=ref %s
5+
6+
#ifdef __SIZEOF_INT128__
7+
namespace i128 {
8+
typedef __int128 int128_t;
9+
typedef unsigned __int128 uint128_t;
10+
constexpr int128_t I128_1 = 12;
11+
static_assert(I128_1 == 12, "");
12+
static_assert(I128_1 != 10, "");
13+
static_assert(I128_1 != 12, ""); // expected-error{{failed}} \
14+
// ref-error{{failed}} \
15+
// expected-note{{evaluates to}} \
16+
// ref-note{{evaluates to}}
17+
18+
static const __uint128_t UINT128_MAX =__uint128_t(__int128_t(-1L));
19+
static_assert(UINT128_MAX == -1, "");
20+
21+
static const __int128_t INT128_MAX = UINT128_MAX >> (__int128_t)1;
22+
static_assert(INT128_MAX != 0, "");
23+
static const __int128_t INT128_MIN = -INT128_MAX - 1;
24+
constexpr __int128 A = INT128_MAX + 1; // expected-error {{must be initialized by a constant expression}} \
25+
// expected-note {{outside the range}} \
26+
// ref-error {{must be initialized by a constant expression}} \
27+
// ref-note {{outside the range}}
28+
constexpr int128_t Two = (int128_t)1 << 1ul;
29+
static_assert(Two == 2, "");
30+
31+
constexpr uint128_t AllOnes = ~static_cast<uint128_t>(0);
32+
static_assert(AllOnes == UINT128_MAX, "");
33+
34+
#if __cplusplus >= 201402L
35+
template <typename T>
36+
constexpr T CastFrom(__int128_t A) {
37+
T B = (T)A;
38+
return B;
39+
}
40+
static_assert(CastFrom<char>(12) == 12, "");
41+
static_assert(CastFrom<unsigned char>(12) == 12, "");
42+
static_assert(CastFrom<long>(12) == 12, "");
43+
static_assert(CastFrom<unsigned short>(12) == 12, "");
44+
static_assert(CastFrom<int128_t>(12) == 12, "");
45+
static_assert(CastFrom<float>(12) == 12, "");
46+
static_assert(CastFrom<double>(12) == 12, "");
47+
static_assert(CastFrom<long double>(12) == 12, "");
48+
49+
static_assert(CastFrom<char>(AllOnes) == -1, "");
50+
static_assert(CastFrom<unsigned char>(AllOnes) == 0xFF, "");
51+
static_assert(CastFrom<long>(AllOnes) == -1, "");
52+
static_assert(CastFrom<unsigned short>(AllOnes) == 0xFFFF, "");
53+
static_assert(CastFrom<int>(AllOnes) == -1, "");
54+
static_assert(CastFrom<int128_t>(AllOnes) == -1, "");
55+
static_assert(CastFrom<uint128_t>(AllOnes) == AllOnes, "");
56+
57+
template <typename T>
58+
constexpr __int128 CastTo(T A) {
59+
int128_t B = (int128_t)A;
60+
return B;
61+
}
62+
static_assert(CastTo<char>(12) == 12, "");
63+
static_assert(CastTo<unsigned char>(12) == 12, "");
64+
static_assert(CastTo<long>(12) == 12, "");
65+
static_assert(CastTo<unsigned long long>(12) == 12, "");
66+
static_assert(CastTo<float>(12) == 12, "");
67+
static_assert(CastTo<double>(12) == 12, "");
68+
static_assert(CastTo<long double>(12) == 12, "");
69+
#endif
70+
71+
constexpr int128_t Error = __LDBL_MAX__; // ref-warning {{implicit conversion of out of range value}} \
72+
// ref-error {{must be initialized by a constant expression}} \
73+
// ref-note {{is outside the range of representable values of type}} \
74+
// expected-warning {{implicit conversion of out of range value}} \
75+
// expected-error {{must be initialized by a constant expression}} \
76+
// expected-note {{is outside the range of representable values of type}}
77+
}
78+
79+
#endif

clang/test/AST/Interp/literals.cpp

-75
Original file line numberDiff line numberDiff line change
@@ -26,81 +26,6 @@ static_assert(number != 10, ""); // expected-error{{failed}} \
2626
// expected-note{{evaluates to}} \
2727
// ref-note{{evaluates to}}
2828

29-
30-
#ifdef __SIZEOF_INT128__
31-
namespace i128 {
32-
typedef __int128 int128_t;
33-
typedef unsigned __int128 uint128_t;
34-
constexpr int128_t I128_1 = 12;
35-
static_assert(I128_1 == 12, "");
36-
static_assert(I128_1 != 10, "");
37-
static_assert(I128_1 != 12, ""); // expected-error{{failed}} \
38-
// ref-error{{failed}} \
39-
// expected-note{{evaluates to}} \
40-
// ref-note{{evaluates to}}
41-
42-
static const __uint128_t UINT128_MAX =__uint128_t(__int128_t(-1L));
43-
static_assert(UINT128_MAX == -1, "");
44-
45-
static const __int128_t INT128_MAX = UINT128_MAX >> (__int128_t)1;
46-
static_assert(INT128_MAX != 0, "");
47-
static const __int128_t INT128_MIN = -INT128_MAX - 1;
48-
constexpr __int128 A = INT128_MAX + 1; // expected-error {{must be initialized by a constant expression}} \
49-
// expected-note {{outside the range}} \
50-
// ref-error {{must be initialized by a constant expression}} \
51-
// ref-note {{outside the range}}
52-
constexpr int128_t Two = (int128_t)1 << 1ul;
53-
static_assert(Two == 2, "");
54-
55-
constexpr uint128_t AllOnes = ~static_cast<uint128_t>(0);
56-
static_assert(AllOnes == UINT128_MAX, "");
57-
58-
#if __cplusplus >= 201402L
59-
template <typename T>
60-
constexpr T CastFrom(__int128_t A) {
61-
T B = (T)A;
62-
return B;
63-
}
64-
static_assert(CastFrom<char>(12) == 12, "");
65-
static_assert(CastFrom<unsigned char>(12) == 12, "");
66-
static_assert(CastFrom<long>(12) == 12, "");
67-
static_assert(CastFrom<unsigned short>(12) == 12, "");
68-
static_assert(CastFrom<int128_t>(12) == 12, "");
69-
static_assert(CastFrom<float>(12) == 12, "");
70-
static_assert(CastFrom<double>(12) == 12, "");
71-
static_assert(CastFrom<long double>(12) == 12, "");
72-
73-
static_assert(CastFrom<char>(AllOnes) == -1, "");
74-
static_assert(CastFrom<unsigned char>(AllOnes) == 0xFF, "");
75-
static_assert(CastFrom<long>(AllOnes) == -1, "");
76-
static_assert(CastFrom<unsigned short>(AllOnes) == 0xFFFF, "");
77-
static_assert(CastFrom<int>(AllOnes) == -1, "");
78-
static_assert(CastFrom<int128_t>(AllOnes) == -1, "");
79-
static_assert(CastFrom<uint128_t>(AllOnes) == AllOnes, "");
80-
81-
template <typename T>
82-
constexpr __int128 CastTo(T A) {
83-
int128_t B = (int128_t)A;
84-
return B;
85-
}
86-
static_assert(CastTo<char>(12) == 12, "");
87-
static_assert(CastTo<unsigned char>(12) == 12, "");
88-
static_assert(CastTo<long>(12) == 12, "");
89-
static_assert(CastTo<unsigned long long>(12) == 12, "");
90-
static_assert(CastTo<float>(12) == 12, "");
91-
static_assert(CastTo<double>(12) == 12, "");
92-
static_assert(CastTo<long double>(12) == 12, "");
93-
#endif
94-
95-
constexpr int128_t Error = __LDBL_MAX__; // ref-warning {{implicit conversion of out of range value}} \
96-
// ref-error {{must be initialized by a constant expression}} \
97-
// ref-note {{is outside the range of representable values of type}} \
98-
// expected-warning {{implicit conversion of out of range value}} \
99-
// expected-error {{must be initialized by a constant expression}} \
100-
// expected-note {{is outside the range of representable values of type}}
101-
}
102-
#endif
103-
10429
constexpr bool b = number;
10530
static_assert(b, "");
10631
constexpr int one = true;

0 commit comments

Comments
 (0)