aaron.ballman created this revision.
aaron.ballman added reviewers: porglezomp, jyknight, nickdesaulniers.
Herald added a project: All.
aaron.ballman requested review of this revision.
Herald added a project: clang.

https://github.com/llvm/llvm-project/commit/5d8aaad4452f60ba8902e921d9bed606713a8f26
 removed the warning group as the functionality is no longer a GNU extension. 
However, users have asked for the warning group to be supported so that code 
transitioning from Clang 16 to Clang 17 has an easier migration path when 
compiling with `-Werror`. This patch restores the warning group, but as an 
ignored warning group because the functionality is now always considered to be 
a C extension rather than a GNU extension. This allows users to do `-Werror 
-pedantic -Wno-gnu-empty-intializer -Wno-c2x-extensions` to silence the 
diagnostics in both Clang 16 and Clang 17.

This patch has no release notes because this is changing the behavior of 
something changed during the Clang 17 cycle.

Fixes https://github.com/llvm/llvm-project/issues/64357


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157503

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/test/Sema/empty-init.c


Index: clang/test/Sema/empty-init.c
===================================================================
--- /dev/null
+++ clang/test/Sema/empty-init.c
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 %s -std=c2x -Wall -pedantic -fsyntax-only -verify=good
+// RUN: %clang_cc1 %s -std=c2x -Wpre-c2x-compat -fsyntax-only -verify=c2x
+// RUN: %clang_cc1 %s -std=c2x -Wpre-c2x-compat -Wno-gnu-empty-initializer 
-fsyntax-only -verify=c2x
+// RUN: %clang_cc1 %s -std=c2x -Wgnu-empty-initializer -fsyntax-only 
-verify=good
+// RUN: %clang_cc1 %s -std=c17 -Wall -pedantic -fsyntax-only -verify=c2x-ext
+// RUN: %clang_cc1 %s -std=c17 -Wgnu-empty-initializer -fsyntax-only 
-verify=good
+// RUN: %clang_cc1 %s -std=c17 -Wc2x-extensions -fsyntax-only -verify=c2x-ext
+// RUN: %clang_cc1 %s -std=c17 -Wpre-c2x-compat -fsyntax-only -verify=good
+
+// good-no-diagnostics
+
+// Empty brace initialization used to be a GNU extension, but the feature was
+// added to C2x. We now treat empty initialization as a C extension rather than
+// a GNU extension. Thus, -Wgnu-empty-initializer is always silently ignored.
+
+struct S {
+  int a;
+};
+
+struct S s = {};     /* c2x-warning {{use of an empty initializer is 
incompatible with C standards before C2x}}
+                        c2x-ext-warning {{use of an empty initializer is a C2x 
extension}}
+                      */
+
+void func(void) {
+  struct S s2 = {};  /* c2x-warning {{use of an empty initializer is 
incompatible with C standards before C2x}}
+                        c2x-ext-warning {{use of an empty initializer is a C2x 
extension}}
+                      */
+  (void)s2;
+}
+
Index: clang/include/clang/Basic/DiagnosticGroups.td
===================================================================
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -20,6 +20,7 @@
 // Empty DiagGroups are recognized by clang but ignored.
 def ODR : DiagGroup<"odr">;
 def : DiagGroup<"abi">;
+def : DiagGroup<"gnu-empty-initializer">; // Now a C extension, not GNU.
 def AbsoluteValue : DiagGroup<"absolute-value">;
 def MisspelledAssumption : DiagGroup<"misspelled-assumption">;
 def UnknownAssumption : DiagGroup<"unknown-assumption">;


Index: clang/test/Sema/empty-init.c
===================================================================
--- /dev/null
+++ clang/test/Sema/empty-init.c
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 %s -std=c2x -Wall -pedantic -fsyntax-only -verify=good
+// RUN: %clang_cc1 %s -std=c2x -Wpre-c2x-compat -fsyntax-only -verify=c2x
+// RUN: %clang_cc1 %s -std=c2x -Wpre-c2x-compat -Wno-gnu-empty-initializer -fsyntax-only -verify=c2x
+// RUN: %clang_cc1 %s -std=c2x -Wgnu-empty-initializer -fsyntax-only -verify=good
+// RUN: %clang_cc1 %s -std=c17 -Wall -pedantic -fsyntax-only -verify=c2x-ext
+// RUN: %clang_cc1 %s -std=c17 -Wgnu-empty-initializer -fsyntax-only -verify=good
+// RUN: %clang_cc1 %s -std=c17 -Wc2x-extensions -fsyntax-only -verify=c2x-ext
+// RUN: %clang_cc1 %s -std=c17 -Wpre-c2x-compat -fsyntax-only -verify=good
+
+// good-no-diagnostics
+
+// Empty brace initialization used to be a GNU extension, but the feature was
+// added to C2x. We now treat empty initialization as a C extension rather than
+// a GNU extension. Thus, -Wgnu-empty-initializer is always silently ignored.
+
+struct S {
+  int a;
+};
+
+struct S s = {};     /* c2x-warning {{use of an empty initializer is incompatible with C standards before C2x}}
+                        c2x-ext-warning {{use of an empty initializer is a C2x extension}}
+                      */
+
+void func(void) {
+  struct S s2 = {};  /* c2x-warning {{use of an empty initializer is incompatible with C standards before C2x}}
+                        c2x-ext-warning {{use of an empty initializer is a C2x extension}}
+                      */
+  (void)s2;
+}
+
Index: clang/include/clang/Basic/DiagnosticGroups.td
===================================================================
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -20,6 +20,7 @@
 // Empty DiagGroups are recognized by clang but ignored.
 def ODR : DiagGroup<"odr">;
 def : DiagGroup<"abi">;
+def : DiagGroup<"gnu-empty-initializer">; // Now a C extension, not GNU.
 def AbsoluteValue : DiagGroup<"absolute-value">;
 def MisspelledAssumption : DiagGroup<"misspelled-assumption">;
 def UnknownAssumption : DiagGroup<"unknown-assumption">;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D157503: Silently ac... Aaron Ballman via Phabricator via cfe-commits

Reply via email to