[PATCH] D157503: Silently accept -Wgnu-empty-initializer

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 9 07:05:22 PDT 2023


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">;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157503.548606.patch
Type: text/x-patch
Size: 2214 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230809/e22ae429/attachment.bin>


More information about the cfe-commits mailing list