[cfe-commits] r173286 - in /cfe/trunk: include/clang/Basic/DiagnosticGroups.td include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaType.cpp test/Sema/warn-vla.c test/SemaCXX/c99-variable-length-array-cxx11.cpp test/SemaCXX/c99-variable-length-array.cpp test/SemaCXX/warn-vla.cpp

Dmitri Gribenko gribozavr at gmail.com
Wed Jan 23 12:02:51 PST 2013


Author: gribozavr
Date: Wed Jan 23 14:02:51 2013
New Revision: 173286

URL: http://llvm.org/viewvc/llvm-project?rev=173286&view=rev
Log:
Implement -Wvla correctly

GCC implements -Wvla as "warn on every VLA" (this is useful to find every VLA,
for example, if they are forbidden by coding guidelines).  Currently Clang
implements -Wvla as "warn on VLA when it is an extension".

The attached patch makes our behavior match GCC.  The existing vla extwarn is
moved under -Wvla-extension and is still included into -Wgnu.

This fixes PR5953.

Added:
    cfe/trunk/test/Sema/warn-vla.c
    cfe/trunk/test/SemaCXX/warn-vla.cpp
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticGroups.td
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaType.cpp
    cfe/trunk/test/SemaCXX/c99-variable-length-array-cxx11.cpp
    cfe/trunk/test/SemaCXX/c99-variable-length-array.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=173286&r1=173285&r2=173286&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Wed Jan 23 14:02:51 2013
@@ -317,6 +317,7 @@
 def VectorConversion : DiagGroup<"vector-conversion">;      // clang specific
 def VexingParse : DiagGroup<"vexing-parse">;
 def VLA : DiagGroup<"vla">;
+def VLAExtension : DiagGroup<"vla-extension">;
 def VolatileRegisterVar : DiagGroup<"volatile-register-var">;
 def Visibility : DiagGroup<"visibility">;
 def ZeroLengthArray : DiagGroup<"zero-length-array">;
@@ -473,7 +474,7 @@
 def C99 : DiagGroup<"c99-extensions">;
 
 // A warning group for warnings about GCC extensions.
-def GNU : DiagGroup<"gnu", [GNUDesignator, VLA, ZeroLengthArray]>;
+def GNU : DiagGroup<"gnu", [GNUDesignator, VLAExtension, ZeroLengthArray]>;
 // A warning group for warnings about code that clang accepts but gcc doesn't.
 def GccCompat : DiagGroup<"gcc-compat">;
 

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=173286&r1=173285&r2=173286&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Jan 23 14:02:51 2013
@@ -75,7 +75,9 @@
 
 // C99 variable-length arrays
 def ext_vla : Extension<"variable length arrays are a C99 feature">,
-  InGroup<VLA>;
+  InGroup<VLAExtension>;
+def warn_vla_used : Warning<"variable length array used">,
+  InGroup<VLA>, DefaultIgnore;
 def err_vla_non_pod : Error<"variable length array of non-POD element type %0">;
 def err_vla_in_sfinae : Error<
   "variable length array cannot be formed during template argument deduction">;

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=173286&r1=173285&r2=173286&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Wed Jan 23 14:02:51 2013
@@ -1496,6 +1496,11 @@
                                      : diag::ext_c99_array_usage) << ASM;
   }
 
+  if (T->isVariableArrayType()) {
+    // Warn about VLAs for -Wvla.
+    Diag(Loc, diag::warn_vla_used);
+  }
+
   return T;
 }
 

Added: cfe/trunk/test/Sema/warn-vla.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-vla.c?rev=173286&view=auto
==============================================================================
--- cfe/trunk/test/Sema/warn-vla.c (added)
+++ cfe/trunk/test/Sema/warn-vla.c Wed Jan 23 14:02:51 2013
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -std=c99 -fsyntax-only -verify -Wvla %s
+// RUN: %clang_cc1 -std=c89 -fsyntax-only -verify -Wvla %s
+
+void test1(int n) {
+  int v[n]; // expected-warning {{variable length array used}}
+}
+
+void test2(int n, int v[n]) { // expected-warning {{variable length array used}}
+}
+
+void test3(int n, int v[n]); // expected-warning {{variable length array used}}
+

Modified: cfe/trunk/test/SemaCXX/c99-variable-length-array-cxx11.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/c99-variable-length-array-cxx11.cpp?rev=173286&r1=173285&r2=173286&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/c99-variable-length-array-cxx11.cpp (original)
+++ cfe/trunk/test/SemaCXX/c99-variable-length-array-cxx11.cpp Wed Jan 23 14:02:51 2013
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wvla %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wvla-extension %s
 struct StillPOD {
   StillPOD() = default;
 };

Modified: cfe/trunk/test/SemaCXX/c99-variable-length-array.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/c99-variable-length-array.cpp?rev=173286&r1=173285&r2=173286&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/c99-variable-length-array.cpp (original)
+++ cfe/trunk/test/SemaCXX/c99-variable-length-array.cpp Wed Jan 23 14:02:51 2013
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -Wvla %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Wvla-extension %s
 struct NonPOD {
   NonPOD();
 };

Added: cfe/trunk/test/SemaCXX/warn-vla.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-vla.cpp?rev=173286&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-vla.cpp (added)
+++ cfe/trunk/test/SemaCXX/warn-vla.cpp Wed Jan 23 14:02:51 2013
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wvla %s
+
+void test1(int n) {
+  int v[n]; // expected-warning {{variable length array used}}
+}
+
+void test2(int n, int v[n]) { // expected-warning {{variable length array used}}
+}
+
+void test3(int n, int v[n]); // expected-warning {{variable length array used}}
+
+template<typename T>
+void test4(int n) {
+  int v[n]; // expected-warning {{variable length array used}}
+}
+
+template<typename T>
+void test5(int n, int v[n]) { // expected-warning {{variable length array used}}
+}
+
+template<typename T>
+void test6(int n, int v[n]); // expected-warning {{variable length array used}}
+
+template<typename T>
+void test7(int n, T v[n]) { // expected-warning {{variable length array used}}
+}
+





More information about the cfe-commits mailing list