public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c: Fix up error-recovery on non-empty VLA initializers [PR109409]
@ 2023-04-14 19:20 Jakub Jelinek
  2023-04-24 20:48 ` Joseph Myers
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2023-04-14 19:20 UTC (permalink / raw)
  To: Joseph S. Myers, Marek Polacek; +Cc: gcc-patches

Hi!

On the following testcase we ICE, because after we emit the
variable-sized object may not be initialized except with an empty initializer
error we don't really reset the initializer to error_mark_node and then at
-Wformat checking time we ICE on seeing STRING_CST initializer for a VLA.

The following patch just arranges for error_mark_node to be returned after
the error diagnostics.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2023-04-14  Jakub Jelinek  <jakub@redhat.com>

	PR c/109409
	* c-parser.cc (c_parser_initializer): Move diagnostics about
	initialization of variable sized object with non-empty initializer
	after c_parser_expr_no_commas call and ret.set_error (); after it.

	* gcc.dg/pr109409.c: New test.

--- gcc/c/c-parser.cc.jj	2023-02-18 12:38:30.759025693 +0100
+++ gcc/c/c-parser.cc	2023-04-13 13:09:13.287373656 +0200
@@ -5677,11 +5677,14 @@ c_parser_initializer (c_parser *parser,
     {
       struct c_expr ret;
       location_t loc = c_parser_peek_token (parser)->location;
-      if (decl != error_mark_node && C_DECL_VARIABLE_SIZE (decl))
-	error_at (loc,
-		  "variable-sized object may not be initialized except "
-		  "with an empty initializer");
       ret = c_parser_expr_no_commas (parser, NULL);
+      if (decl != error_mark_node && C_DECL_VARIABLE_SIZE (decl))
+	{
+	  error_at (loc,
+		    "variable-sized object may not be initialized except "
+		    "with an empty initializer");
+	  ret.set_error ();
+	}
       /* This is handled mostly by gimplify.cc, but we have to deal with
 	 not warning about int x = x; as it is a GCC extension to turn off
 	 this warning but only if warn_init_self is zero.  */
--- gcc/testsuite/gcc.dg/pr109409.c.jj	2023-04-13 13:31:52.865765576 +0200
+++ gcc/testsuite/gcc.dg/pr109409.c	2023-04-13 13:13:26.994714440 +0200
@@ -0,0 +1,10 @@
+/* PR c/109409 */
+/* { dg-do compile } */
+/* { dg-options "-Wall" } */
+
+void
+foo (int n)
+{
+  const char c[n] = "1";	/* { dg-error "variable-sized object may not be initialized except with an empty initializer" } */
+  __builtin_printf (c);
+}

	Jakub


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] c: Fix up error-recovery on non-empty VLA initializers [PR109409]
  2023-04-14 19:20 [PATCH] c: Fix up error-recovery on non-empty VLA initializers [PR109409] Jakub Jelinek
@ 2023-04-24 20:48 ` Joseph Myers
  0 siblings, 0 replies; 2+ messages in thread
From: Joseph Myers @ 2023-04-24 20:48 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Marek Polacek, gcc-patches

On Fri, 14 Apr 2023, Jakub Jelinek via Gcc-patches wrote:

> Hi!
> 
> On the following testcase we ICE, because after we emit the
> variable-sized object may not be initialized except with an empty initializer
> error we don't really reset the initializer to error_mark_node and then at
> -Wformat checking time we ICE on seeing STRING_CST initializer for a VLA.
> 
> The following patch just arranges for error_mark_node to be returned after
> the error diagnostics.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-04-24 20:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-14 19:20 [PATCH] c: Fix up error-recovery on non-empty VLA initializers [PR109409] Jakub Jelinek
2023-04-24 20:48 ` Joseph Myers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).