annotate clang/test/Sema/switch-1.c @ 207:2e18cbf3894f

LLVM12
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 08 Jun 2021 06:07:14 +0900
parents 1d019706d866
children c4bab56944e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-apple-darwin10 %s
anatofuz
parents:
diff changeset
2 // RUN: %clang_cc1 -x c++ -fsyntax-only -verify -triple x86_64-apple-darwin10 %s
anatofuz
parents:
diff changeset
3 // RUN: %clang_cc1 -x c++ -fsyntax-only -verify -triple x86_64-apple-darwin10 -std=c++98 %s
anatofuz
parents:
diff changeset
4 // RUN: %clang_cc1 -x c++ -fsyntax-only -verify -triple x86_64-apple-darwin10 -std=c++11 %s
anatofuz
parents:
diff changeset
5 // rdar://11577384
anatofuz
parents:
diff changeset
6 // rdar://13423975
anatofuz
parents:
diff changeset
7
anatofuz
parents:
diff changeset
8 int f(int i) {
anatofuz
parents:
diff changeset
9 switch (i) {
anatofuz
parents:
diff changeset
10 case 2147483647 + 2:
anatofuz
parents:
diff changeset
11 #if (__cplusplus <= 199711L) // C or C++03 or earlier modes
anatofuz
parents:
diff changeset
12 // expected-warning@-2 {{overflow in expression; result is -2147483647 with type 'int'}}
anatofuz
parents:
diff changeset
13 #else
anatofuz
parents:
diff changeset
14 // expected-error@-4 {{case value is not a constant expression}} \
anatofuz
parents:
diff changeset
15 // expected-note@-4 {{value 2147483649 is outside the range of representable values of type 'int'}}
anatofuz
parents:
diff changeset
16 #endif
anatofuz
parents:
diff changeset
17 return 1;
anatofuz
parents:
diff changeset
18 case 9223372036854775807L * 4:
anatofuz
parents:
diff changeset
19 #if (__cplusplus <= 199711L)
anatofuz
parents:
diff changeset
20 // expected-warning@-2 {{overflow in expression; result is -4 with type 'long'}}
anatofuz
parents:
diff changeset
21 #else
anatofuz
parents:
diff changeset
22 // expected-error@-4 {{case value is not a constant expression}} \
anatofuz
parents:
diff changeset
23 // expected-note@-4 {{value 36893488147419103228 is outside the range of representable values of type 'long'}}
anatofuz
parents:
diff changeset
24 #endif
anatofuz
parents:
diff changeset
25 return 2;
anatofuz
parents:
diff changeset
26 case (123456 *789012) + 1:
anatofuz
parents:
diff changeset
27 #if (__cplusplus <= 199711L)
anatofuz
parents:
diff changeset
28 // expected-warning@-2 {{overflow in expression; result is -1375982336 with type 'int'}}
anatofuz
parents:
diff changeset
29 #else
anatofuz
parents:
diff changeset
30 // expected-error@-4 {{case value is not a constant expression}} \
anatofuz
parents:
diff changeset
31 // expected-note@-4 {{value 97408265472 is outside the range of representable values of type 'int'}}
anatofuz
parents:
diff changeset
32 #endif
anatofuz
parents:
diff changeset
33 return 3;
anatofuz
parents:
diff changeset
34 case (2147483647*4)/4:
anatofuz
parents:
diff changeset
35 #if (__cplusplus <= 199711L)
anatofuz
parents:
diff changeset
36 // expected-warning@-2 {{overflow in expression; result is -4 with type 'int'}}
anatofuz
parents:
diff changeset
37 #else
anatofuz
parents:
diff changeset
38 // expected-error@-4 {{case value is not a constant expression}} \
anatofuz
parents:
diff changeset
39 // expected-note@-4 {{value 8589934588 is outside the range of representable values of type 'int'}}
anatofuz
parents:
diff changeset
40 #endif
anatofuz
parents:
diff changeset
41 case (2147483647*4)%4:
anatofuz
parents:
diff changeset
42 #if (__cplusplus <= 199711L)
anatofuz
parents:
diff changeset
43 // expected-warning@-2 {{overflow in expression; result is -4 with type 'int'}}
anatofuz
parents:
diff changeset
44 #else
anatofuz
parents:
diff changeset
45 // expected-error@-4 {{case value is not a constant expression}} \
anatofuz
parents:
diff changeset
46 // expected-note@-4 {{value 8589934588 is outside the range of representable values of type 'int'}}
anatofuz
parents:
diff changeset
47 #endif
anatofuz
parents:
diff changeset
48 return 4;
anatofuz
parents:
diff changeset
49 case 2147483647:
anatofuz
parents:
diff changeset
50 return 0;
anatofuz
parents:
diff changeset
51 }
anatofuz
parents:
diff changeset
52 return (i, 65537) * 65537; // expected-warning {{overflow in expression; result is 131073 with type 'int'}} \
anatofuz
parents:
diff changeset
53 // expected-warning {{expression result unused}}
anatofuz
parents:
diff changeset
54 }
anatofuz
parents:
diff changeset
55
anatofuz
parents:
diff changeset
56 // rdar://18405357
anatofuz
parents:
diff changeset
57 unsigned long long l = 65536 * 65536; // expected-warning {{overflow in expression; result is 0 with type 'int'}}
anatofuz
parents:
diff changeset
58 unsigned long long l2 = 65536 * (unsigned)65536;
anatofuz
parents:
diff changeset
59 unsigned long long l3 = 65536 * 65536ULL;