From patchwork Fri Apr 14 19:15:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 83562 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp606293vqo; Fri, 14 Apr 2023 12:16:36 -0700 (PDT) X-Google-Smtp-Source: AKy350YtRkHNJaNdeUH1HMwAOQINJfCSqAGhYMFeSSVysxCCbnRJXU09n5bJYmXD0DuhPwsbsR1u X-Received: by 2002:a17:906:6bd0:b0:94e:f969:fb3e with SMTP id t16-20020a1709066bd000b0094ef969fb3emr176043ejs.43.1681499796363; Fri, 14 Apr 2023 12:16:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681499796; cv=none; d=google.com; s=arc-20160816; b=jVP3AhvQ2Hr4v0LlbYSehasHFCoPBePO7GlCf+9DZCWCG4LNrQFVj+mDibPPjaGHqn fFqQVPhrmimRNLed8eT1XhBS95IjfB4PFsslWXeQVmnGiRO+l8kjkwHLYsg+sa+3GZu9 fF/HHxGgKqO9mvBZZYwiA+nMFNlkwn2+ZccCZhAcNH4dH7YAg6HWl9fsl/rfnk+T6QCI p5qPgvxn7AxaikxJ5znNt7k0mvtz3gLbKbvYCmNWA7s4fDK+6PS69GU7AgLz92rv1toG 58IM8FfsEa7/AnuVYWTdop6SULhpDyFE1FUpMIKSkcnFbMeOZ05yicS+AHYnZoGBbR02 Cs6Q== 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=LVeZvsXnuKSJBJFhZbbX8puDEldTNg0MYVp0xrGjyR8=; b=GrHvbtiE51cRvjDYSNRbEls22vFJ3HovZPqTrB/CsoM1NL8ZE6cOcIlssvbDX3O4S9 77D0+X6md46KKjhavKgki6XcErYGpG5v8BoYKfD3dF3dEPJcWIsH7RRkHiwypnbJ0Spa Ij2v6r5x5muqP0q8qrR97o+LRWMPUBu61JzgcZTlAujZYE8J6H4iKqgSnLjKE/rFsQl3 3N7wSIbrsqOWDW4VadeUR1SsDpbQXMVlmUMc1oOnnkm9ZCMiZ9wjyNbia84n7/5hQHzi Ux5LaXUlHVnk8xvTJJoR34qFBUPmnq/DGhJ8oGMYnB6tdxQ6zTee/5en6M1lHhPmKHEK AfOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=rfbmFMu+; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id t23-20020aa7d717000000b00506884c922bsi798514edq.255.2023.04.14.12.16.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Apr 2023 12:16:36 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=rfbmFMu+; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 4351E3858408 for ; Fri, 14 Apr 2023 19:16:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4351E3858408 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1681499795; bh=LVeZvsXnuKSJBJFhZbbX8puDEldTNg0MYVp0xrGjyR8=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=rfbmFMu+FmR0UUiDcZ1xGEMy/7XHTInJku0C0hgs3AscKZB3y5gA649/DVkeyhkV0 SrVWMYLC0pB44HQbJb+wK37b255YM7l32cLgcZO19ZHqXwS4tpON2EFIrJ6EZ3pema 298jZ0TvthhTTjh3HHUTnG4mQrALoJVzghABsAaE= 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.133.124]) by sourceware.org (Postfix) with ESMTPS id 1D3AD3858C5E for ; Fri, 14 Apr 2023 19:15:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1D3AD3858C5E 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-562-xcVPiA7xPtyO6Glx-nq8Cw-1; Fri, 14 Apr 2023 15:15:49 -0400 X-MC-Unique: xcVPiA7xPtyO6Glx-nq8Cw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 87B5E8996E2; Fri, 14 Apr 2023 19:15:49 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2F81DC16028; Fri, 14 Apr 2023 19:15:48 +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 33EJFfLr1939094 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 14 Apr 2023 21:15:41 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 33EJFeSZ1939092; Fri, 14 Apr 2023 21:15:40 +0200 Date: Fri, 14 Apr 2023 21:15:40 +0200 To: "Joseph S. Myers" , Marek Polacek Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c: Fix up error-recovery on functions initialized as variables [PR109412] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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?1763180330277347155?= X-GMAIL-MSGID: =?utf-8?q?1763180330277347155?= Hi! The change to allow empty initializers in C broke error-recovery on the following testcase. We are emitting function %qD is initialized like a variable error early; if the initializer is non-empty, we just emit another error that the initializer is invalid. Previously if it was empty, we'd emit another error that scalar is being initialized by empty initializer (not really correct), but now we instead just try to build_zero_cst for the FUNCTION_TYPE and ICE on it. The following patch just emits the same diagnostics for the empty initializers as we emit for the non-empty ones. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-04-14 Jakub Jelinek PR c/107682 PR c/109412 * c-typeck.cc (pop_init_level): If constructor_type is FUNCTION_TYPE, reject empty initializer as invalid. * gcc.dg/pr109412.c: New test. Jakub --- gcc/c/c-typeck.cc.jj 2023-03-29 08:32:35.747720324 +0200 +++ gcc/c/c-typeck.cc 2023-04-13 11:37:30.353762300 +0200 @@ -9374,6 +9374,11 @@ pop_init_level (location_t loc, int impl { if (constructor_erroneous || constructor_type == error_mark_node) ret.value = error_mark_node; + else if (TREE_CODE (constructor_type) == FUNCTION_TYPE) + { + error_init (loc, "invalid initializer"); + ret.value = error_mark_node; + } else if (TREE_CODE (constructor_type) == POINTER_TYPE) /* Ensure this is a null pointer constant in the case of a 'constexpr' object initialized with {}. */ --- gcc/testsuite/gcc.dg/pr109412.c.jj 2023-04-13 12:06:27.820694502 +0200 +++ gcc/testsuite/gcc.dg/pr109412.c 2023-04-13 12:06:07.561986811 +0200 @@ -0,0 +1,20 @@ +/* PR c/107682 */ +/* PR c/109412 */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +char bar () = {}; /* { dg-error "function 'bar' is initialized like a variable" } */ + /* { dg-error "invalid initializer" "" { target *-*-* } .-1 } */ + /* { dg-message "near initialization for 'bar'" "" { target *-*-* } .-2 } */ +char baz () = { 1 }; /* { dg-error "function 'baz' is initialized like a variable" } */ + /* { dg-error "invalid initializer" "" { target *-*-* } .-1 } */ + /* { dg-message "near initialization for 'baz'" "" { target *-*-* } .-2 } */ +void +foo () +{ + int qux () = {}; /* { dg-error "function 'qux' is initialized like a variable" } */ + /* { dg-error "invalid initializer" "" { target *-*-* } .-1 } */ + /* { dg-message "near initialization for 'qux'" "" { target *-*-* } .-2 } */ + int corge () = { 1 }; /* { dg-error "function 'corge' is initialized like a variable" } */ + /* { dg-error "invalid initializer" "" { target *-*-* } .-1 } */ +} /* { dg-message "near initialization for 'corge'" "" { target *-*-* } .-2 } */