Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / Sema / gnu-flags.c
blob941d7084869decbaa3588280ffd90912af35b682
1 // RUN: %clang_cc1 -fsyntax-only -verify %s -DNONE -Wno-gnu
2 // RUN: %clang_cc1 -fsyntax-only -verify %s -DALL -Wgnu
3 // RUN: %clang_cc1 -fsyntax-only -verify %s -DALL -Wno-gnu \
4 // RUN: -Wgnu-alignof-expression -Wgnu-case-range -Wgnu-complex-integer -Wgnu-conditional-omitted-operand \
5 // RUN: -Wgnu-label-as-value -Wgnu-statement-expression \
6 // RUN: -Wgnu-compound-literal-initializer -Wgnu-flexible-array-initializer \
7 // RUN: -Wgnu-redeclared-enum -Wgnu-folding-constant -Wgnu-empty-struct \
8 // RUN: -Wgnu-union-cast -Wgnu-variable-sized-type-not-at-end
9 // RUN: %clang_cc1 -fsyntax-only -verify %s -DNONE -Wgnu \
10 // RUN: -Wno-gnu-alignof-expression -Wno-gnu-case-range -Wno-gnu-complex-integer -Wno-gnu-conditional-omitted-operand \
11 // RUN: -Wno-gnu-label-as-value -Wno-gnu-statement-expression \
12 // RUN: -Wno-gnu-compound-literal-initializer -Wno-gnu-flexible-array-initializer \
13 // RUN: -Wno-gnu-redeclared-enum -Wno-gnu-folding-constant -Wno-gnu-empty-struct \
14 // RUN: -Wno-gnu-union-cast -Wno-gnu-variable-sized-type-not-at-end
15 // Additional disabled tests:
16 // %clang_cc1 -fsyntax-only -verify %s -DALIGNOF -Wno-gnu -Wgnu-alignof-expression
17 // %clang_cc1 -fsyntax-only -verify %s -DCASERANGE -Wno-gnu -Wgnu-case-range
18 // %clang_cc1 -fsyntax-only -verify %s -DCOMPLEXINT -Wno-gnu -Wgnu-complex-integer
19 // %clang_cc1 -fsyntax-only -verify %s -DOMITTEDOPERAND -Wno-gnu -Wgnu-conditional-omitted-operand
20 // %clang_cc1 -fsyntax-only -verify %s -DLABELVALUE -Wno-gnu -Wgnu-label-as-value
21 // %clang_cc1 -fsyntax-only -verify %s -DSTATEMENTEXP -Wno-gnu -Wgnu-statement-expression
22 // %clang_cc1 -fsyntax-only -verify %s -DSTATEMENTEXPMACRO -Wno-gnu -Wgnu-statement-expression-from-macro-expansion
23 // %clang_cc1 -fsyntax-only -verify %s -DCOMPOUNDLITERALINITIALIZER -Wno-gnu -Wgnu-compound-literal-initializer
24 // %clang_cc1 -fsyntax-only -verify %s -DFLEXIBLEARRAYINITIALIZER -Wno-gnu -Wgnu-flexible-array-initializer
25 // %clang_cc1 -fsyntax-only -verify %s -DREDECLAREDENUM -Wno-gnu -Wgnu-redeclared-enum
26 // %clang_cc1 -fsyntax-only -verify %s -DUNIONCAST -Wno-gnu -Wgnu-union-cast
27 // %clang_cc1 -fsyntax-only -verify %s -DVARIABLESIZEDTYPENOTATEND -Wno-gnu -Wgnu-variable-sized-type-not-at-end
28 // %clang_cc1 -fsyntax-only -verify %s -DFOLDINGCONSTANT -Wno-gnu -Wgnu-folding-constant
29 // %clang_cc1 -fsyntax-only -verify %s -DEMPTYSTRUCT -Wno-gnu -Wgnu-empty-struct
31 #if NONE
32 // expected-no-diagnostics
33 #endif
36 #if ALL || ALIGNOF
37 // expected-warning@+4 {{'_Alignof' applied to an expression is a GNU extension}}
38 #endif
40 char align;
41 _Static_assert(_Alignof(align) > 0, "align's alignment is wrong");
44 #if ALL || CASERANGE
45 // expected-warning@+5 {{use of GNU case range extension}}
46 #endif
48 void caserange(int x) {
49 switch (x) {
50 case 42 ... 44: ;
55 #if ALL || COMPLEXINT
56 // expected-warning@+3 {{complex integer types are a GNU extension}}
57 #endif
59 _Complex short int complexint;
62 #if ALL || OMITTEDOPERAND
63 // expected-warning@+3 {{use of GNU ?: conditional expression extension, omitting middle operand}}
64 #endif
66 static const char* omittedoperand = (const char*)0 ?: "Null";
69 #if ALL || LABELVALUE
70 // expected-warning@+6 {{use of GNU address-of-label extension}}
71 // expected-warning@+7 {{use of GNU indirect-goto extension}}
72 #endif
74 void labelvalue(void) {
75 void *ptr;
76 ptr = &&foo;
77 foo:
78 goto *ptr;
82 #if ALL || STATEMENTEXP
83 // expected-warning@+5 {{use of GNU statement expression extension}}
84 #endif
86 void statementexp(void)
88 int a = ({ 1; });
91 #if ALL || STATEMENTEXP || STATEMENTEXPMACRO
92 // expected-warning@+5 {{use of GNU statement expression extension from macro expansion}}
93 #endif
95 #define STMT_EXPR_MACRO(a) ({ (a); })
96 void statementexprmacro(void) {
97 int a = STMT_EXPR_MACRO(1);
100 #if ALL || COMPOUNDLITERALINITIALIZER
101 // expected-warning@+4 {{initialization of an array of type 'int[5]' from a compound literal of type 'int[5]' is a GNU extension}}
102 #endif
104 typedef int int5[5];
105 int cli[5] = (int[]){1, 2, 3, 4, 5};
108 #if ALL || FLEXIBLEARRAYINITIALIZER
109 // expected-note@+6 {{initialized flexible array member 'y' is here}}
110 // expected-warning@+6 {{flexible array initialization is a GNU extension}}
111 #endif
113 struct fai {
114 int x;
115 int y[];
116 } fai = { 1, { 2, 3, 4 } };
119 #if ALL || FOLDINGCONSTANT
120 // expected-warning@+5 {{expression is not an integer constant expression; folding it to a constant is a GNU extension}}
121 // expected-warning@+7 {{variable length array folded to constant array as an extension}}
122 #endif
124 enum {
125 fic = (int)(0.75 * 1000 * 1000)
127 static const int size = 100;
128 int data[size];
130 void foo(void) { int data[size]; } // OK, always a VLA
132 #if ALL || REDECLAREDENUM
133 // expected-note@+4 {{previous definition is here}}
134 // expected-warning@+8 {{redeclaration of already-defined enum 'RE' is a GNU extension}}
135 #endif
137 enum RE {
138 Val1,
139 Val2
142 enum RE;
145 #if ALL || UNIONCAST
146 // expected-warning@+4 {{cast to union type is a GNU extension}}
147 #endif
149 union uc { int i; unsigned : 3; };
150 union uc w = (union uc)2;
153 #if ALL || VARIABLESIZEDTYPENOTATEND
154 // expected-warning@+8 {{field 'hdr' with variable sized type 'struct vst' not at the end of a struct or class is a GNU extension}}
155 #endif
157 struct vst {
158 short tag_type;
159 char tag_data[];
161 struct vstnae {
162 struct vst hdr;
163 char data;
167 #if ALL || EMPTYSTRUCT
168 // expected-warning@+4 {{empty struct is a GNU extension}}
169 // expected-warning@+4 {{struct without named members is a GNU extension}}
170 #endif
172 const struct {} es;
173 struct {int:5;} swnm;