From patchwork Tue Oct 11 20:00:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 1931 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp2275726wrs; Tue, 11 Oct 2022 13:00:56 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5JTsBK59RhwGq7+WTNlFLTiunIbod9n8JuTWPGkebZA5+viFuzllOKwPGVOcjXp0onDxqJ X-Received: by 2002:aa7:d7c5:0:b0:459:fad8:fd2 with SMTP id e5-20020aa7d7c5000000b00459fad80fd2mr24700080eds.336.1665518456655; Tue, 11 Oct 2022 13:00:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665518456; cv=none; d=google.com; s=arc-20160816; b=EV1nqB5RoZFU0hh4WJmcfqir6/Y7L+QmGmQFsERwSFGi74dCyNqRD4KiL2q/cFuZTq zWSLcWy/ZJLxe0pAcAD5OwsX7m7to2GlUJdPx3PIfW4h0Pimme8J9+WXKDCj9C+VidvY v6N1AzgE26Dl9g3pqVzLxUBaBN9n++hnkNHeMUq5eQL46vKkly1fNsbxIR9BG9B4P6jo oxzIgs2pPfCj/bHm4aFp5bhAFq5rqqhikumH10UdamfuteIeMQNdUqs+4b6hJ0uzr9OE vMqxFaGDruMI3sBb+fR4xnHq3qroGypwaFoRLjR+ufGkCzbEFKK4GHwlft55SPVBg1Pu Ivtg== 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-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=yj6hALuKpEcpMx1J0+u4viFjSv7UV1eRZqOGTbrD4ns=; b=oMkawjKNBugXbPQEtDSyong7dLWC9ljcUUILJ+j8j94Wo0GhFvT6mtAU0pw3y3SLtW 6hATysKt2byOZfnkOHugUu75lvPYT5vwS40S1wyV6mLTKvAaZiarp0K6W2ugXbJEuy4S TdCMhl5maJO36hdTeIpQWaslL113RrtYRHPVHP26LcVPTwtlWb4iEKYLretSXCYnD+/F CAOMukODQ58+UijaawfBo7hokQXrb6O1XendByBrAbhTSz9Ee0DQSTO9bOPwsG9kILjt v+Lw2uz/JJu2pzfJf0VqwwgYtCatqSC629I23/PCnaUHM5u7CBtj0tFBUPL495ZaWtnR u7yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=dMJJqy1r; 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 hr1-20020a1709073f8100b0078d4a0c77f9si18001069ejc.458.2022.10.11.13.00.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Oct 2022 13:00:56 -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=dMJJqy1r; 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 663893857BB3 for ; Tue, 11 Oct 2022 20:00:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 663893857BB3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665518455; bh=yj6hALuKpEcpMx1J0+u4viFjSv7UV1eRZqOGTbrD4ns=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=dMJJqy1rVO3TdA6GQyJX8zVGIjoHaNpXT6wYm+FDiribgbCP3frq1ufu+hZgf2kv+ A7KX1njgiil1xr80SWXO0NWgexA2uAPSXdmXAg2srRhXiFf8UR7bti0GF7vOVrBk2T BdrPSJ0ZWt3shIKd4EA5ZE7UhbNRP6tJPcSYPHk0= 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 920BB3858D28 for ; Tue, 11 Oct 2022 20:00:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 920BB3858D28 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-515-3yaEXJseM22mAy0jSrQSEA-1; Tue, 11 Oct 2022 16:00:11 -0400 X-MC-Unique: 3yaEXJseM22mAy0jSrQSEA-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 AECE185A583 for ; Tue, 11 Oct 2022 20:00:10 +0000 (UTC) Received: from pdp-11.redhat.com (unknown [10.22.17.139]) by smtp.corp.redhat.com (Postfix) with ESMTP id 912A2C15BB3; Tue, 11 Oct 2022 20:00:10 +0000 (UTC) To: GCC Patches , Jason Merrill Subject: [PATCH] c++: ICE with VEC_INIT_EXPR and defarg [PR106925] Date: Tue, 11 Oct 2022 16:00:03 -0400 Message-Id: <20221011200003.695682-1-polacek@redhat.com> 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 X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP 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: Marek Polacek via Gcc-patches From: Marek Polacek Reply-To: Marek Polacek 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?1746422681079847110?= X-GMAIL-MSGID: =?utf-8?q?1746422681079847110?= Since r12-8066, in cxx_eval_vec_init we perform expand_vec_init_expr while processing the default argument in this test. At this point start_preparsed_function hasn't yet set current_function_decl. expand_vec_init_expr then leads to maybe_splice_retval_cleanup which checks DECL_CONSTRUCTOR_P (current_function_decl) without checking that c_f_d is non-null first. It seems correct that c_f_d is null here, so it seems to me that maybe_splice_retval_cleanup should check c_f_d as in the following patch. Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/12? PR c++/106925 gcc/cp/ChangeLog: * except.cc (maybe_splice_retval_cleanup): Check current_function_decl. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/initlist-defarg3.C: New test. --- gcc/cp/except.cc | 3 +++ gcc/testsuite/g++.dg/cpp0x/initlist-defarg3.C | 13 +++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp0x/initlist-defarg3.C base-commit: 23c3cbaed36f6d2f3a7a64f6ebda69329723514b diff --git a/gcc/cp/except.cc b/gcc/cp/except.cc index b8a85ed0572..9f77289b9ca 100644 --- a/gcc/cp/except.cc +++ b/gcc/cp/except.cc @@ -1327,6 +1327,9 @@ maybe_splice_retval_cleanup (tree compound_stmt) && current_binding_level->level_chain->kind == sk_function_parms); if ((function_body || current_binding_level->kind == sk_try) + /* When we're processing a default argument, c_f_d may not have been + set. */ + && current_function_decl && !DECL_CONSTRUCTOR_P (current_function_decl) && !DECL_DESTRUCTOR_P (current_function_decl) && current_retval_sentinel) diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-defarg3.C b/gcc/testsuite/g++.dg/cpp0x/initlist-defarg3.C new file mode 100644 index 00000000000..5c3e886b306 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/initlist-defarg3.C @@ -0,0 +1,13 @@ +// PR c++/106925 +// { dg-do compile { target c++11 } } + +struct Foo; +template struct __array_traits { typedef Foo _Type[_Nm]; }; +template struct array { + typename __array_traits<_Nm>::_Type _M_elems; +}; +template struct MyVector { array data{}; }; +struct Foo { + float a{0}; +}; +void foo(MyVector<1> = MyVector<1>());