brintos

brintos / llvm-project-archived public Read only

0
0
Text · 9.0 KiB · a06d0a9 Raw
154 lines · c
1// RUN: %clang_cc1 -DX32TYPE=ULONG -triple powerpc-unknown-linux-gnu -std=c89 -x c %s -verify2// RUN: %clang_cc1 -DX32TYPE=ULONG -triple powerpc-unknown-linux-gnu -std=iso9899:199409 -x c %s -verify3// RUN: %clang_cc1 -DX32TYPE=ULONG -triple powerpc-unknown-linux-gnu -std=c++98 -x c++ %s -verify4// RUN: %clang_cc1 -DX32TYPE=LLONG -triple powerpc-unknown-linux-gnu -std=c99 -x c %s -verify5// RUN: %clang_cc1 -DX32TYPE=LLONG -triple powerpc-unknown-linux-gnu -std=c11 -x c %s -verify6// RUN: %clang_cc1 -DX32TYPE=LLONG -triple powerpc-unknown-linux-gnu -std=c++11 -x c++ %s -verify7// RUN: %clang_cc1 -DX32TYPE=LLONG -triple powerpc-unknown-linux-gnu -std=c++1y -x c++ %s -verify8// RUN: %clang_cc1 -DX32TYPE=LLONG -triple powerpc-unknown-linux-gnu -std=c++1z -x c++ %s -verify9// RUN: %clang_cc1 -DX64TYPE=ULONG -triple powerpc64-unknown-linux-gnu -std=c89 -x c %s -verify10// RUN: %clang_cc1 -DX64TYPE=ULONG -triple powerpc64-unknown-linux-gnu -std=iso9899:199409 -x c %s -verify11// RUN: %clang_cc1 -DX64TYPE=ULONG -triple powerpc64-unknown-linux-gnu -std=c++98 -x c++ %s -verify12// RUN: %clang_cc1 -DX64TYPE=ULLONG -triple powerpc64-unknown-linux-gnu -std=c99 -x c %s -verify13// RUN: %clang_cc1 -DX64TYPE=ULLONG -triple powerpc64-unknown-linux-gnu -std=c11 -x c %s -verify14// RUN: %clang_cc1 -DX64TYPE=ULLONG -triple powerpc64-unknown-linux-gnu -std=c++11 -x c++ %s -verify15// RUN: %clang_cc1 -DX64TYPE=ULLONG -triple powerpc64-unknown-linux-gnu -std=c++1y -x c++ %s -verify16// RUN: %clang_cc1 -DX64TYPE=ULLONG -triple powerpc64-unknown-linux-gnu -std=c++1z -x c++ %s -verify17 18#ifdef X64TYPE19#define X32TYPE long20#endif21 22#define IS_ULONG_ULONG 123#define IS_ULONG2(X) IS_ULONG_##X24#define IS_ULONG(X) IS_ULONG2(X)25 26#if !defined(X64TYPE) && !IS_ULONG(X32TYPE)27// expected-no-diagnostics28#endif29 30typedef unsigned long ULONG;31typedef long long LLONG;32typedef 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 ******************************************************************************/38extern X32TYPE x32;39extern __typeof__(2147483648) x32;40extern __typeof__(2147483648l) x32;41extern __typeof__(2147483648L) x32;42 43#if IS_ULONG(X32TYPE)44#if !__cplusplus45 46/******************************************************************************47 * Under pre-C99 ISO C, unsigned long is attempted for decimal integer literals48 * that do not have a suffix containing "u" or "U" if the literal does not fit49 * 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#else55 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#endif65#endif66 67 68#ifdef X64TYPE69 70/******************************************************************************71 * Test 2^63 as a decimal literal with no suffix and with the "l" and "L" cases.72 ******************************************************************************/73extern X64TYPE x64;74extern __typeof__(9223372036854775808) x64;75extern __typeof__(9223372036854775808l) x64;76extern __typeof__(9223372036854775808L) x64;77 78#if IS_ULONG(X64TYPE)79 80#if !__cplusplus81 82/******************************************************************************83 * Under pre-C99 ISO C, unsigned long is attempted for decimal integer literals84 * that do not have a suffix containing "u" or "U" if the literal does not fit85 * 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#else91 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#endif101#else102 103/******************************************************************************104 * The status quo in C99/C++11-and-later modes for the literals in question is105 * 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#endif111#endif112 113 114/******************************************************************************115 * Test preprocessor arithmetic with 2^31 as a decimal literal with no suffix116 * 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 signed122 * integer types within the controlling constant expression for conditional123 * inclusion, then it will also be signed with said modified range.124 ******************************************************************************/125#define EXPR(X) ((X - X) - 1 < 0)126#else127 128/******************************************************************************129 * Strictly speaking, in pre-C99/C++11 ISO C/C++, the preprocessor arithmetic is130 * evaluated with the range of long/unsigned long; however, both Clang and GCC131 * evaluate using 64-bits even when long/unsigned long are 32-bits outside of132 * preprocessing.133 *134 * If the range used becomes 32-bits, then this test will enforce the treatment135 * 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 is139 * affected by the modified range of the signed and unsigned integer types140 * within the controlling constant expression for conditional inclusion is141 * 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 a146                                                 // preprocessor "long" or the147                                                 // literals in question are148                                                 // unsigned149#endif150 151#if !(EXPR(2147483648) && EXPR(2147483648l) && EXPR(2147483648L))152#error Unexpected signedness or conversion behavior153#endif154