r370066 - Replace some custom C11 extension warnings with the generic warning.

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 27 07:41:40 PDT 2019


Author: aaronballman
Date: Tue Aug 27 07:41:39 2019
New Revision: 370066

URL: http://llvm.org/viewvc/llvm-project?rev=370066&view=rev
Log:
Replace some custom C11 extension warnings with the generic warning.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
    cfe/trunk/lib/Parse/ParseDecl.cpp
    cfe/trunk/lib/Parse/ParseDeclCXX.cpp
    cfe/trunk/lib/Parse/ParseExpr.cpp
    cfe/trunk/test/Parser/c11-noreturn.c
    cfe/trunk/test/Sema/generic-selection.c
    cfe/trunk/test/Sema/static-assert.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=370066&r1=370065&r2=370066&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Tue Aug 27 07:41:39 2019
@@ -119,8 +119,6 @@ def warn_microsoft_qualifiers_ignored :
   "qualifiers after comma in declarator list are ignored">,
   InGroup<IgnoredAttributes>;
 
-def ext_c11_generic_selection : Extension<
-  "generic selections are a C11-specific feature">, InGroup<C11>;
 def err_duplicate_default_assoc : Error<
   "duplicate default generic association">;
 def note_previous_default_assoc : Note<
@@ -129,8 +127,6 @@ def note_previous_default_assoc : Note<
 def ext_c11_feature : Extension<
   "'%0' is a C11 extension">, InGroup<C11>;
 
-def ext_c11_noreturn : Extension<
-  "_Noreturn functions are a C11-specific feature">, InGroup<C11>;
 def err_c11_noreturn_misplaced : Error<
   "'_Noreturn' keyword must precede function declarator">;
 
@@ -374,8 +370,6 @@ def err_unexpected_token_in_nested_name_
   "'%0' cannot be a part of nested name specifier; did you mean ':'?">;
 def err_bool_redeclaration : Error<
   "redeclaration of C++ built-in type 'bool'">;
-def ext_c11_static_assert : Extension<
-  "_Static_assert is a C11-specific feature">, InGroup<C11>;
 def warn_cxx98_compat_static_assert : Warning<
   "static_assert declarations are incompatible with C++98">,
   InGroup<CXX98Compat>, DefaultIgnore;

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=370066&r1=370065&r2=370066&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Tue Aug 27 07:41:39 2019
@@ -3626,7 +3626,7 @@ void Parser::ParseDeclarationSpecifiers(
     }
     case tok::kw__Noreturn:
       if (!getLangOpts().C11)
-        Diag(Loc, diag::ext_c11_noreturn);
+        Diag(Tok, diag::ext_c11_feature) << Tok.getName();
       isInvalid = DS.setFunctionSpecNoreturn(Loc, PrevSpec, DiagID);
       break;
 

Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=370066&r1=370065&r2=370066&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Tue Aug 27 07:41:39 2019
@@ -862,7 +862,7 @@ Decl *Parser::ParseStaticAssertDeclarati
          "Not a static_assert declaration");
 
   if (Tok.is(tok::kw__Static_assert) && !getLangOpts().C11)
-    Diag(Tok, diag::ext_c11_static_assert);
+    Diag(Tok, diag::ext_c11_feature) << Tok.getName();
   if (Tok.is(tok::kw_static_assert))
     Diag(Tok, diag::warn_cxx98_compat_static_assert);
 

Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=370066&r1=370065&r2=370066&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Tue Aug 27 07:41:39 2019
@@ -2733,11 +2733,10 @@ ExprResult Parser::ParseStringLiteralExp
 /// \endverbatim
 ExprResult Parser::ParseGenericSelectionExpression() {
   assert(Tok.is(tok::kw__Generic) && "_Generic keyword expected");
-  SourceLocation KeyLoc = ConsumeToken();
-
   if (!getLangOpts().C11)
-    Diag(KeyLoc, diag::ext_c11_generic_selection);
+    Diag(Tok, diag::ext_c11_feature) << Tok.getName();
 
+  SourceLocation KeyLoc = ConsumeToken();
   BalancedDelimiterTracker T(*this, tok::l_paren);
   if (T.expectAndConsume())
     return ExprError();

Modified: cfe/trunk/test/Parser/c11-noreturn.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/c11-noreturn.c?rev=370066&r1=370065&r2=370066&view=diff
==============================================================================
--- cfe/trunk/test/Parser/c11-noreturn.c (original)
+++ cfe/trunk/test/Parser/c11-noreturn.c Tue Aug 27 07:41:39 2019
@@ -15,4 +15,4 @@ _Noreturn int; // expected-error {{'_Nor
 _Noreturn struct S; // expected-error {{'_Noreturn' can only appear on functions}}
 _Noreturn enum E { e }; // expected-error {{'_Noreturn' can only appear on functions}}
 
-// CHECK-EXT: _Noreturn functions are a C11-specific feature
+// CHECK-EXT: '_Noreturn' is a C11 extension

Modified: cfe/trunk/test/Sema/generic-selection.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/generic-selection.c?rev=370066&r1=370065&r2=370066&view=diff
==============================================================================
--- cfe/trunk/test/Sema/generic-selection.c (original)
+++ cfe/trunk/test/Sema/generic-selection.c Tue Aug 27 07:41:39 2019
@@ -1,40 +1,43 @@
 // RUN: %clang_cc1 -std=c11 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c99 -pedantic -fsyntax-only -verify=expected,ext %s
 
 void g(void);
 
 void foo(int n) {
-  (void) _Generic(0,
+  (void) _Generic(0, // ext-warning {{'_Generic' is a C11 extension}}
       struct A: 0, // expected-error {{type 'struct A' in generic association incomplete}}
       void(): 0,   // expected-error {{type 'void ()' in generic association not an object type}}
       int[n]: 0);  // expected-error {{type 'int [n]' in generic association is a variably modified type}}
 
-  (void) _Generic(0,
+  (void) _Generic(0, // ext-warning {{'_Generic' is a C11 extension}}
       void (*)():     0,  // expected-note {{compatible type 'void (*)()' specified here}}
       void (*)(void): 0); // expected-error {{type 'void (*)(void)' in generic association compatible with previously specified type 'void (*)()'}}
 
-  (void) _Generic((void (*)()) 0, // expected-error {{controlling expression type 'void (*)()' compatible with 2 generic association types}}
+  (void) _Generic((void (*)()) 0, // expected-error {{controlling expression type 'void (*)()' compatible with 2 generic association types}} \
+                                  // ext-warning {{'_Generic' is a C11 extension}}
       void (*)(int):  0,  // expected-note {{compatible type 'void (*)(int)' specified here}}
       void (*)(void): 0); // expected-note {{compatible type 'void (*)(void)' specified here}}
 
-  (void) _Generic(0, // expected-error {{controlling expression type 'int' not compatible with any generic association type}}
+  (void) _Generic(0, // expected-error {{controlling expression type 'int' not compatible with any generic association type}} \
+                     // ext-warning {{'_Generic' is a C11 extension}}
       char: 0, short: 0, long: 0);
 
-  int a1[_Generic(0, int: 1, short: 2, float: 3, default: 4) == 1 ? 1 : -1];
-  int a2[_Generic(0, default: 1, short: 2, float: 3, int: 4) == 4 ? 1 : -1];
-  int a3[_Generic(0L, int: 1, short: 2, float: 3, default: 4) == 4 ? 1 : -1];
-  int a4[_Generic(0L, default: 1, short: 2, float: 3, int: 4) == 1 ? 1 : -1];
-  int a5[_Generic(0, int: 1, short: 2, float: 3) == 1 ? 1 : -1];
-  int a6[_Generic(0, short: 1, float: 2, int: 3) == 3 ? 1 : -1];
+  int a1[_Generic(0, int: 1, short: 2, float: 3, default: 4) == 1 ? 1 : -1]; // ext-warning {{'_Generic' is a C11 extension}}
+  int a2[_Generic(0, default: 1, short: 2, float: 3, int: 4) == 4 ? 1 : -1]; // ext-warning {{'_Generic' is a C11 extension}}
+  int a3[_Generic(0L, int: 1, short: 2, float: 3, default: 4) == 4 ? 1 : -1]; // ext-warning {{'_Generic' is a C11 extension}}
+  int a4[_Generic(0L, default: 1, short: 2, float: 3, int: 4) == 1 ? 1 : -1]; // ext-warning {{'_Generic' is a C11 extension}}
+  int a5[_Generic(0, int: 1, short: 2, float: 3) == 1 ? 1 : -1]; // ext-warning {{'_Generic' is a C11 extension}}
+  int a6[_Generic(0, short: 1, float: 2, int: 3) == 3 ? 1 : -1]; // ext-warning {{'_Generic' is a C11 extension}}
 
-  int a7[_Generic("test", char *: 1, default: 2) == 1 ? 1 : -1];
-  int a8[_Generic(g, void (*)(void): 1, default: 2) == 1 ? 1 : -1];
+  int a7[_Generic("test", char *: 1, default: 2) == 1 ? 1 : -1]; // ext-warning {{'_Generic' is a C11 extension}}
+  int a8[_Generic(g, void (*)(void): 1, default: 2) == 1 ? 1 : -1]; // ext-warning {{'_Generic' is a C11 extension}}
 
   const int i = 12;
-  int a9[_Generic(i, int: 1, default: 2) == 1 ? 1 : -1];
+  int a9[_Generic(i, int: 1, default: 2) == 1 ? 1 : -1]; // ext-warning {{'_Generic' is a C11 extension}}
 
   // This is expected to not trigger any diagnostics because the controlling
   // expression is not evaluated.
-  (void)_Generic(*(int *)0, int: 1);
+  (void)_Generic(*(int *)0, int: 1); // ext-warning {{'_Generic' is a C11 extension}}
 }
 
 int __attribute__((overloadable)) test (int);
@@ -42,5 +45,5 @@ double __attribute__((overloadable)) tes
 char testc(char);
 
 void PR30201(void) {
-  _Generic(4, char:testc, default:test)(4);
+  _Generic(4, char:testc, default:test)(4); // ext-warning {{'_Generic' is a C11 extension}}
 }

Modified: cfe/trunk/test/Sema/static-assert.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/static-assert.c?rev=370066&r1=370065&r2=370066&view=diff
==============================================================================
--- cfe/trunk/test/Sema/static-assert.c (original)
+++ cfe/trunk/test/Sema/static-assert.c Tue Aug 27 07:41:39 2019
@@ -1,25 +1,30 @@
 // RUN: %clang_cc1 -std=c11 -fsyntax-only -verify %s
-// RUN: %clang_cc1 -xc++ -std=c++11 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c99 -pedantic -fsyntax-only -verify=expected,ext %s
+// RUN: %clang_cc1 -xc++ -std=c++11 -pedantic -fsyntax-only -verify=expected,ext %s
 
-_Static_assert("foo", "string is nonzero");
+_Static_assert("foo", "string is nonzero"); // ext-warning {{'_Static_assert' is a C11 extension}}
 #ifndef __cplusplus
 // expected-error at -2 {{static_assert expression is not an integral constant expression}}
 #endif
 
-_Static_assert(1, "1 is nonzero");
-_Static_assert(0, "0 is nonzero"); // expected-error {{static_assert failed "0 is nonzero"}}
+_Static_assert(1, "1 is nonzero"); // ext-warning {{'_Static_assert' is a C11 extension}}
+_Static_assert(0, "0 is nonzero"); // expected-error {{static_assert failed "0 is nonzero"}} \
+                                   // ext-warning {{'_Static_assert' is a C11 extension}}
 
 void foo(void) {
-  _Static_assert(1, "1 is nonzero");
-  _Static_assert(0, "0 is nonzero"); // expected-error {{static_assert failed "0 is nonzero"}}
+  _Static_assert(1, "1 is nonzero"); // ext-warning {{'_Static_assert' is a C11 extension}}
+  _Static_assert(0, "0 is nonzero"); // expected-error {{static_assert failed "0 is nonzero"}} \
+                                     // ext-warning {{'_Static_assert' is a C11 extension}}
 }
 
-_Static_assert(1, invalid); // expected-error {{expected string literal for diagnostic message in static_assert}}
+_Static_assert(1, invalid); // expected-error {{expected string literal for diagnostic message in static_assert}} \
+                            // ext-warning {{'_Static_assert' is a C11 extension}}
 
 struct A {
   int a;
-  _Static_assert(1, "1 is nonzero");
-  _Static_assert(0, "0 is nonzero"); // expected-error {{static_assert failed "0 is nonzero"}}
+  _Static_assert(1, "1 is nonzero"); // ext-warning {{'_Static_assert' is a C11 extension}}
+  _Static_assert(0, "0 is nonzero"); // expected-error {{static_assert failed "0 is nonzero"}} \
+                                     // ext-warning {{'_Static_assert' is a C11 extension}}
 };
 
 #ifdef __cplusplus
@@ -36,7 +41,12 @@ struct A {
     _Static_assert(sizeof(T1) == sizeof(T2), "type size mismatch"); \
   }
 
-typedef UNION(unsigned, struct A) U1;
-UNION(char[2], short) u2 = { .one = { 'a', 'b' } };
-typedef UNION(char, short) U3; // expected-error {{static_assert failed due to requirement 'sizeof(char) == sizeof(short)' "type size mismatch"}}
-typedef UNION(float, 0.5f) U4; // expected-error {{expected a type}}
+typedef UNION(unsigned, struct A) U1; // ext-warning 3 {{'_Static_assert' is a C11 extension}}
+UNION(char[2], short) u2 = { .one = { 'a', 'b' } }; // ext-warning 3 {{'_Static_assert' is a C11 extension}}
+#if defined(__cplusplus)
+// ext-warning at -2 {{designated initializers are a C99 feature}}
+#endif
+typedef UNION(char, short) U3; // expected-error {{static_assert failed due to requirement 'sizeof(char) == sizeof(short)' "type size mismatch"}} \
+                               // ext-warning 3 {{'_Static_assert' is a C11 extension}}
+typedef UNION(float, 0.5f) U4; // expected-error {{expected a type}} \
+                               // ext-warning 3 {{'_Static_assert' is a C11 extension}}




More information about the cfe-commits mailing list