diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2013-09-18 23:23:17 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2013-09-18 23:23:17 +0000 |
commit | 626956111d630f90a0456e4c8751eb48f1067403 (patch) | |
tree | 9e5891d4f2f6bf724941df5d4ead55c04b1cb602 /clang/test | |
parent | f9edb00fa49c178f91bf5a367a604c7c88fa4518 (diff) | |
download | bcm5719-llvm-626956111d630f90a0456e4c8751eb48f1067403.tar.gz bcm5719-llvm-626956111d630f90a0456e4c8751eb48f1067403.zip |
Add specific warning flags for GNU ext in Sema.
This patch adds the following, more specific warning flags:
gnu-anonymous-struct
gnu-compound-literal-initializer
gnu-empty-struct
gnu-flexible-array-initializer
gnu-flexible-array-union-member
gnu-folding-constant
redeclared-class-member
gnu-redeclared-enum
gnu-union-cast
gnu-variable-sized-type-not-at-end
Patch by Peter Lewis.
llvm-svn: 190972
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/Misc/warning-flags-tree.c | 5 | ||||
-rw-r--r-- | clang/test/Misc/warning-flags.c | 2 | ||||
-rw-r--r-- | clang/test/Sema/gnu-flags.c | 113 | ||||
-rw-r--r-- | clang/test/SemaCXX/gnu-flags.cpp | 76 |
4 files changed, 179 insertions, 17 deletions
diff --git a/clang/test/Misc/warning-flags-tree.c b/clang/test/Misc/warning-flags-tree.c index a64e942f20b..d71c9f618b4 100644 --- a/clang/test/Misc/warning-flags-tree.c +++ b/clang/test/Misc/warning-flags-tree.c @@ -36,11 +36,8 @@ // CHECK-GNU: ext_gnu_array_range // CHECK-GNU: ext_gnu_missing_equal_designator // CHECK-GNU: ext_gnu_old_style_field_designator -// CHECK-GNU: -Wvla +// CHECK-GNU: -Wvla-extension // CHECK-GNU: ext_vla -// CHECK-GNU: ext_array_init_copy -// CHECK-GNU: ext_empty_struct_union -// CHECK-GNU: ext_expr_not_ice // There are more GNU extensions but we don't need to check them all. // RUN: diagtool tree --flags-only -Wgnu | FileCheck -check-prefix CHECK-FLAGS-ONLY %s diff --git a/clang/test/Misc/warning-flags.c b/clang/test/Misc/warning-flags.c index 3ba445042e3..d7555822cc1 100644 --- a/clang/test/Misc/warning-flags.c +++ b/clang/test/Misc/warning-flags.c @@ -156,4 +156,4 @@ CHECK-NEXT: warn_weak_import The list of warnings in -Wpedantic should NEVER grow. -CHECK: Number in -Wpedantic (not covered by other -W flags): 29 +CHECK: Number in -Wpedantic (not covered by other -W flags): 28 diff --git a/clang/test/Sema/gnu-flags.c b/clang/test/Sema/gnu-flags.c index 065fc2f9f14..e7588b7b371 100644 --- a/clang/test/Sema/gnu-flags.c +++ b/clang/test/Sema/gnu-flags.c @@ -1,19 +1,32 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s -DALIGNOF +// RUN: %clang_cc1 -fsyntax-only -verify %s -DNONE -Wno-gnu // RUN: %clang_cc1 -fsyntax-only -verify %s -DALL -Wgnu -// RUN: %clang_cc1 -fsyntax-only -verify %s -DALL \ +// RUN: %clang_cc1 -fsyntax-only -verify %s -DALL -Wno-gnu \ // RUN: -Wgnu-alignof-expression -Wgnu-case-range -Wgnu-complex-integer -Wgnu-conditional-omitted-operand \ -// RUN: -Wgnu-empty-initializer -Wgnu-label-as-value -Wgnu-statement-expression +// RUN: -Wgnu-empty-initializer -Wgnu-label-as-value -Wgnu-statement-expression \ +// RUN: -Wgnu-compound-literal-initializer -Wgnu-flexible-array-initializer \ +// RUN: -Wgnu-redeclared-enum -Wgnu-folding-constant -Wgnu-empty-struct \ +// RUN: -Wgnu-union-cast -Wgnu-variable-sized-type-not-at-end // RUN: %clang_cc1 -fsyntax-only -verify %s -DNONE -Wgnu \ // RUN: -Wno-gnu-alignof-expression -Wno-gnu-case-range -Wno-gnu-complex-integer -Wno-gnu-conditional-omitted-operand \ -// RUN: -Wno-gnu-empty-initializer -Wno-gnu-label-as-value -Wno-gnu-statement-expression -// RUNNOT: %clang_cc1 -fsyntax-only -verify %s -DALIGNOF -Wgnu-alignof-expression -// RUNNOT: %clang_cc1 -fsyntax-only -verify %s -DNONE -Wno-gnu-alignof-expression -// RUNNOT: %clang_cc1 -fsyntax-only -verify %s -DALIGNOF -DCASERANGE -Wgnu-case-range -// RUNNOT: %clang_cc1 -fsyntax-only -verify %s -DALIGNOF -DCOMPLEXINT -Wgnu-complex-integer -// RUNNOT: %clang_cc1 -fsyntax-only -verify %s -DALIGNOF -DOMITTEDOPERAND -Wgnu-conditional-omitted-operand -// RUNNOT: %clang_cc1 -fsyntax-only -verify %s -DALIGNOF -DEMPTYINIT -Wgnu-empty-initializer -// RUNNOT: %clang_cc1 -fsyntax-only -verify %s -DALIGNOF -DLABELVALUE -Wgnu-label-as-value -// RUNNOT: %clang_cc1 -fsyntax-only -verify %s -DALIGNOF -DSTATEMENTEXP -Wgnu-statement-expression +// RUN: -Wno-gnu-empty-initializer -Wno-gnu-label-as-value -Wno-gnu-statement-expression \ +// RUN: -Wno-gnu-compound-literal-initializer -Wno-gnu-flexible-array-initializer \ +// RUN: -Wno-gnu-redeclared-enum -Wno-gnu-folding-constant -Wno-gnu-empty-struct \ +// RUN: -Wno-gnu-union-cast -Wno-gnu-variable-sized-type-not-at-end +// Additional disabled tests: +// %clang_cc1 -fsyntax-only -verify %s -DALIGNOF -Wno-gnu -Wgnu-alignof-expression +// %clang_cc1 -fsyntax-only -verify %s -DCASERANGE -Wno-gnu -Wgnu-case-range +// %clang_cc1 -fsyntax-only -verify %s -DCOMPLEXINT -Wno-gnu -Wgnu-complex-integer +// %clang_cc1 -fsyntax-only -verify %s -DOMITTEDOPERAND -Wno-gnu -Wgnu-conditional-omitted-operand +// %clang_cc1 -fsyntax-only -verify %s -DEMPTYINIT -Wno-gnu -Wgnu-empty-initializer +// %clang_cc1 -fsyntax-only -verify %s -DLABELVALUE -Wno-gnu -Wgnu-label-as-value +// %clang_cc1 -fsyntax-only -verify %s -DSTATEMENTEXP -Wno-gnu -Wgnu-statement-expression +// %clang_cc1 -fsyntax-only -verify %s -DCOMPOUNDLITERALINITIALIZER -Wno-gnu -Wgnu-compound-literal-initializer +// %clang_cc1 -fsyntax-only -verify %s -DFLEXIBLEARRAYINITIALIZER -Wno-gnu -Wgnu-flexible-array-initializer +// %clang_cc1 -fsyntax-only -verify %s -DREDECLAREDENUM -Wno-gnu -Wgnu-redeclared-enum +// %clang_cc1 -fsyntax-only -verify %s -DUNIONCAST -Wno-gnu -Wgnu-union-cast +// %clang_cc1 -fsyntax-only -verify %s -DVARIABLESIZEDTYPENOTATEND -Wno-gnu -Wgnu-variable-sized-type-not-at-end +// %clang_cc1 -fsyntax-only -verify %s -DFOLDINGCONSTANT -Wno-gnu -Wgnu-folding-constant +// %clang_cc1 -fsyntax-only -verify %s -DEMPTYSTRUCT -Wno-gnu -Wgnu-empty-struct #if NONE // expected-no-diagnostics @@ -72,6 +85,7 @@ foo: goto *ptr; } + #if ALL || STATEMENTEXP // expected-warning@+5 {{use of GNU statement expression extension}} #endif @@ -80,3 +94,78 @@ void statementexp() { int a = ({ 1; }); } + + +#if ALL || COMPOUNDLITERALINITIALIZER +// expected-warning@+4 {{initialization of an array of type 'int [5]' from a compound literal of type 'int [5]' is a GNU extension}} +#endif + +typedef int int5[5]; +int cli[5] = (int[]){1, 2, 3, 4, 5}; + + +#if ALL || FLEXIBLEARRAYINITIALIZER +// expected-note@+6 {{initialized flexible array member 'y' is here}} +// expected-warning@+6 {{flexible array initialization is a GNU extension}} +#endif + +struct fai { + int x; + int y[]; +} fai = { 1, { 2, 3, 4 } }; + + +#if ALL || FOLDINGCONSTANT +// expected-warning@+5 {{expression is not an integer constant expression; folding it to a constant is a GNU extension}} +// expected-warning@+7 {{variable length array folded to constant array as an extension}} +#endif + +enum { + fic = (int)(0.75 * 1000 * 1000) +}; +static const int size = 100; +void foo(void) { int data[size]; } + +#if ALL || REDECLAREDENUM +// expected-note@+4 {{previous definition is here}} +// expected-warning@+8 {{redeclaration of already-defined enum 'RE' is a GNU extension}} +#endif + +enum RE { + Val1, + Val2 +}; + +enum RE; + + +#if ALL || UNIONCAST +// expected-warning@+4 {{cast to union type is a GNU extension}} +#endif + +union uc { int i; unsigned : 3; }; +union uc w = (union uc)2; + + +#if ALL || VARIABLESIZEDTYPENOTATEND +// expected-warning@+8 {{field 'hdr' with variable sized type 'struct vst' not at the end of a struct or class is a GNU extension}} +#endif + +struct vst { + short tag_type; + char tag_data[]; +}; +struct vstnae { + struct vst hdr; + char data; +}; + + +#if ALL || EMPTYSTRUCT +// expected-warning@+4 {{empty struct is a GNU extension}} +// expected-warning@+4 {{struct without named members is a GNU extension}} +#endif + +const struct {} es; +struct {int:5;} swnm; + diff --git a/clang/test/SemaCXX/gnu-flags.cpp b/clang/test/SemaCXX/gnu-flags.cpp new file mode 100644 index 00000000000..05770c53704 --- /dev/null +++ b/clang/test/SemaCXX/gnu-flags.cpp @@ -0,0 +1,76 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s -DNONE -Wno-gnu +// RUN: %clang_cc1 -fsyntax-only -verify %s -DALL -Wgnu +// RUN: %clang_cc1 -fsyntax-only -verify %s -DALL -Wno-gnu \ +// RUN: -Wgnu-anonymous-struct -Wredeclared-class-member \ +// RUN: -Wgnu-flexible-array-union-member -Wgnu-folding-constant \ +// RUN: -Wgnu-empty-struct +// RUN: %clang_cc1 -fsyntax-only -verify %s -DNONE -Wgnu \ +// RUN: -Wno-gnu-anonymous-struct -Wno-redeclared-class-member \ +// RUN: -Wno-gnu-flexible-array-union-member -Wno-gnu-folding-constant \ +// RUN: -Wno-gnu-empty-struct +// Additional disabled tests: +// %clang_cc1 -fsyntax-only -verify %s -DANONYMOUSSTRUCT -Wno-gnu -Wgnu-anonymous-struct +// %clang_cc1 -fsyntax-only -verify %s -DREDECLAREDCLASSMEMBER -Wno-gnu -Wredeclared-class-member +// %clang_cc1 -fsyntax-only -verify %s -DFLEXIBLEARRAYUNIONMEMBER -Wno-gnu -Wgnu-flexible-array-union-member +// %clang_cc1 -fsyntax-only -verify %s -DFOLDINGCONSTANT -Wno-gnu -Wgnu-folding-constant +// %clang_cc1 -fsyntax-only -verify %s -DEMPTYSTRUCT -Wno-gnu -Wgnu-empty-struct + +#if NONE +// expected-no-diagnostics +#endif + + +#if ALL || ANONYMOUSSTRUCT +// expected-warning@+5 {{anonymous structs are a GNU extension}} +#endif + +struct as { + int x; + struct { + int a; + float b; + }; +}; + + +#if ALL || REDECLAREDCLASSMEMBER +// expected-note@+6 {{previous declaration is here}} +// expected-warning@+6 {{class member cannot be redeclared}} +#endif + +namespace rcm { + class A { + class X; + class X; + class X {}; + }; +} + + +#if ALL || FLEXIBLEARRAYUNIONMEMBER +// expected-warning@+6 {{flexible array member 'c1' in a union is a GNU extension}} +#endif + +struct faum { + int l; + union { + int c1[]; + }; +}; + + +#if ALL || FOLDINGCONSTANT +// expected-warning@+4 {{in-class initializer for static data member is not a constant expression; folding it to a constant is a GNU extension}} +#endif + +struct fic { + static const int B = int(0.75 * 1000 * 1000); +}; + + +#if ALL || EMPTYSTRUCT +// expected-warning@+3 {{flexible array member 'a' in otherwise empty struct is a GNU extension}} +#endif + +struct ofam {int a[];}; + |