Commit f8d448d5 authored by Aaron Ballman's avatar Aaron Ballman
Browse files

Correct behavior of VLA extension diagnostic in C89 mode

Post-commit feedback (https://reviews.llvm.org/D156565#4654773) found
that the changes in 84a3aadf 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.
parent b507509f
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -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]>;
+2 −2
Original line number Diff line number Diff line
@@ -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>;
+1 −1
Original line number Diff line number Diff line
@@ -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
+24 −0
Original line number Diff line number Diff line
/* 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;
}