diff options
author | S. Gilles <sgilles@terpmail.umd.edu> | 2014-06-05 19:36:03 +0000 |
---|---|---|
committer | Jeff Law <law@gcc.gnu.org> | 2014-06-05 13:36:03 -0600 |
commit | 9bac5cbb2bfbf362682e103b726bd2f1f433a8ef (patch) | |
tree | cbffa0bae02b85683b8ae55888f3d5d76ad39e5c /gcc | |
parent | a148c4b2645a213a99d26056ed942fcec918bc42 (diff) | |
download | gcc-9bac5cbb2bfbf362682e103b726bd2f1f433a8ef.zip gcc-9bac5cbb2bfbf362682e103b726bd2f1f433a8ef.tar.gz gcc-9bac5cbb2bfbf362682e103b726bd2f1f433a8ef.tar.bz2 |
re PR c/53119 (-Wmissing-braces wrongly warns about universal zero initializer {0})
2014-06-05 S. Gilles <sgilles@terpmail.umd.edu>
PR c/53119
* c-typeck.c (push_init_level, process_init_element,
pop_init_level): Correct check for zero initialization, move
missing brace warning to respect zero initialization.
PR c/53119
* gcc.dg/pr53119.c: New testcase.
From-SVN: r211289
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/c/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/c/c-typeck.c | 38 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr53119.c | 25 |
4 files changed, 61 insertions, 14 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 85b0065..54d0de7 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,10 @@ +2014-06-05 S. Gilles <sgilles@terpmail.umd.edu> + + PR c/53119 + * c-typeck.c (push_init_level, process_init_element, + pop_init_level): Correct check for zero initialization, move + missing brace warning to respect zero initialization. + 2014-06-05 Marek Polacek <polacek@redhat.com> PR c/56724 diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index f09f39e..e4fa0c3 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -74,9 +74,9 @@ int in_typeof; if expr.original_code == SIZEOF_EXPR. */ tree c_last_sizeof_arg; -/* 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; @@ -6864,6 +6864,9 @@ static int constructor_nonconst; /* 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. */ @@ -7025,7 +7028,7 @@ start_init (tree decl, tree asmspec_tree ATTRIBUTE_UNUSED, int top_level) constructor_stack = 0; constructor_range_stack = 0; - missing_braces_mentioned = 0; + found_missing_braces = 0; spelling_base = 0; spelling_size = 0; @@ -7120,6 +7123,7 @@ really_start_incremental_init (tree type) constructor_type = type; constructor_incremental = 1; constructor_designated = 0; + constructor_zeroinit = 1; designator_depth = 0; designator_erroneous = 0; @@ -7323,12 +7327,8 @@ push_init_level (location_t loc, int implicit, set_nonincremental_init (braced_init_obstack); } - if (implicit == 1 && warn_missing_braces && !missing_braces_mentioned) - { - missing_braces_mentioned = 1; - warning_init (input_location, 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) @@ -7461,16 +7461,23 @@ pop_init_level (location_t loc, int implicit, } } + if (vec_safe_length (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 (loc, 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_safe_length (constructor_elements) == 1 - && integer_zerop ((*constructor_elements)[0].value)); - /* Do not warn for flexible array members or zero-length arrays. */ while (constructor_unfilled_fields && (!DECL_SIZE (constructor_unfilled_fields) @@ -8600,6 +8607,9 @@ process_init_element (location_t loc, struct c_expr value, bool implicit, 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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 06b1e33..8e0fb80 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2014-06-05 S. Gilles <sgilles@terpmail.umd.edu> + + PR c/53119 + * gcc.dg/pr53119.c: New testcase. + 2014-06-05 Senthil Kumar Selvaraj <senthil_kumar.selvaraj@atmel.com> PR target/52472 diff --git a/gcc/testsuite/gcc.dg/pr53119.c b/gcc/testsuite/gcc.dg/pr53119.c new file mode 100644 index 0000000..044811d --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr53119.c @@ -0,0 +1,25 @@ +/* { dg-do compile } */ + +/* { dg-options "-Wmissing-braces -Wmissing-field-initializers" } */ + +struct a { + int x, y, z; +}; + +struct b { + struct a w, z; +}; + +int main (void) +{ + struct a az = { 0 }; + struct a anz = { 1 }; /* { dg-warning "missing initializer for" } */ + struct a aez = { 0, 0 }; /* { dg-warning "missing initializer for" } */ + + struct b bz = { 0 }; + struct b bnz = { 0, 0, 0, 0, 0, 0 }; /* { dg-warning "missing braces" } */ + + return 0; +} + +/* { dg-excess-errors "note" } */ |