[clang] e959931 - [Sema] Put existing warning under -Wexcess-initializers
Richard Sandiford via cfe-commits
cfe-commits at lists.llvm.org
Wed May 6 03:29:06 PDT 2020
Author: Richard Sandiford
Date: 2020-05-06T11:28:40+01:00
New Revision: e959931092d54330ce33f0c1a8479c978d39f655
URL: https://github.com/llvm/llvm-project/commit/e959931092d54330ce33f0c1a8479c978d39f655
DIFF: https://github.com/llvm/llvm-project/commit/e959931092d54330ce33f0c1a8479c978d39f655.diff
LOG: [Sema] Put existing warning under -Wexcess-initializers
I have a follow-on patch that uses an alternative wording for
ext_excess_initializers in some cases. This patch puts it and
a couple of related warnings under their own -W option in order
to avoid a regression in Misc/warning-flags.c.
Differential Revision: https://reviews.llvm.org/D79244
Added:
Modified:
clang/docs/DiagnosticsReference.rst
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/test/Misc/warning-flags.c
clang/test/Sema/array-init.c
clang/test/Sema/init.c
Removed:
################################################################################
diff --git a/clang/docs/DiagnosticsReference.rst b/clang/docs/DiagnosticsReference.rst
index 2bb1dd6b685b..38618f453027 100644
--- a/clang/docs/DiagnosticsReference.rst
+++ b/clang/docs/DiagnosticsReference.rst
@@ -4481,6 +4481,35 @@ This diagnostic is enabled by default.
+-----------------------------------------------------------------------------------------------------------------------------+
+-Wexcess-initializers
+---------------------
+This diagnostic is enabled by default.
+
+**Diagnostic text:**
+
++-----------------------------------------------------------------+--------------------+-------------------------------+
+|:warning:`warning:` |nbsp| :diagtext:`excess elements in` |nbsp| |+------------------+| |nbsp| :diagtext:`initializer`|
+| ||:diagtext:`array` || |
+| |+------------------+| |
+| ||:diagtext:`vector`|| |
+| |+------------------+| |
+| ||:diagtext:`scalar`|| |
+| |+------------------+| |
+| ||:diagtext:`union` || |
+| |+------------------+| |
+| ||:diagtext:`struct`|| |
+| |+------------------+| |
++-----------------------------------------------------------------+--------------------+-------------------------------+
+
++--------------------------------------------------------------------------------+
+|:warning:`warning:` |nbsp| :diagtext:`excess elements in char array initializer`|
++--------------------------------------------------------------------------------+
+
++------------------------------------------------------------------------------------+
+|:warning:`warning:` |nbsp| :diagtext:`initializer-string for char array is too long`|
++------------------------------------------------------------------------------------+
+
+
-Wexit-time-destructors
-----------------------
**Diagnostic text:**
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td
index 3db9d5814ba3..b6a252ac01a9 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -350,6 +350,7 @@ def Dangling : DiagGroup<"dangling", [DanglingField,
DanglingGsl,
ReturnStackAddress]>;
def DistributedObjectModifiers : DiagGroup<"distributed-object-modifiers">;
+def ExcessInitializers : DiagGroup<"excess-initializers">;
def ExpansionToDefined : DiagGroup<"expansion-to-defined">;
def FlagEnum : DiagGroup<"flag-enum">;
def IncrementBool : DiagGroup<"increment-bool", [DeprecatedIncrementBool]>;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8beb47812d40..7624fd7107c8 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5396,15 +5396,18 @@ def err_variable_object_no_init : Error<
def err_excess_initializers : Error<
"excess elements in %select{array|vector|scalar|union|struct}0 initializer">;
def ext_excess_initializers : ExtWarn<
- "excess elements in %select{array|vector|scalar|union|struct}0 initializer">;
+ "excess elements in %select{array|vector|scalar|union|struct}0 initializer">,
+ InGroup<ExcessInitializers>;
def err_excess_initializers_in_char_array_initializer : Error<
"excess elements in char array initializer">;
def ext_excess_initializers_in_char_array_initializer : ExtWarn<
- "excess elements in char array initializer">;
+ "excess elements in char array initializer">,
+ InGroup<ExcessInitializers>;
def err_initializer_string_for_char_array_too_long : Error<
"initializer-string for char array is too long">;
def ext_initializer_string_for_char_array_too_long : ExtWarn<
- "initializer-string for char array is too long">;
+ "initializer-string for char array is too long">,
+ InGroup<ExcessInitializers>;
def warn_missing_field_initializers : Warning<
"missing field %0 initializer">,
InGroup<MissingFieldInitializers>, DefaultIgnore;
diff --git a/clang/test/Misc/warning-flags.c b/clang/test/Misc/warning-flags.c
index 9c28d3adcf93..aff90dd6f1d3 100644
--- a/clang/test/Misc/warning-flags.c
+++ b/clang/test/Misc/warning-flags.c
@@ -18,12 +18,9 @@ This test serves two purposes:
The list of warnings below should NEVER grow. It should gradually shrink to 0.
-CHECK: Warnings without flags (75):
-CHECK-NEXT: ext_excess_initializers
-CHECK-NEXT: ext_excess_initializers_in_char_array_initializer
+CHECK: Warnings without flags (72):
CHECK-NEXT: ext_expected_semi_decl_list
CHECK-NEXT: ext_explicit_specialization_storage_class
-CHECK-NEXT: ext_initializer_string_for_char_array_too_long
CHECK-NEXT: ext_missing_declspec
CHECK-NEXT: ext_missing_whitespace_after_macro_name
CHECK-NEXT: ext_new_paren_array_nonconst
diff --git a/clang/test/Sema/array-init.c b/clang/test/Sema/array-init.c
index 7cb48153168f..15edcb0a8656 100644
--- a/clang/test/Sema/array-init.c
+++ b/clang/test/Sema/array-init.c
@@ -148,11 +148,20 @@ int xx_sizecheck[(sizeof(xx) / sizeof(char)) == 5? 1 : -1];
static char const yy[5] = "test";
static char const zz[3] = "test"; // expected-warning{{initializer-string for char array is too long}}
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wexcess-initializers"
+static char const zz_quiet[3] = "test";
+#pragma clang diagnostic pop
+
void charArrays() {
static char const test[] = "test";
int test_sizecheck[(sizeof(test) / sizeof(char)) == 5? 1 : -1];
static char const test2[] = { "weird stuff" };
static char const test3[] = { "test", "excess stuff" }; // expected-warning{{excess elements in char array initializer}}
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wexcess-initializers"
+ static char const test3_quiet[] = {"test", "excess stuff"};
+#pragma clang diagnostic pop
char* cp[] = { "Hello" };
diff --git a/clang/test/Sema/init.c b/clang/test/Sema/init.c
index 8ac17abd8c69..26fb7c813b19 100644
--- a/clang/test/Sema/init.c
+++ b/clang/test/Sema/init.c
@@ -121,6 +121,10 @@ struct foo2 bar2[] = {
};
struct foo2 bar3 = { 1, 2 }; // expected-warning{{excess elements in struct initializer}}
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wexcess-initializers"
+struct foo2 bar3_silent = {1, 2};
+#pragma clang diagnostic pop
int* ptest1 = __builtin_choose_expr(1, (int*)0, (int*)0);
More information about the cfe-commits
mailing list