From patchwork Fri Apr 14 19:20:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 83563 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp608868vqo; Fri, 14 Apr 2023 12:21:44 -0700 (PDT) X-Google-Smtp-Source: AKy350ZQqdoVgUKxsBXNkcZ9UDE8ETFbS6ppy0CRfI/THEc01HfCpjASIv07P0ubrSvLs06186+k X-Received: by 2002:a17:906:f75b:b0:94e:df38:6f45 with SMTP id jp27-20020a170906f75b00b0094edf386f45mr147147ejb.54.1681500103916; Fri, 14 Apr 2023 12:21:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681500103; cv=none; d=google.com; s=arc-20160816; b=yUxLl7Ec8I9HLjLExYT46ARFv/g3xQ3M/77LnIX7u4GwbDvabevAswJRGeAmvHBdux Rfx5iI7MaAmaFXyV8hvy6zyX/ie17gprxl1jx7BB+IaV6S5THovhkC2sh/MN7jJpKkHC qdlRugds/a3r9mza8QrsMkSofs256UFYzsSbJojg2ZpdCOZDMI+jsSa7QB3iue3d9XtV spmwEpweBKB6EuVINDsky7UpJzxhk44lrjK6X40YjAouBV77yV3G/9sM72yi8BKr2nGb pVHhFkLePKLfp2Ab9SKCoZnbUcUKSD/pRHCJZYKF3DVN45QL5XYRghJSH7V3uZqSG6tV Z30w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=EIp8DkF4rCbaFqVy5CG0TABTxgsWbUzXPZsAfGc+rMk=; b=a8MLWdCfvMyLPeH078dmKOBMA3N25aERmt2vs1kAAht4W2IsNPoUuJe7x2EBi44EGi 9m3M8q9A4+/a7MhvDkoYkESzOycYz01fjRe+cQlu4zfVjwYVTcjp5e4bYZblSblRkjnD GWU6GCcLEYouUr5K6ZytlegFGIkSsnlrHD2jES2VUXssPWidnZ49Alewc6ll/oqVK1IX B7qfFt5709zj2d6fHu3Pisd9D4kAOIJoRfNbRfW/rKYAe82/tLcimd8rEYgZySs2k7yH Tk6+PsGlusurUpJug/0Ls5GpqxgDE0lHxo/XGaPC/73A9zGdeLC3O2UFw5cpGndPwdV8 M75w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=LCggFUxK; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id mj8-20020a170906af8800b009476f9ececesi5381618ejb.890.2023.04.14.12.21.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Apr 2023 12:21:43 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=LCggFUxK; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 898BD3858C78 for ; Fri, 14 Apr 2023 19:21:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 898BD3858C78 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1681500102; bh=EIp8DkF4rCbaFqVy5CG0TABTxgsWbUzXPZsAfGc+rMk=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=LCggFUxK0cVCufXthhSbnzSEX1wqCrO+ajl1AuNIasRtKtw0+Sg608k5S4if7GZRD QxM7485JXrQ/gQzuW3+e68acnOLbHAMmkI5XH5Zqz35SoxyDvtxlnoFwt3OP7/GDAj Mbq/DYHpn6ntvya6Gx+BANtxEw9042YT+DM2UM7U= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 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 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: 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-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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763180653124824194?= X-GMAIL-MSGID: =?utf-8?q?1763180653124824194?= 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. Jakub --- 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); +}