• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang_cc1 -DX32TYPE=ULONG -triple powerpc-unknown-linux-gnu -std=c89 -x c %s -verify
2 // RUN: %clang_cc1 -DX32TYPE=ULONG -triple powerpc-unknown-linux-gnu -std=iso9899:199409 -x c %s -verify
3 // RUN: %clang_cc1 -DX32TYPE=ULONG -triple powerpc-unknown-linux-gnu -std=c++98 -x c++ %s -verify
4 // RUN: %clang_cc1 -DX32TYPE=LLONG -triple powerpc-unknown-linux-gnu -std=c99 -x c %s -verify
5 // RUN: %clang_cc1 -DX32TYPE=LLONG -triple powerpc-unknown-linux-gnu -std=c11 -x c %s -verify
6 // RUN: %clang_cc1 -DX32TYPE=LLONG -triple powerpc-unknown-linux-gnu -std=c++11 -x c++ %s -verify
7 // RUN: %clang_cc1 -DX32TYPE=LLONG -triple powerpc-unknown-linux-gnu -std=c++1y -x c++ %s -verify
8 // RUN: %clang_cc1 -DX32TYPE=LLONG -triple powerpc-unknown-linux-gnu -std=c++1z -x c++ %s -verify
9 // RUN: %clang_cc1 -DX64TYPE=ULONG -triple powerpc64-unknown-linux-gnu -std=c89 -x c %s -verify
10 // RUN: %clang_cc1 -DX64TYPE=ULONG -triple powerpc64-unknown-linux-gnu -std=iso9899:199409 -x c %s -verify
11 // RUN: %clang_cc1 -DX64TYPE=ULONG -triple powerpc64-unknown-linux-gnu -std=c++98 -x c++ %s -verify
12 // RUN: %clang_cc1 -DX64TYPE=ULLONG -triple powerpc64-unknown-linux-gnu -std=c99 -x c %s -verify
13 // RUN: %clang_cc1 -DX64TYPE=ULLONG -triple powerpc64-unknown-linux-gnu -std=c11 -x c %s -verify
14 // RUN: %clang_cc1 -DX64TYPE=ULLONG -triple powerpc64-unknown-linux-gnu -std=c++11 -x c++ %s -verify
15 // RUN: %clang_cc1 -DX64TYPE=ULLONG -triple powerpc64-unknown-linux-gnu -std=c++1y -x c++ %s -verify
16 // RUN: %clang_cc1 -DX64TYPE=ULLONG -triple powerpc64-unknown-linux-gnu -std=c++1z -x c++ %s -verify
17 
18 #ifdef X64TYPE
19 #define X32TYPE long
20 #endif
21 
22 #define IS_ULONG_ULONG 1
23 #define IS_ULONG2(X) IS_ULONG_##X
24 #define IS_ULONG(X) IS_ULONG2(X)
25 
26 #if !defined(X64TYPE) && !IS_ULONG(X32TYPE)
27 // expected-no-diagnostics
28 #endif
29 
30 typedef unsigned long ULONG;
31 typedef long long LLONG;
32 typedef unsigned long long ULLONG;
33 
34 
35 /******************************************************************************
36  * Test 2^31 as a decimal literal with no suffix and with the "l" and "L" cases.
37  ******************************************************************************/
38 extern X32TYPE x32;
39 extern __typeof__(2147483648) x32;
40 extern __typeof__(2147483648l) x32;
41 extern __typeof__(2147483648L) x32;
42 
43 #if IS_ULONG(X32TYPE)
44 #if !__cplusplus
45 
46 /******************************************************************************
47  * Under pre-C99 ISO C, unsigned long is attempted for decimal integer literals
48  * that do not have a suffix containing "u" or "U" if the literal does not fit
49  * within the range of int or long. See 6.1.3.2 paragraph 5.
50  ******************************************************************************/
51 // expected-warning@39 {{integer literal is too large to be represented in type 'long', interpreting as 'unsigned long' per C89; this literal will have type 'long long' in C99 onwards}}
52 // expected-warning@40 {{integer literal is too large to be represented in type 'long', interpreting as 'unsigned long' per C89; this literal will have type 'long long' in C99 onwards}}
53 // expected-warning@41 {{integer literal is too large to be represented in type 'long', interpreting as 'unsigned long' per C89; this literal will have type 'long long' in C99 onwards}}
54 #else
55 
56 /******************************************************************************
57  * Under pre-C++11 ISO C++, the same holds if the literal contains an "l" or "L"
58  * in its suffix; otherwise, the behavior is undefined. See 2.13.1 [lex.icon]
59  * paragraph 2.
60  ******************************************************************************/
61 // expected-warning@39 {{integer literal is too large to be represented in type 'long' and is subject to undefined behavior under C++98, interpreting as 'unsigned long'; this literal will have type 'long long' in C++11 onwards}}
62 // expected-warning@40 {{integer literal is too large to be represented in type 'long', interpreting as 'unsigned long' per C++98; this literal will have type 'long long' in C++11 onwards}}
63 // expected-warning@41 {{integer literal is too large to be represented in type 'long', interpreting as 'unsigned long' per C++98; this literal will have type 'long long' in C++11 onwards}}
64 #endif
65 #endif
66 
67 
68 #ifdef X64TYPE
69 
70 /******************************************************************************
71  * Test 2^63 as a decimal literal with no suffix and with the "l" and "L" cases.
72  ******************************************************************************/
73 extern X64TYPE x64;
74 extern __typeof__(9223372036854775808) x64;
75 extern __typeof__(9223372036854775808l) x64;
76 extern __typeof__(9223372036854775808L) x64;
77 
78 #if IS_ULONG(X64TYPE)
79 
80 #if !__cplusplus
81 
82 /******************************************************************************
83  * Under pre-C99 ISO C, unsigned long is attempted for decimal integer literals
84  * that do not have a suffix containing "u" or "U" if the literal does not fit
85  * within the range of int or long. See 6.1.3.2 paragraph 5.
86  ******************************************************************************/
87 // expected-warning@74 {{integer literal is too large to be represented in type 'long', interpreting as 'unsigned long' per C89; this literal will be ill-formed in C99 onwards}}
88 // expected-warning@75 {{integer literal is too large to be represented in type 'long', interpreting as 'unsigned long' per C89; this literal will be ill-formed in C99 onwards}}
89 // expected-warning@76 {{integer literal is too large to be represented in type 'long', interpreting as 'unsigned long' per C89; this literal will be ill-formed in C99 onwards}}
90 #else
91 
92 /******************************************************************************
93  * Under pre-C++11 ISO C++, the same holds if the literal contains an "l" or "L"
94  * in its suffix; otherwise, the behavior is undefined. See 2.13.1 [lex.icon]
95  * paragraph 2.
96  ******************************************************************************/
97 // expected-warning@74 {{integer literal is too large to be represented in type 'long' and is subject to undefined behavior under C++98, interpreting as 'unsigned long'; this literal will be ill-formed in C++11 onwards}}
98 // expected-warning@75 {{integer literal is too large to be represented in type 'long', interpreting as 'unsigned long' per C++98; this literal will be ill-formed in C++11 onwards}}
99 // expected-warning@76 {{integer literal is too large to be represented in type 'long', interpreting as 'unsigned long' per C++98; this literal will be ill-formed in C++11 onwards}}
100 #endif
101 #else
102 
103 /******************************************************************************
104  * The status quo in C99/C++11-and-later modes for the literals in question is
105  * to interpret them as unsigned as an extension.
106  ******************************************************************************/
107 // expected-warning@74 {{integer literal is too large to be represented in a signed integer type, interpreting as unsigned}}
108 // expected-warning@75 {{integer literal is too large to be represented in a signed integer type, interpreting as unsigned}}
109 // expected-warning@76 {{integer literal is too large to be represented in a signed integer type, interpreting as unsigned}}
110 #endif
111 #endif
112 
113 
114 /******************************************************************************
115  * Test preprocessor arithmetic with 2^31 as a decimal literal with no suffix
116  * and with the "l" and "L" cases.
117  ******************************************************************************/
118 #if !IS_ULONG(X32TYPE)
119 
120 /******************************************************************************
121  * If the literal is signed without need for the modified range of the signed
122  * integer types within the controlling constant expression for conditional
123  * inclusion, then it will also be signed with said modified range.
124  ******************************************************************************/
125 #define EXPR(X) ((X - X) - 1 < 0)
126 #else
127 
128 /******************************************************************************
129  * Strictly speaking, in pre-C99/C++11 ISO C/C++, the preprocessor arithmetic is
130  * evaluated with the range of long/unsigned long; however, both Clang and GCC
131  * evaluate using 64-bits even when long/unsigned long are 32-bits outside of
132  * preprocessing.
133  *
134  * If the range used becomes 32-bits, then this test will enforce the treatment
135  * as unsigned of the literals in question.
136  *
137  * Note:
138  * Under pre-C99/C++11 ISO C/C++, whether the interpretation of the literal is
139  * affected by the modified range of the signed and unsigned integer types
140  * within the controlling constant expression for conditional inclusion is
141  * unclear.
142  ******************************************************************************/
143 #define PP_LONG_MAX ((0ul - 1ul) >> 1)
144 #define EXPR(X)                                                                \
145   (PP_LONG_MAX >= 0x80000000 || (X - X) - 1 > 0) // either 2^31 fits into a
146                                                  // preprocessor "long" or the
147                                                  // literals in question are
148                                                  // unsigned
149 #endif
150 
151 #if !(EXPR(2147483648) && EXPR(2147483648l) && EXPR(2147483648L))
152 #error Unexpected signedness or conversion behavior
153 #endif
154