From patchwork Fri Mar 3 15:18:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 63970 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp465944wrd; Fri, 3 Mar 2023 07:19:26 -0800 (PST) X-Google-Smtp-Source: AK7set/DHLqwsmXGYtx73U0a5V7Wn0CDwyNIUXonMI6AwqNtJNZHEuOiPll29Jm8sTWW3iY2Ud5P X-Received: by 2002:a05:6402:1503:b0:4ab:553:75d8 with SMTP id f3-20020a056402150300b004ab055375d8mr2003602edw.10.1677856766126; Fri, 03 Mar 2023 07:19:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677856766; cv=none; d=google.com; s=arc-20160816; b=ww0Y7qp4a3KJAkTkrAVpAiFEA5Y8JH+KVdOAKFMDlCDQiDn1xAscvzG7Dg48PEXKOH L5IJ5tRhxgloy7+q+yLN4AJ/ZH1kJmApSM3nWXs6acPVFBALL1+dF04gxnhvWh+WPY7K xa98WAqlpYVw8J2eYbV0kFyz7IP/suPkIBuQtsFnpXDh8EXRCxHZPaG8zh2xU2HvMUQe 73H3VSQUO6SbgE3YjURfQXzwZWwnCsNjmIPB91xWlbtm3M0Mzo1oAhX1nDM/3pWiexI0 2wfpENuNYZxKuhdPkcBGRL9GDT6Tb/HkVsrt7VI/gmsm/hDcOTZDWxUqqLzybw/E3/Yf Aqfg== 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:in-reply-to:mime-version:references:message-id :subject:cc:to:date:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=MD/BYZvMK92k1WvLPvVbBqLHHCdGPDNhlVxl1xPzpTg=; b=Hh3B3QQjeOFEOB14EONznF/xhxo20BDwHwKCkCZXT6h7RlW+WajSskWCZ/5zCpwT5t 2CborGP0ReQerScgBhMBkEJko09FXJluXF4zdMYL8Ds1e4YBjWTzxzWhTsEosTgsGKZc QwIULpRrpEBSwgTZ3k9rJ/GjqUM5xewTHm/3PKmd6V1zUwc2bygS71R9vidraKdHe4xJ IhxywapG/xR4xZOXD3d39LHcET1+3OBK0BmREG3R5HcAjaevesZe7oHLF9ZOxxkg+oRD UAm3zL0HN0CLLsFZlbDUFp9iWlVKa3toLTyZvn835uYFDDjufLzr6yyhuPGjZnRTNrGi uSHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Y3We8d64; 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 j5-20020aa7c0c5000000b004c2f8f5bff2si2930893edp.428.2023.03.03.07.19.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Mar 2023 07:19:26 -0800 (PST) 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=Y3We8d64; 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 4115C3857352 for ; Fri, 3 Mar 2023 15:19:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4115C3857352 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677856761; bh=MD/BYZvMK92k1WvLPvVbBqLHHCdGPDNhlVxl1xPzpTg=; h=Date:To:Cc:Subject:References:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=Y3We8d64o10dztwKWfUcvTTBkwxRIwQZk/IRJEKljSwWH5o0q0nlKQmLEdHKLliXn PlEFjLZ/rg676t7ov7l+gMDxkhXAzst3p2HZQ2qWsxpyaRXBvOC18WvowBqEV9xS5I n3T3uG6xhF2/eW0PC5/0dQUrkO/Z70BPp8gTZrJU= 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 E44643858C78 for ; Fri, 3 Mar 2023 15:18:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E44643858C78 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-638-W-MQ7n_oN4yRzu_ZfCYbuQ-1; Fri, 03 Mar 2023 10:18:25 -0500 X-MC-Unique: W-MQ7n_oN4yRzu_ZfCYbuQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C8B181C0754B for ; Fri, 3 Mar 2023 15:18:24 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 87D9B440D8; Fri, 3 Mar 2023 15:18:24 +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 323FIMe52485283 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 3 Mar 2023 16:18:22 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 323FIMDe2485282; Fri, 3 Mar 2023 16:18:22 +0100 Date: Fri, 3 Mar 2023 16:18:21 +0100 To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c++, v2: Don't defer local statics initialized with constant expressions [PR108702] Message-ID: References: <5aff4f89-5f00-c71a-5681-3d481a354c9b@redhat.com> MIME-Version: 1.0 In-Reply-To: <5aff4f89-5f00-c71a-5681-3d481a354c9b@redhat.com> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.7 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 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?1759360336555982044?= X-GMAIL-MSGID: =?utf-8?q?1759360336555982044?= On Thu, Mar 02, 2023 at 11:48:04AM -0500, Jason Merrill wrote: > > The stmtexpr19.C testcase used to be rejected as it has a static > > variable in statement expression in constexpr context, but as that > > static variable is initialized by constant expression, when P2647R1 > > was implemented we agreed to make it valid. > > > > Now, as reported, the testcase compiles fine, but doesn't actually link > > because the static variable isn't defined anywhere, and with -flto ICEs > > because of this problem. This is because we never > > varpool_node::finalize_decl those vars, the constant expression in which > > the DECL_EXPR is present for the static VAR_DECL is folded (constant > > evaluated) into just the address of the VAR_DECL. > > Would it make sense to define it when we see the DECL_EXPR in constant > evaluation? So like this? Passes GXX_TESTSUITE_STDS=98,11,14,17,20,2b make check-g++ so far. 2023-03-03 Jakub Jelinek PR c++/108702 * constexpr.cc: Include toplev.h. (cxx_eval_constant_expression) : When seeing a local static initialized by constant expression outside of a constexpr function which has been deferred by make_rtl_for_nonlocal_decl, call rest_of_decl_compilation on it. * g++.dg/ext/stmtexpr19.C: Use dg-do link rather than dg-do compile. Jakub --- gcc/cp/constexpr.cc.jj 2023-03-03 00:34:44.113679918 +0100 +++ gcc/cp/constexpr.cc 2023-03-03 13:26:57.602871900 +0100 @@ -40,6 +40,7 @@ along with GCC; see the file COPYING3. #include "attribs.h" #include "fold-const.h" #include "intl.h" +#include "toplev.h" static bool verify_constant (tree, bool, bool *, bool *); #define VERIFY_CONSTANT(X) \ @@ -7127,6 +7128,24 @@ cxx_eval_constant_expression (const cons break; } + /* make_rtl_for_nonlocal_decl could have deferred emission of + a local static var, but if it appears in a statement expression + which is constant expression evaluated to e.g. just the address + of the variable, its DECL_EXPR will never be seen during + gimple lowering's record_vars_into as the statement expression + will not be in the IL at all. */ + if (VAR_P (r) + && TREE_STATIC (r) + && !DECL_REALLY_EXTERN (r) + && DECL_FUNCTION_SCOPE_P (r) + && !var_in_maybe_constexpr_fn (r) + && decl_constant_var_p (r)) + { + varpool_node *node = varpool_node::get (r); + if (node == NULL || !node->definition) + rest_of_decl_compilation (r, 0, at_eof); + } + if (AGGREGATE_TYPE_P (TREE_TYPE (r)) || VECTOR_TYPE_P (TREE_TYPE (r))) { --- gcc/testsuite/g++.dg/ext/stmtexpr19.C.jj 2023-02-09 15:52:29.623359240 +0100 +++ gcc/testsuite/g++.dg/ext/stmtexpr19.C 2023-03-03 12:24:20.217186735 +0100 @@ -1,6 +1,6 @@ // PR c++/81073 // { dg-options "" } -// { dg-do compile { target c++11 } } +// { dg-do link { target c++11 } } struct test { const int *addr; };