mirror of
https://github.com/richfelker/musl-cross-make.git
synced 2025-04-19 23:44:58 +02:00
105 lines
3.4 KiB
Diff
105 lines
3.4 KiB
Diff
Fix for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119
|
|
wrong warning when using the universal zero initializer {0}
|
|
|
|
Backported to GCC 4.7.4
|
|
|
|
Subject: 2014-06-05 S. Gilles <sgilles@terpmail.umd.edu>
|
|
X-Git-Url: http://repo.or.cz/w/official-gcc.git/commitdiff_plain/95cdf3fdf2d440eb7775def8e35ab970651c33d9?hp=14a3093e9943937cbc63dfbf4d51ca60f8325b29
|
|
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@211289 138bc75d-0d04-0410-961f-82ee72b054a4
|
|
|
|
--- gcc-4.7.4/gcc/c-typeck.c 2012-09-20 22:50:17.000000000 +0200
|
|
+++ gcc-4.7.4.patched/gcc/c-typeck.c 2014-08-03 16:26:14.515016910 +0200
|
|
@@ -68,9 +68,9 @@
|
|
/* The level of nesting inside "typeof". */
|
|
int in_typeof;
|
|
|
|
-/* Nonzero if we've already printed a "missing braces around initializer"
|
|
- message within this initializer. */
|
|
-static int missing_braces_mentioned;
|
|
+/* Nonzero if we might need to print a "missing braces around
|
|
+ initializer" message within this initializer. */
|
|
+static int found_missing_braces;
|
|
|
|
static int require_constant_value;
|
|
static int require_constant_elements;
|
|
@@ -6455,6 +6455,9 @@
|
|
/* 1 if this constructor is erroneous so far. */
|
|
static int constructor_erroneous;
|
|
|
|
+/* 1 if this constructor is the universal zero initializer { 0 }. */
|
|
+static int constructor_zeroinit;
|
|
+
|
|
/* Structure for managing pending initializer elements, organized as an
|
|
AVL tree. */
|
|
|
|
@@ -6616,7 +6619,7 @@
|
|
constructor_stack = 0;
|
|
constructor_range_stack = 0;
|
|
|
|
- missing_braces_mentioned = 0;
|
|
+ found_missing_braces = 0;
|
|
|
|
spelling_base = 0;
|
|
spelling_size = 0;
|
|
@@ -6711,6 +6714,7 @@
|
|
constructor_type = type;
|
|
constructor_incremental = 1;
|
|
constructor_designated = 0;
|
|
+ constructor_zeroinit = 1;
|
|
designator_depth = 0;
|
|
designator_erroneous = 0;
|
|
|
|
@@ -6908,11 +6912,8 @@
|
|
set_nonincremental_init (braced_init_obstack);
|
|
}
|
|
|
|
- if (implicit == 1 && warn_missing_braces && !missing_braces_mentioned)
|
|
- {
|
|
- missing_braces_mentioned = 1;
|
|
- warning_init (OPT_Wmissing_braces, "missing braces around initializer");
|
|
- }
|
|
+ if (implicit == 1)
|
|
+ found_missing_braces = 1;
|
|
|
|
if (TREE_CODE (constructor_type) == RECORD_TYPE
|
|
|| TREE_CODE (constructor_type) == UNION_TYPE)
|
|
@@ -7045,17 +7046,23 @@
|
|
}
|
|
}
|
|
|
|
+ if (VEC_length (constructor_elt, constructor_elements) != 1)
|
|
+ constructor_zeroinit = 0;
|
|
+
|
|
+ /* Warn when some structs are initialized with direct aggregation. */
|
|
+ if (!implicit && found_missing_braces && warn_missing_braces
|
|
+ && !constructor_zeroinit)
|
|
+ {
|
|
+ warning_init (OPT_Wmissing_braces,
|
|
+ "missing braces around initializer");
|
|
+ }
|
|
+
|
|
/* Warn when some struct elements are implicitly initialized to zero. */
|
|
if (warn_missing_field_initializers
|
|
&& constructor_type
|
|
&& TREE_CODE (constructor_type) == RECORD_TYPE
|
|
&& constructor_unfilled_fields)
|
|
{
|
|
- bool constructor_zeroinit =
|
|
- (VEC_length (constructor_elt, constructor_elements) == 1
|
|
- && integer_zerop
|
|
- (VEC_index (constructor_elt, constructor_elements, 0)->value));
|
|
-
|
|
/* Do not warn for flexible array members or zero-length arrays. */
|
|
while (constructor_unfilled_fields
|
|
&& (!DECL_SIZE (constructor_unfilled_fields)
|
|
@@ -8170,6 +8177,9 @@
|
|
designator_depth = 0;
|
|
designator_erroneous = 0;
|
|
|
|
+ if (!implicit && value.value && !integer_zerop (value.value))
|
|
+ constructor_zeroinit = 0;
|
|
+
|
|
/* Handle superfluous braces around string cst as in
|
|
char x[] = {"foo"}; */
|
|
if (string_flag
|