Skip to content

Commit f8d448d

Browse files
committed
Correct behavior of VLA extension diagnostic in C89 mode
Post-commit feedback (https://reviews.llvm.org/D156565#4654773) found that the changes in 84a3aad 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.
1 parent b507509 commit f8d448d

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-5
lines changed

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,8 @@ def VariadicMacros : DiagGroup<"variadic-macros">;
849849
def VectorConversion : DiagGroup<"vector-conversion">; // clang specific
850850
def VexingParse : DiagGroup<"vexing-parse">;
851851
def VLAUseStaticAssert : DiagGroup<"vla-extension-static-assert">;
852-
def VLAExtension : DiagGroup<"vla-extension", [VLAUseStaticAssert]>;
852+
def VLACxxExtension : DiagGroup<"vla-cxx-extension", [VLAUseStaticAssert]>;
853+
def VLAExtension : DiagGroup<"vla-extension", [VLACxxExtension]>;
853854
def VLA : DiagGroup<"vla", [VLAExtension]>;
854855
def VolatileRegisterVar : DiagGroup<"volatile-register-var">;
855856
def Visibility : DiagGroup<"visibility">;
@@ -1086,7 +1087,8 @@ def Consumed : DiagGroup<"consumed">;
10861087
// warning should be active _only_ when -Wall is passed in, mark it as
10871088
// DefaultIgnore in addition to putting it here.
10881089
def All : DiagGroup<"all", [Most, Parentheses, Switch, SwitchBool,
1089-
MisleadingIndentation, PackedNonPod, VLAExtension]>;
1090+
MisleadingIndentation, PackedNonPod,
1091+
VLACxxExtension]>;
10901092

10911093
// Warnings that should be in clang-cl /w4.
10921094
def : DiagGroup<"CL4", [All, Extra]>;

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ def ext_vla : Extension<"variable length arrays are a C99 feature">,
141141
// language modes, we warn as an extension but add the warning group to -Wall.
142142
def ext_vla_cxx : ExtWarn<
143143
"variable length arrays in C++ are a Clang extension">,
144-
InGroup<VLAExtension>;
144+
InGroup<VLACxxExtension>;
145145
def ext_vla_cxx_in_gnu_mode : Extension<ext_vla_cxx.Summary>,
146-
InGroup<VLAExtension>;
146+
InGroup<VLACxxExtension>;
147147
def ext_vla_cxx_static_assert : ExtWarn<
148148
"variable length arrays in C++ are a Clang extension; did you mean to use "
149149
"'static_assert'?">, InGroup<VLAUseStaticAssert>;

clang/test/Misc/warning-wall.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ CHECK-NEXT: -Wswitch
105105
CHECK-NEXT: -Wswitch-bool
106106
CHECK-NEXT: -Wmisleading-indentation
107107
CHECK-NEXT: -Wpacked-non-pod
108-
CHECK-NEXT: -Wvla-extension
108+
CHECK-NEXT: -Wvla-cxx-extension
109109
CHECK-NEXT: -Wvla-extension-static-assert
110110

111111
CHECK-NOT:-W

clang/test/Sema/vla-ext.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* RUN: %clang_cc1 -verify=off -std=c89 %s
2+
* RUN: %clang_cc1 -verify=off -Wall -std=c89 %s
3+
* RUN: %clang_cc1 -verify -pedantic -std=c89 %s
4+
* RUN: %clang_cc1 -verify -Wvla-extension -std=c89 %s
5+
* RUN: %clang_cc1 -verify=off -Wvla-cxx-extension -std=c89 %s
6+
* RUN: %clang_cc1 -verify=off -pedantic -std=c99 %s
7+
* RUN: %clang_cc1 -verify=off -Wall -std=c99 %s
8+
* RUN: %clang_cc1 -verify=off -std=c99 -Wvla-extension %s
9+
* The next run line still issues the extension warning because VLAs are an
10+
* extension in C89, but the line after it will issue the congratulatory
11+
* diagnostic.
12+
* RUN: %clang_cc1 -verify -Wvla -std=c89 %s
13+
* RUN: %clang_cc1 -verify=wvla -Wvla -std=c99 %s
14+
*/
15+
16+
/* off-no-diagnostics */
17+
18+
void func(int n) {
19+
int array[n]; /* expected-warning {{variable length arrays are a C99 feature}}
20+
wvla-warning {{variable length array used}}
21+
*/
22+
(void)array;
23+
}
24+

0 commit comments

Comments
 (0)