[clang] [Clang] Don't diagnose VLA for `-std=gnu++*` by default (PR #89943)

Kolya Panchenko via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 24 08:54:04 PDT 2024


https://github.com/nikolaypanchenko created https://github.com/llvm/llvm-project/pull/89943

The changeset aims to keep Clang's behavior prior to `7339c0f` and to match current behavior in GCC until GCC community decides what should be default: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110848

>From c9bdaf6644894a5a42d68d0ca4d82766a7cfa928 Mon Sep 17 00:00:00 2001
From: Kolya Panchenko <kolya.panchenko at sifive.com>
Date: Wed, 24 Apr 2024 08:47:03 -0700
Subject: [PATCH] [Clang] Don't diagnose VLA for `-std=gnu++*` by default

The changeset aims to keep Clang's behavior prior to `7339c0f` and to match
current behavior in GCC until GCC community decides what should be
default: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110848
---
 clang/include/clang/Basic/DiagnosticGroups.td    | 3 ++-
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 4 ++--
 clang/test/Sema/vla-ext.c                        | 1 +
 clang/test/SemaCXX/c99-variable-length-array.cpp | 1 +
 clang/test/SemaCXX/coroutine-vla.cpp             | 1 +
 5 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td
index 60f87da2a7387c..e85a09e7d00beb 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -870,7 +870,8 @@ def VectorConversion : DiagGroup<"vector-conversion">;      // clang specific
 def VexingParse : DiagGroup<"vexing-parse">;
 def VLAUseStaticAssert : DiagGroup<"vla-extension-static-assert">;
 def VLACxxExtension : DiagGroup<"vla-cxx-extension", [VLAUseStaticAssert]>;
-def VLAExtension : DiagGroup<"vla-extension", [VLACxxExtension]>;
+def GNUVLACxxExtension : DiagGroup<"gnu-vla-cxx-extension", [VLACxxExtension]>;
+def VLAExtension : DiagGroup<"vla-extension", [GNUVLACxxExtension]>;
 def VLA : DiagGroup<"vla", [VLAExtension]>;
 def VolatileRegisterVar : DiagGroup<"volatile-register-var">;
 def Visibility : DiagGroup<"visibility">;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 63e951daec7477..e0f9a074bdfb0c 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -143,12 +143,12 @@ def ext_vla_cxx : ExtWarn<
   "variable length arrays in C++ are a Clang extension">,
   InGroup<VLACxxExtension>;
 def ext_vla_cxx_in_gnu_mode : Extension<ext_vla_cxx.Summary>,
-  InGroup<VLACxxExtension>;
+  InGroup<GNUVLACxxExtension>;
 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>;
 def ext_vla_cxx_in_gnu_mode_static_assert : Extension<
-  ext_vla_cxx_static_assert.Summary>, InGroup<VLAUseStaticAssert>;
+  ext_vla_cxx_static_assert.Summary>, InGroup<GNUVLACxxExtension>;
 def warn_vla_used : Warning<"variable length array used">,
   InGroup<VLA>, DefaultIgnore;
 def err_vla_in_sfinae : Error<
diff --git a/clang/test/Sema/vla-ext.c b/clang/test/Sema/vla-ext.c
index 4ad96d97901c9e..df553d5c030b44 100644
--- a/clang/test/Sema/vla-ext.c
+++ b/clang/test/Sema/vla-ext.c
@@ -3,6 +3,7 @@
  * 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 -Wgnu-vla-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
diff --git a/clang/test/SemaCXX/c99-variable-length-array.cpp b/clang/test/SemaCXX/c99-variable-length-array.cpp
index 82ddb0fd2e2337..5df5fa98291ddb 100644
--- a/clang/test/SemaCXX/c99-variable-length-array.cpp
+++ b/clang/test/SemaCXX/c99-variable-length-array.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -Wvla-extension %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Wgnu-vla-cxx-extension %s
 struct NonPOD {
   NonPOD();
 };
diff --git a/clang/test/SemaCXX/coroutine-vla.cpp b/clang/test/SemaCXX/coroutine-vla.cpp
index 176e35f346e2b4..145358b08f3501 100644
--- a/clang/test/SemaCXX/coroutine-vla.cpp
+++ b/clang/test/SemaCXX/coroutine-vla.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -std=c++20 -fsyntax-only -Wno-vla-cxx-extension -verify
+// RUN: %clang_cc1 %s -std=c++20 -fsyntax-only -Wno-gnu-vla-cxx-extension -verify
 #include "Inputs/std-coroutine.h"
 
 struct promise;



More information about the cfe-commits mailing list