Hello Joseph, Martin,

Asher Gordon <asd...@posteo.net> writes:

> Joseph Myers <jos...@codesourcery.com> writes:
>
>> I don't see you in the FSF copyright assignment list; could you
>> complete
>> https://git.savannah.gnu.org/cgit/gnulib.git/plain/doc/Copyright/request-assign.future
>> (unless you're already covered by an employer assignment)?
>
> Done.

My copyright assignment finally got finished, so you should be able to
apply my patches now.

For your convenience, I have attached the three patches below:
From e94073b90d5906dc4eb14ebfec4ea24ae1241184 Mon Sep 17 00:00:00 2001
From: Asher Gordon <asd...@posteo.net>
Date: Mon, 8 Jun 2020 20:59:38 -0400
Subject: [PATCH 1/3] Replace free with XDELETE.

gcc/c/ChangeLog:

	* c-typeck.c (free_all_tagged_tu_seen_up_to): Replace free
	with XDELETE.
	(finish_init): Likewise.
	(pop_init_level): Likewise.
---
 gcc/c/c-typeck.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index fb5c288b549..44f2722adb8 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -1407,7 +1407,7 @@ free_all_tagged_tu_seen_up_to (const struct tagged_tu_seen_cache *tu_til)
       const struct tagged_tu_seen_cache *const tu1
 	= (const struct tagged_tu_seen_cache *) tu;
       tu = tu1->next;
-      free (CONST_CAST (struct tagged_tu_seen_cache *, tu1));
+      XDELETE (CONST_CAST (struct tagged_tu_seen_cache *, tu1));
     }
   tagged_tu_seen_base = tu_til;
 }
@@ -8314,13 +8314,13 @@ finish_init (void)
     {
       struct constructor_stack *q = constructor_stack;
       constructor_stack = q->next;
-      free (q);
+      XDELETE (q);
     }
 
   gcc_assert (!constructor_range_stack);
 
   /* Pop back to the data of the outer initializer (if any).  */
-  free (spelling_base);
+  XDELETE (spelling_base);
 
   constructor_decl = p->decl;
   require_constant_value = p->require_constant_value;
@@ -8333,7 +8333,7 @@ finish_init (void)
   spelling_size = p->spelling_size;
   constructor_top_level = p->top_level;
   initializer_stack = p->next;
-  free (p);
+  XDELETE (p);
 }

 /* Call here when we see the initializer is surrounded by braces.
@@ -8864,7 +8864,7 @@ pop_init_level (location_t loc, int implicit,
   RESTORE_SPELLING_DEPTH (constructor_depth);
 
   constructor_stack = p->next;
-  free (p);
+  XDELETE (p);
 
   if (ret.value == NULL_TREE && constructor_stack == 0)
     ret.value = error_mark_node;
-- 
2.27.0

From b69c8aec5639655bc87ded65d75041a7e1d7c14f Mon Sep 17 00:00:00 2001
From: Asher Gordon <asd...@posteo.net>
Date: Wed, 3 Jun 2020 17:20:08 -0400
Subject: [PATCH 2/3] PR c/95379 Treat { 0 } specially for -Wdesignated-init.

gcc/c/ChangeLog:

	PR c/95379
	* c-typeck.c (warning_init): Allow variable arguments.
	(struct positional_init_info): New type.
	(struct initializer_stack): Add positional_init_info for
	-Wdesignated-init warnings.
	(start_init): Initialize
	initializer_stack->positional_init_info.
	(finish_init): Free initializer_stack->positional_init_info.
	(pop_init_level): Move -Wdesignated-init warning here from
	process_init_element so that we can treat { 0 } specially.
	(process_init_element): Instead of warning on
	-Wdesignated-init here, remember a list of locations and
	fields where we should warn, and do the actual warning in
	pop_init_level.

gcc/ChangeLog:

	PR c/95379
	* doc/extend.texi: Document { 0 } as a special case for the
	designated_init attribute.

gcc/testsuite/ChangeLog:

	PR c/95379
	* gcc.dg/Wdesignated-init-3.c: New test.
---
 gcc/c/c-typeck.c                          | 69 ++++++++++++++++++++---
 gcc/doc/extend.texi                       |  4 ++
 gcc/testsuite/gcc.dg/Wdesignated-init-3.c | 12 ++++
 3 files changed, 77 insertions(+), 8 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/Wdesignated-init-3.c

diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index 44f2722adb8..1afec3fdc36 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -107,7 +107,7 @@ static void push_string (const char *);
 static void push_member_name (tree);
 static int spelling_length (void);
 static char *print_spelling (char *);
-static void warning_init (location_t, int, const char *);
+static void warning_init (location_t, int, const char *, ...);
 static tree digest_init (location_t, tree, tree, tree, bool, bool, int);
 static void output_init_element (location_t, tree, tree, bool, tree, tree, bool,
 				 bool, struct obstack *);
@@ -6431,11 +6431,12 @@ pedwarn_init (location_t loc, int opt, const char *gmsgid, ...)
    controls this warning.  GMSGID identifies the message.  The
    component name is taken from the spelling stack.  */
 
-static void
-warning_init (location_t loc, int opt, const char *gmsgid)
+static void ATTRIBUTE_GCC_DIAG (3,4)
+warning_init (location_t loc, int opt, const char *gmsgid, ...)
 {
   char *ofwhat;
   bool warned;
+  va_list ap;
 
   auto_diagnostic_group d;
 
@@ -6445,7 +6446,9 @@ warning_init (location_t loc, int opt, const char *gmsgid)
   location_t exploc = expansion_point_location_if_in_system_header (loc);
 
   /* The gmsgid may be a format string with %< and %>. */
-  warned = warning_at (exploc, opt, gmsgid);
+  va_start (ap, gmsgid);
+  warned = emit_diagnostic_valist (DK_WARNING, exploc, opt, gmsgid, &ap);
+  va_end (ap);
   ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
   if (*ofwhat && warned)
     inform (exploc, "(near initialization for %qs)", ofwhat);
@@ -8225,6 +8228,22 @@ struct constructor_range_stack
 
 static struct constructor_range_stack *constructor_range_stack;
 
+/* This structure stores information for positional initializers
+   (field and location).  */
+struct positional_init_info {
+  location_t loc;
+  tree field;
+
+  /* So that the vector operations can set this to zero.  */
+  void
+  operator= (int value)
+  {
+    gcc_assert (value == 0);
+    loc = 0;
+    field = NULL_TREE;
+  }
+};
+
 /* This stack records separate initializers that are nested.
    Nested initializers can't happen in ANSI C, but GNU C allows them
    in cases like { ... (struct foo) { ... } ... }.  */
@@ -8243,6 +8262,7 @@ struct initializer_stack
   char require_constant_value;
   char require_constant_elements;
   rich_location *missing_brace_richloc;
+  vec<struct positional_init_info, va_gc> *positional_init_info;
 };
 
 static struct initializer_stack *initializer_stack;
@@ -8268,6 +8288,7 @@ start_init (tree decl, tree asmspec_tree ATTRIBUTE_UNUSED, int top_level,
   p->top_level = constructor_top_level;
   p->next = initializer_stack;
   p->missing_brace_richloc = richloc;
+  vec_alloc (p->positional_init_info, 0);
   initializer_stack = p;
 
   constructor_decl = decl;
@@ -8333,6 +8354,8 @@ finish_init (void)
   spelling_size = p->spelling_size;
   constructor_top_level = p->top_level;
   initializer_stack = p->next;
+
+  vec_free (p->positional_init_info);
   XDELETE (p);
 }

@@ -8790,6 +8813,33 @@ pop_init_level (location_t loc, int implicit,
 	  }
     }
 
+  /* Warn when positional initializers are used for a structure with
+     the designated_init attribute, but make an exception for { 0 }.  */
+  if (!constructor_zeroinit
+      && vec_safe_length (initializer_stack->positional_init_info))
+    {
+      struct positional_init_info info;
+
+      gcc_assert (constructor_type);
+      gcc_assert (TREE_CODE (constructor_type) == RECORD_TYPE);
+
+      for (unsigned int i = 0;
+	   vec_safe_iterate (initializer_stack->positional_init_info, i, &info);
+	   i++)
+	{
+	  warning_init (info.loc,
+			OPT_Wdesignated_init,
+			"positional initialization of field %qD in %qT "
+			"declared with %<designated_init%> attribute",
+			info.field, constructor_type);
+	  inform (DECL_SOURCE_LOCATION (info.field),
+		  "in definition of %qT", constructor_type);
+	}
+    }
+
+  /* We must free this here so we don't warn again later.  */
+  vec_free (initializer_stack->positional_init_info);
+
   /* Pad out the end of the structure.  */
   if (p->replacement_value.value)
     /* If this closes a superfluous brace pair,
@@ -10021,10 +10071,13 @@ process_init_element (location_t loc, struct c_expr value, bool implicit,
       && TREE_CODE (constructor_type) == RECORD_TYPE
       && lookup_attribute ("designated_init",
 			   TYPE_ATTRIBUTES (constructor_type)))
-    warning_init (loc,
-		  OPT_Wdesignated_init,
-		  "positional initialization of field "
-		  "in %<struct%> declared with %<designated_init%> attribute");
+    {
+      /* Remember where we got a positional initializer so we can warn
+	 if it initializes a field of a structure with the
+	 designated_init attribute.  */
+      struct positional_init_info info = { loc, constructor_fields };
+      vec_safe_push (initializer_stack->positional_init_info, info);
+    }
 
   /* If we've exhausted any levels that didn't have braces,
      pop them now.  */
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index 0fb7e27d9ce..332803c64e3 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -8101,6 +8101,10 @@ attribute is to allow the programmer to indicate that a structure's
 layout may change, and that therefore relying on positional
 initialization will result in future breakage.
 
+Note that the universal zero initializer, @code{@{ 0 @}}, is considered
+a special case and will not produce a warning when used to initialize a
+structure with the @code{designated_init} attribute.
+
 GCC emits warnings based on this attribute by default; use
 @option{-Wno-designated-init} to suppress them.
 
diff --git a/gcc/testsuite/gcc.dg/Wdesignated-init-3.c b/gcc/testsuite/gcc.dg/Wdesignated-init-3.c
new file mode 100644
index 00000000000..1da3ed5bef4
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wdesignated-init-3.c
@@ -0,0 +1,12 @@
+/* PR c/95379 */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99" } */
+
+struct Des {
+  int x;
+  int y;
+} __attribute__ ((designated_init));
+
+struct Des d1 = { 0 }; /* { dg-bogus "(positional|near initialization)" } */
+struct Des d2 = { 5 }; /* { dg-warning "(positional|near initialization)" } */
+struct Des d3 = { 0, 0 }; /* { dg-warning "(positional|near initialization)" } */
-- 
2.27.0

From acb880883ad4b3256cc5db725c27ebea022e34e9 Mon Sep 17 00:00:00 2001
From: Asher Gordon <asd...@posteo.net>
Date: Sun, 7 Jun 2020 13:37:27 -0400
Subject: [PATCH 3/3] Add -Wuniversal-initializer to not suppress warnings
 about { 0 }.

gcc/ChangeLog:

	* doc/invoke.texi: Document -Wuniversal-initializer.

gcc/c-family/ChangeLog:

	* c.opt: Add -Wuniversal-initializer

gcc/c/ChangeLog:

	* c-typeck.c (pop_init_level): Don't suppress warnings about { 0 }
	if warn_zero_init.

gcc/testsuite/ChangeLog:

	* gcc.dg/Wuniversal-initializer.c: New test.
---
 gcc/c-family/c.opt                            |  4 ++++
 gcc/c/c-typeck.c                              |  9 ++++----
 gcc/doc/invoke.texi                           | 22 ++++++++++++++++++-
 gcc/testsuite/gcc.dg/Wuniversal-initializer.c | 20 +++++++++++++++++
 4 files changed, 50 insertions(+), 5 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/Wuniversal-initializer.c

diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 2b1aca16eb4..4aeed985b8a 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -1191,6 +1191,10 @@ Wuninitialized
 C ObjC C++ ObjC++ LTO LangEnabledBy(C ObjC C++ ObjC++ LTO,Wall)
 ;
 
+Wuniversal-initializer
+C ObjC C++ ObjC++ Var(warn_zero_init) Init(0) Warning
+Don't suppress warnings about { 0 }.
+
 Wmaybe-uninitialized
 C ObjC C++ ObjC++ LTO LangEnabledBy(C ObjC C++ ObjC++ LTO,Wall)
 ;
diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index 1afec3fdc36..a9cfe68fd1e 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -8777,7 +8777,7 @@ pop_init_level (location_t loc, int implicit,
 
   /* Warn when some structs are initialized with direct aggregation.  */
   if (!implicit && found_missing_braces && warn_missing_braces
-      && !constructor_zeroinit)
+      && (!constructor_zeroinit || warn_zero_init))
     {
       gcc_assert (initializer_stack->missing_brace_richloc);
       warning_at (initializer_stack->missing_brace_richloc,
@@ -8801,8 +8801,9 @@ pop_init_level (location_t loc, int implicit,
 	    /* Do not warn if this level of the initializer uses member
 	       designators; it is likely to be deliberate.  */
 	    && !constructor_designated
-	    /* Do not warn about initializing with { 0 } or with { }.  */
-	    && !constructor_zeroinit)
+	    /* Do not warn about initializing with { 0 } or with { }
+	       unless warn_zero_init.  */
+	    && (!constructor_zeroinit || warn_zero_init))
 	  {
 	    if (warning_at (input_location, OPT_Wmissing_field_initializers,
 			    "missing initializer for field %qD of %qT",
@@ -8815,7 +8816,7 @@ pop_init_level (location_t loc, int implicit,
 
   /* Warn when positional initializers are used for a structure with
      the designated_init attribute, but make an exception for { 0 }.  */
-  if (!constructor_zeroinit
+  if ((!constructor_zeroinit || warn_zero_init)
       && vec_safe_length (initializer_stack->positional_init_info))
     {
       struct positional_init_info info;
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index ba18e05fb1a..38da2ff0bd5 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -371,7 +371,7 @@ Objective-C and Objective-C++ Dialects}.
 -Wno-switch-outside-range  -Wno-switch-unreachable  -Wsync-nand @gol
 -Wsystem-headers  -Wtautological-compare  -Wtrampolines  -Wtrigraphs @gol
 -Wtype-limits  -Wundef @gol
--Wuninitialized  -Wunknown-pragmas @gol
+-Wuninitialized  -Wno-universal-initializer  -Wunknown-pragmas @gol
 -Wunsuffixed-float-constants  -Wunused @gol
 -Wunused-but-set-parameter  -Wunused-but-set-variable @gol
 -Wunused-const-variable  -Wunused-const-variable=@var{n} @gol
@@ -6512,6 +6512,26 @@ to compute a value that itself is never used, because such
 computations may be deleted by data flow analysis before the warnings
 are printed.
 
+@item -Wuniversal-initializer
+@opindex Wuniversal-initializer
+@opindex Wno-universal-initializer
+Do not suppress warnings about the universal zero initializer,
+@code{@{ 0 @}}, where a warning would otherwise be produced.  For
+example, even with @option{-Wmissing-braces}, the following would not
+warn, because an exception is made for the universal initializer:
+
+@smallexample
+int a[1][1] = @{ 0 @};
+@end smallexample
+
+However, if @code{-Wuniversal-initializer} is used, that code would
+produce a warning (caused by @option{-Wmissing-braces}).
+
+This warning is not enabled by default, nor is it enabled by any other
+options.  If you don't want to suppress warnings about the universal
+zero initializer, you must specify @option{-Wuniversal-initializer}
+explicitly.
+
 @item -Wno-invalid-memory-model
 @opindex Winvalid-memory-model
 @opindex Wno-invalid-memory-model
diff --git a/gcc/testsuite/gcc.dg/Wuniversal-initializer.c b/gcc/testsuite/gcc.dg/Wuniversal-initializer.c
new file mode 100644
index 00000000000..803dfd10e1c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wuniversal-initializer.c
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-options "-Wall -Wmissing-field-initializers -Wuniversal-initializer" } */
+
+struct Pok {
+  int x;
+  int y;
+};
+
+struct Nest {
+  struct Pok p;
+};
+
+struct Des {
+  int a;
+} __attribute__((designated_init));
+
+struct Pok p = { 0 }; /* { dg-warning "missing initializer for field" } */
+struct Nest n = { 0 }; /* { dg-warning "missing braces around initializer" } */
+struct Des d = { 0 }; /* { dg-warning "(positional|near initialization)" } */
+int a[1][1] = { 0 };  /* { dg-warning "missing braces around initializer" } */
-- 
2.27.0

Thanks,
Asher

-- 
<cas> well there ya go.  say something stupid in irc and have it
      immortalised forever in someone's .sig file
                               --------
I prefer to send and receive mail encrypted. Please send me your
public key, and if you do not have my public key, please let me
know. Thanks.

GPG fingerprint: 38F3 975C D173 4037 B397  8095 D4C9 C4FC 5460 8E68

Attachment: signature.asc
Description: PGP signature

Reply via email to