From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 227BA3858416; Thu, 27 Apr 2023 09:42:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 227BA3858416 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682588522; bh=ugVKMlu0zxKW7WV3Fcw4TVjLW1dkBkakn/gDSXz6RnE=; h=From:To:Subject:Date:From; b=xmlIptEIElamQBouuGWaOhuizkrqFSapIaY8PF60mI+ng8WQppQZuJUnMQYkcnzl6 zzPAAqKQoG/7gf9bmy5GtZMNGMk+KO6n4WUzC71FYPmzysZYqpUK873mhKJDeloust MyotxS32hAEAZqKoRDhb8WEZcBKOYK3NpHxfm/ig= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-7258] c: Fix up error-recovery on non-empty VLA initializers [PR109409] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/releases/gcc-13 X-Git-Oldrev: 7e312adcb70ca7d67f0c2cf238cddec9b3243ff9 X-Git-Newrev: 297d0efc13d73d36371583c2d6d6e7a47f88cd02 Message-Id: <20230427094202.227BA3858416@sourceware.org> Date: Thu, 27 Apr 2023 09:42:02 +0000 (GMT) List-Id: https://gcc.gnu.org/g:297d0efc13d73d36371583c2d6d6e7a47f88cd02 commit r13-7258-g297d0efc13d73d36371583c2d6d6e7a47f88cd02 Author: Jakub Jelinek Date: Thu Apr 27 11:36:54 2023 +0200 c: Fix up error-recovery on non-empty VLA initializers [PR109409] 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. 2023-04-27 Jakub Jelinek 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. (cherry picked from commit d8842271ebf9a81128df9ae80e1d3b688749eac8) Diff: --- gcc/c/c-parser.cc | 11 +++++++---- gcc/testsuite/gcc.dg/pr109409.c | 10 ++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc index 21bc3167ce2..3627a3fbdc7 100644 --- a/gcc/c/c-parser.cc +++ b/gcc/c/c-parser.cc @@ -5677,11 +5677,14 @@ c_parser_initializer (c_parser *parser, tree decl) { 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. */ diff --git a/gcc/testsuite/gcc.dg/pr109409.c b/gcc/testsuite/gcc.dg/pr109409.c new file mode 100644 index 00000000000..097a511c07e --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr109409.c @@ -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); +}