Merge branch 'v1.4' into v1.5
[librecmc/librecmc.git] / toolchain / gcc / patches / arc-2016.03 / 003-universal_initializer.patch
1 --- a/gcc/c/c-typeck.c
2 +++ b/gcc/c/c-typeck.c
3 @@ -62,9 +62,9 @@ int in_typeof;
4     if expr.original_code == SIZEOF_EXPR.  */
5  tree c_last_sizeof_arg;
6  
7 -/* Nonzero if we've already printed a "missing braces around initializer"
8 -   message within this initializer.  */
9 -static int missing_braces_mentioned;
10 +/* Nonzero if we might need to print a "missing braces around
11 +   initializer" message within this initializer.  */
12 +static int found_missing_braces;
13  
14  static int require_constant_value;
15  static int require_constant_elements;
16 @@ -6363,6 +6363,9 @@ static int constructor_nonconst;
17  /* 1 if this constructor is erroneous so far.  */
18  static int constructor_erroneous;
19  
20 +/* 1 if this constructor is the universal zero initializer { 0 }.  */
21 +static int constructor_zeroinit;
22 +
23  /* Structure for managing pending initializer elements, organized as an
24     AVL tree.  */
25  
26 @@ -6524,7 +6527,7 @@ start_init (tree decl, tree asmspec_tree
27    constructor_stack = 0;
28    constructor_range_stack = 0;
29  
30 -  missing_braces_mentioned = 0;
31 +  found_missing_braces = 0;
32  
33    spelling_base = 0;
34    spelling_size = 0;
35 @@ -6619,6 +6622,7 @@ really_start_incremental_init (tree type
36    constructor_type = type;
37    constructor_incremental = 1;
38    constructor_designated = 0;
39 +  constructor_zeroinit = 1;
40    designator_depth = 0;
41    designator_erroneous = 0;
42  
43 @@ -6816,11 +6820,8 @@ push_init_level (int implicit, struct ob
44         set_nonincremental_init (braced_init_obstack);
45      }
46  
47 -  if (implicit == 1 && warn_missing_braces && !missing_braces_mentioned)
48 -    {
49 -      missing_braces_mentioned = 1;
50 -      warning_init (OPT_Wmissing_braces, "missing braces around initializer");
51 -    }
52 +  if (implicit == 1)
53 +    found_missing_braces = 1;
54  
55    if (TREE_CODE (constructor_type) == RECORD_TYPE
56            || TREE_CODE (constructor_type) == UNION_TYPE)
57 @@ -6953,16 +6954,23 @@ pop_init_level (int implicit, struct obs
58         }
59      }
60  
61 +  if (vec_safe_length (constructor_elements) != 1)
62 +    constructor_zeroinit = 0;
63 +
64 +  /* Warn when some structs are initialized with direct aggregation.  */
65 +  if (!implicit && found_missing_braces && warn_missing_braces
66 +      && !constructor_zeroinit)
67 +    {
68 +      warning_init (OPT_Wmissing_braces,
69 +                   "missing braces around initializer");
70 +    }
71 +
72    /* Warn when some struct elements are implicitly initialized to zero.  */
73    if (warn_missing_field_initializers
74        && constructor_type
75        && TREE_CODE (constructor_type) == RECORD_TYPE
76        && constructor_unfilled_fields)
77      {
78 -       bool constructor_zeroinit =
79 -        (vec_safe_length (constructor_elements) == 1
80 -         && integer_zerop ((*constructor_elements)[0].value));
81 -
82         /* Do not warn for flexible array members or zero-length arrays.  */
83         while (constructor_unfilled_fields
84                && (!DECL_SIZE (constructor_unfilled_fields)
85 @@ -8077,6 +8085,9 @@ process_init_element (struct c_expr valu
86    designator_depth = 0;
87    designator_erroneous = 0;
88  
89 +  if (!implicit && value.value && !integer_zerop (value.value))
90 +    constructor_zeroinit = 0;
91 +
92    /* Handle superfluous braces around string cst as in
93       char x[] = {"foo"}; */
94    if (string_flag