[clang] f8d448d - Correct behavior of VLA extension diagnostic in C89 mode

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 23 05:08:12 PDT 2023


Author: Aaron Ballman
Date: 2023-10-23T08:07:59-04:00
New Revision: f8d448d5e587a23886c3226957f880146a4d8c69

URL: https://github.com/llvm/llvm-project/commit/f8d448d5e587a23886c3226957f880146a4d8c69
DIFF: https://github.com/llvm/llvm-project/commit/f8d448d5e587a23886c3226957f880146a4d8c69.diff

LOG: Correct behavior of VLA extension diagnostic in C89 mode

Post-commit feedback (https://reviews.llvm.org/D156565#4654773) found
that the changes in 84a3aadf0f2483dde0acfc4e79f2a075a5f35bd1 caused us
to diagnose use of VLAs in C89 mode by default which was an unintended
change.

This adds -Wvla-cxx-extension as a warning group and adds the C++-
specific warnings to it while leaving the C warnings under
-Wvla-extension. -Wvla-cxx-extension is then added to -Wall.

Added: 
    clang/test/Sema/vla-ext.c

Modified: 
    clang/include/clang/Basic/DiagnosticGroups.td
    clang/include/clang/Basic/DiagnosticSemaKinds.td
    clang/test/Misc/warning-wall.c

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td
index dcdae38013d2aaa..4cb792132d6e09d 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -849,7 +849,8 @@ def VariadicMacros : DiagGroup<"variadic-macros">;
 def VectorConversion : DiagGroup<"vector-conversion">;      // clang specific
 def VexingParse : DiagGroup<"vexing-parse">;
 def VLAUseStaticAssert : DiagGroup<"vla-extension-static-assert">;
-def VLAExtension : DiagGroup<"vla-extension", [VLAUseStaticAssert]>;
+def VLACxxExtension : DiagGroup<"vla-cxx-extension", [VLAUseStaticAssert]>;
+def VLAExtension : DiagGroup<"vla-extension", [VLACxxExtension]>;
 def VLA : DiagGroup<"vla", [VLAExtension]>;
 def VolatileRegisterVar : DiagGroup<"volatile-register-var">;
 def Visibility : DiagGroup<"visibility">;
@@ -1086,7 +1087,8 @@ def Consumed       : DiagGroup<"consumed">;
 // warning should be active _only_ when -Wall is passed in, mark it as
 // DefaultIgnore in addition to putting it here.
 def All : DiagGroup<"all", [Most, Parentheses, Switch, SwitchBool,
-                            MisleadingIndentation, PackedNonPod, VLAExtension]>;
+                            MisleadingIndentation, PackedNonPod,
+                            VLACxxExtension]>;
 
 // Warnings that should be in clang-cl /w4.
 def : DiagGroup<"CL4", [All, Extra]>;

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index a4c1cb08de9401a..3bcbb003d6dee19 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -141,9 +141,9 @@ def ext_vla : Extension<"variable length arrays are a C99 feature">,
 // language modes, we warn as an extension but add the warning group to -Wall.
 def ext_vla_cxx : ExtWarn<
   "variable length arrays in C++ are a Clang extension">,
-  InGroup<VLAExtension>;
+  InGroup<VLACxxExtension>;
 def ext_vla_cxx_in_gnu_mode : Extension<ext_vla_cxx.Summary>,
-  InGroup<VLAExtension>;
+  InGroup<VLACxxExtension>;
 def ext_vla_cxx_static_assert : ExtWarn<
   "variable length arrays in C++ are a Clang extension; did you mean to use "
   "'static_assert'?">, InGroup<VLAUseStaticAssert>;

diff  --git a/clang/test/Misc/warning-wall.c b/clang/test/Misc/warning-wall.c
index c0cf8324e6e162e..05a82770e26de69 100644
--- a/clang/test/Misc/warning-wall.c
+++ b/clang/test/Misc/warning-wall.c
@@ -105,7 +105,7 @@ CHECK-NEXT:  -Wswitch
 CHECK-NEXT:  -Wswitch-bool
 CHECK-NEXT:  -Wmisleading-indentation
 CHECK-NEXT:  -Wpacked-non-pod
-CHECK-NEXT:  -Wvla-extension
+CHECK-NEXT:  -Wvla-cxx-extension
 CHECK-NEXT:    -Wvla-extension-static-assert
 
 CHECK-NOT:-W

diff  --git a/clang/test/Sema/vla-ext.c b/clang/test/Sema/vla-ext.c
new file mode 100644
index 000000000000000..4ad96d97901c9e5
--- /dev/null
+++ b/clang/test/Sema/vla-ext.c
@@ -0,0 +1,24 @@
+/* RUN: %clang_cc1 -verify=off -std=c89 %s
+ * RUN: %clang_cc1 -verify=off -Wall -std=c89 %s
+ * RUN: %clang_cc1 -verify -pedantic -std=c89 %s
+ * RUN: %clang_cc1 -verify -Wvla-extension -std=c89 %s
+ * RUN: %clang_cc1 -verify=off -Wvla-cxx-extension -std=c89 %s
+ * RUN: %clang_cc1 -verify=off -pedantic -std=c99 %s
+ * RUN: %clang_cc1 -verify=off -Wall -std=c99 %s
+ * RUN: %clang_cc1 -verify=off -std=c99 -Wvla-extension %s
+ * The next run line still issues the extension warning because VLAs are an
+ * extension in C89, but the line after it will issue the congratulatory
+ * diagnostic.
+ * RUN: %clang_cc1 -verify -Wvla -std=c89 %s
+ * RUN: %clang_cc1 -verify=wvla -Wvla -std=c99 %s
+ */
+
+/* off-no-diagnostics */
+
+void func(int n) {
+  int array[n]; /* expected-warning {{variable length arrays are a C99 feature}}
+                   wvla-warning {{variable length array used}}
+                 */
+  (void)array;
+}
+


        


More information about the cfe-commits mailing list