From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id B997E3858C5E for ; Fri, 14 Apr 2023 19:20:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B997E3858C5E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681500059; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=EIp8DkF4rCbaFqVy5CG0TABTxgsWbUzXPZsAfGc+rMk=; b=YP5nz7rbCmG5NZ3EiJZHGZbClBckbdTHqLc1rQIP302Qoau7J4uAjgJ74BLadzGwSc0IR4 sT5CBmD7KkyFpLjbksd0tCy9Es7RW3rv7a4O35bn4KcFYMWzz9wjcz97xhmjHHmJVuEc8V RpMu13ugw1tJnBaaC4fXETV7dlyEem0= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-63-uZR0f4vgODWl0OCIIHFEYA-1; Fri, 14 Apr 2023 15:20:58 -0400 X-MC-Unique: uZR0f4vgODWl0OCIIHFEYA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B64A08996E2; Fri, 14 Apr 2023 19:20:57 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A6E1140C6E70; Fri, 14 Apr 2023 19:20:56 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 33EJKnIt1939336 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 14 Apr 2023 21:20:49 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 33EJKm101939333; Fri, 14 Apr 2023 21:20:48 +0200 Date: Fri, 14 Apr 2023 21:20:48 +0200 From: Jakub Jelinek To: "Joseph S. Myers" , Marek Polacek Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c: Fix up error-recovery on non-empty VLA initializers [PR109409] Message-ID: Reply-To: Jakub Jelinek MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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 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