Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / Sema / switch-1.c
blob95e64748fb1fbfdd4d4321ce377c903523db71a1
1 // RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-apple-darwin10 %s
2 // RUN: %clang_cc1 -x c++ -fsyntax-only -verify -triple x86_64-apple-darwin10 %s
3 // RUN: %clang_cc1 -x c++ -fsyntax-only -verify -triple x86_64-apple-darwin10 -std=c++98 %s
4 // RUN: %clang_cc1 -x c++ -fsyntax-only -verify -triple x86_64-apple-darwin10 -std=c++11 %s
6 int f(int i) {
7 switch (i) {
8 case 2147483647 + 2:
9 #if (__cplusplus <= 199711L) // C or C++03 or earlier modes
10 // expected-warning@-2 {{overflow in expression; result is -2147483647 with type 'int'}}
11 #else
12 // expected-error@-4 {{case value is not a constant expression}} \
13 // expected-note@-4 {{value 2147483649 is outside the range of representable values of type 'int'}}
14 #endif
15 return 1;
16 case 9223372036854775807L * 4:
17 #if (__cplusplus <= 199711L)
18 // expected-warning@-2 {{overflow in expression; result is -4 with type 'long'}}
19 #else
20 // expected-error@-4 {{case value is not a constant expression}} \
21 // expected-note@-4 {{value 36893488147419103228 is outside the range of representable values of type 'long'}}
22 #endif
23 return 2;
24 case (123456 *789012) + 1:
25 #if (__cplusplus <= 199711L)
26 // expected-warning@-2 {{overflow in expression; result is -1375982336 with type 'int'}}
27 #else
28 // expected-error@-4 {{case value is not a constant expression}} \
29 // expected-note@-4 {{value 97408265472 is outside the range of representable values of type 'int'}}
30 #endif
31 return 3;
32 case (2147483647*4)/4:
33 #if (__cplusplus <= 199711L)
34 // expected-warning@-2 {{overflow in expression; result is -4 with type 'int'}}
35 #else
36 // expected-error@-4 {{case value is not a constant expression}} \
37 // expected-note@-4 {{value 8589934588 is outside the range of representable values of type 'int'}}
38 #endif
39 case (2147483647*4)%4:
40 #if (__cplusplus <= 199711L)
41 // expected-warning@-2 {{overflow in expression; result is -4 with type 'int'}}
42 #else
43 // expected-error@-4 {{case value is not a constant expression}} \
44 // expected-note@-4 {{value 8589934588 is outside the range of representable values of type 'int'}}
45 #endif
46 return 4;
47 case 2147483647:
48 return 0;
50 return (i, 65537) * 65537; // expected-warning {{overflow in expression; result is 131073 with type 'int'}} \
51 // expected-warning {{left operand of comma operator has no effect}}
54 unsigned long long l = 65536 * 65536; // expected-warning {{overflow in expression; result is 0 with type 'int'}}
55 unsigned long long l2 = 65536 * (unsigned)65536;
56 unsigned long long l3 = 65536 * 65536ULL;