| 1 |
// RUN: %clang_cc1 -triple x86_64-unknown-linux -verify %s |
| 2 |
// RUN: %clang_cc1 -triple i686-unknown-linux -verify %s |
| 3 |
// RUN: %clang_cc1 -triple x86_64-unknown-win32 -verify %s |
| 4 |
// RUN: %clang_cc1 -triple i686-unknown-win32 -verify %s |
| 5 |
|
| 6 |
/* WG14 N629: yes |
| 7 |
* integer constant type rules |
| 8 |
*/ |
| 9 |
|
| 10 |
// expected-no-diagnostics |
| 11 |
|
| 12 |
void test_decimal_constants(void) { |
| 13 |
// Easy cases where the value fits into the type you'd expect. |
| 14 |
(void)_Generic(2, int : 1); |
| 15 |
(void)_Generic(2u, unsigned int : 1); |
| 16 |
(void)_Generic(2l, long : 1); |
| 17 |
(void)_Generic(2ul, unsigned long : 1); |
| 18 |
(void)_Generic(2ll, long long : 1); |
| 19 |
(void)_Generic(2ull, unsigned long long : 1); |
| 20 |
|
| 21 |
#if __INT_WIDTH__ == 16 |
| 22 |
#if __LONG_WIDTH__ > 16 |
| 23 |
(void)_Generic(65536, long : 1); |
| 24 |
(void)_Generic(65536U, unsigned long : 1); |
| 25 |
#else |
| 26 |
(void)_Generic(65536, long long : 1); |
| 27 |
(void)_Generic(65536U, unsigned long : 1); |
| 28 |
#endif // __LONG_WIDTH__ > 16 |
| 29 |
#elif __INT_WIDTH__ == 32 |
| 30 |
#if __LONG_WIDTH__ > 32 |
| 31 |
(void)_Generic(4294967296, long : 1); |
| 32 |
(void)_Generic(4294967296U, unsigned long : 1); |
| 33 |
#else |
| 34 |
(void)_Generic(4294967296, long long : 1); |
| 35 |
(void)_Generic(4294967296U, unsigned long long : 1); |
| 36 |
#endif // __LONG_WIDTH__ > 32 |
| 37 |
#endif |
| 38 |
|
| 39 |
#if __LONG_WIDTH__ > 32 |
| 40 |
(void)_Generic(4294967296L, long : 1); |
| 41 |
(void)_Generic(4294967296U, unsigned long : 1); |
| 42 |
#else |
| 43 |
(void)_Generic(4294967296L, long long : 1); |
| 44 |
(void)_Generic(4294967296U, unsigned long long : 1); |
| 45 |
#endif |
| 46 |
} |
| 47 |
|
| 48 |
void test_octal_constants(void) { |
| 49 |
(void)_Generic(02, int : 1); |
| 50 |
(void)_Generic(02u, unsigned int : 1); |
| 51 |
(void)_Generic(02l, long : 1); |
| 52 |
(void)_Generic(02ul, unsigned long : 1); |
| 53 |
(void)_Generic(02ll, long long : 1); |
| 54 |
(void)_Generic(02ull, unsigned long long : 1); |
| 55 |
|
| 56 |
#if __INT_WIDTH__ == 16 |
| 57 |
#if __LONG_WIDTH__ > 16 |
| 58 |
(void)_Generic(0200000, long : 1); |
| 59 |
(void)_Generic(0200000U, unsigned long : 1); |
| 60 |
#else |
| 61 |
(void)_Generic(0200000, long long : 1); |
| 62 |
(void)_Generic(0200000U, unsigned long : 1); |
| 63 |
#endif // __LONG_WIDTH__ > 16 |
| 64 |
#elif __INT_WIDTH__ == 32 |
| 65 |
#if __LONG_WIDTH__ > 32 |
| 66 |
(void)_Generic(040000000000, long : 1); |
| 67 |
(void)_Generic(040000000000U, unsigned long : 1); |
| 68 |
#else |
| 69 |
(void)_Generic(040000000000, long long : 1); |
| 70 |
(void)_Generic(040000000000U, unsigned long long : 1); |
| 71 |
#endif // __LONG_WIDTH__ > 32 |
| 72 |
#endif |
| 73 |
|
| 74 |
#if __LONG_WIDTH__ > 32 |
| 75 |
(void)_Generic(040000000000L, long : 1); |
| 76 |
(void)_Generic(040000000000U, unsigned long : 1); |
| 77 |
#else |
| 78 |
(void)_Generic(040000000000L, long long : 1); |
| 79 |
(void)_Generic(040000000000U, unsigned long long : 1); |
| 80 |
#endif |
| 81 |
} |
| 82 |
|
| 83 |
void test_hexadecimal_constants(void) { |
| 84 |
(void)_Generic(0x2, int : 1); |
| 85 |
(void)_Generic(0x2u, unsigned int : 1); |
| 86 |
(void)_Generic(0x2l, long : 1); |
| 87 |
(void)_Generic(0x2ul, unsigned long : 1); |
| 88 |
(void)_Generic(0x2ll, long long : 1); |
| 89 |
(void)_Generic(0x2ull, unsigned long long : 1); |
| 90 |
|
| 91 |
#if __INT_WIDTH__ == 16 |
| 92 |
#if __LONG_WIDTH__ > 16 |
| 93 |
(void)_Generic(0x10000, long : 1); |
| 94 |
(void)_Generic(0x10000U, unsigned long : 1); |
| 95 |
#else |
| 96 |
(void)_Generic(0x10000, long long : 1); |
| 97 |
(void)_Generic(0x10000U, unsigned long : 1); |
| 98 |
#endif // __LONG_WIDTH__ > 16 |
| 99 |
#elif __INT_WIDTH__ == 32 |
| 100 |
#if __LONG_WIDTH__ > 32 |
| 101 |
(void)_Generic(0x100000000, long : 1); |
| 102 |
(void)_Generic(0x100000000U, unsigned long : 1); |
| 103 |
#else |
| 104 |
(void)_Generic(0x100000000, long long : 1); |
| 105 |
(void)_Generic(0x100000000U, unsigned long long : 1); |
| 106 |
#endif // __LONG_WIDTH__ > 32 |
| 107 |
#endif |
| 108 |
|
| 109 |
#if __LONG_WIDTH__ > 32 |
| 110 |
(void)_Generic(0x100000000L, long : 1); |
| 111 |
(void)_Generic(0x100000000U, unsigned long : 1); |
| 112 |
#else |
| 113 |
(void)_Generic(0x100000000L, long long : 1); |
| 114 |
(void)_Generic(0x100000000U, unsigned long long : 1); |
| 115 |
#endif |
| 116 |
} |