003-universal_initializer.patch 3.1 KB

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