1 // RUN: %clang_cc1 %s -fsyntax-only -verify -triple x86_64-pc-linux-gnu -Wno-unevaluated-expression
2
3 typedef unsigned __uint32_t;
4
5 #define __byte_swap_int_var(x) \
6 __extension__ ({ register __uint32_t __X = (x); \
7 __asm ("bswap %0" : "+r" (__X)); \
8 __X; })
9
test(int _x)10 int test(int _x) {
11 return (__byte_swap_int_var(_x));
12 }
13
14 // PR2374
test2(void)15 int test2(void) { return ({L:5;}); }
test3(void)16 int test3(void) { return ({ {5;} }); } // expected-error {{returning 'void' from a function with incompatible result type 'int'}}\
17 // expected-warning {{expression result unused}}
test4(void)18 int test4(void) { return ({ ({5;}); }); }
test5(void)19 int test5(void) { return ({L1: L2: L3: 5;}); }
test6(void)20 int test6(void) { return ({5;}); }
test7(void)21 void test7(void) { ({5;}); } // expected-warning {{expression result unused}}
22
23 // PR3062
24 int test8[({10;})]; // expected-error {{statement expression not allowed at file scope}}
25
26 // PR3912
test9(const void * P)27 void test9(const void *P) {
28 __builtin_prefetch(P);
29 }
30
31
test10(void)32 void *test10(void) {
33 bar:
34 return &&bar; // expected-warning {{returning address of label, which is local}}
35 }
36
37 // PR38569: Don't warn when returning a label from a statement expression.
38 void test10_logpc(void*);
test10a(void)39 void test10a(void) {
40 test10_logpc(({
41 my_pc:
42 &&my_pc;
43 }));
44 }
45
46 // PR6034
test11(int bit)47 void test11(int bit) {
48 switch (bit)
49 switch (env->fpscr) // expected-error {{use of undeclared identifier 'env'}}
50 {
51 }
52 }
53
54 enum Numbers { kOne, kTwo, kThree, kFour};
test12(enum Numbers num)55 int test12(enum Numbers num) {
56 switch (num == kOne) {// expected-warning {{switch condition has boolean value}}
57 default:
58 case kThree:
59 break;
60 }
61 }
62
63
64 enum x { a, b, c, d, e, f, g };
65
foo(enum x X)66 void foo(enum x X) {
67 switch (X) { // expected-warning {{enumeration value 'g' not handled in switch}}
68 case a:
69 case b:
70 case c:
71 case d:
72 case e:
73 case f:
74 break;
75 }
76
77 switch (X) { // expected-warning {{enumeration values 'f' and 'g' not handled in switch}}
78 case a:
79 case b:
80 case c:
81 case d:
82 case e:
83 break;
84 }
85
86 switch (X) { // expected-warning {{enumeration values 'e', 'f', and 'g' not handled in switch}}
87 case a:
88 case b:
89 case c:
90 case d:
91 break;
92 }
93
94 switch (X) { // expected-warning {{5 enumeration values not handled in switch: 'c', 'd', 'e'...}}
95 case a:
96 case b:
97 break;
98 }
99 }
100
test_pr8880(void)101 int test_pr8880(void) {
102 int first = 1;
103 for ( ; ({ if (first) { first = 0; continue; } 0; }); )
104 return 0;
105 return 1;
106 }
107
108 // In PR22849, we considered __ptr to be a static data member of the anonymous
109 // union. Now we declare it in the parent DeclContext.
test_pr22849(void)110 void test_pr22849(void) {
111 struct Bug {
112 typeof(({ unsigned long __ptr; (int *)(0); })) __val;
113 union Nested {
114 typeof(({ unsigned long __ptr; (int *)(0); })) __val;
115 } n;
116 };
117 enum E {
118 SIZE = sizeof(({unsigned long __ptr; __ptr;}))
119 };
120 }
121
122 // GCC ignores empty statements at the end of compound expressions where the
123 // result type is concerned.
test13(void)124 void test13(void) {
125 int a;
126 a = ({ 1; });
127 a = ({1;; });
128 a = ({int x = 1; (void)x; }); // expected-error {{assigning to 'int' from incompatible type 'void'}}
129 a = ({int x = 1; (void)x;; }); // expected-error {{assigning to 'int' from incompatible type 'void'}}
130 }
131
test14(void)132 void test14(void) { return ({}); }
test15(void)133 void test15(void) {
134 return ({;;;; });
135 }
test16(void)136 void test16(void) {
137 return ({test:;; });
138 }
139