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 717883858D37 for ; Fri, 3 Mar 2023 16:15:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 717883858D37 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=1677860154; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zxg6WaevHsYM/OThWM9NfOj3zux1OX11WoVh3tJ3174=; b=hyUPJaT2QjfJX/WBnXyPIH8RBgYCj4JwoKy1wICqv/+sNsIh9ZF6ov57bFzDc1nIvuMSmO JcqI5EwN6TFNXM8PA1Qe4S+fH+H6BqXZ+wwcxnKnuNJl3yxdYVmFQ9pNt4EsHnLn3XCN5W dE+FTzKXb0h5907N/JpLrLJqi5/ZL0A= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-151-jT7WgxTtPeSj1FOlr9zI4A-1; Fri, 03 Mar 2023 11:15:52 -0500 X-MC-Unique: jT7WgxTtPeSj1FOlr9zI4A-1 Received: by mail-qt1-f197.google.com with SMTP id ga17-20020a05622a591100b003bfdf586476so1754776qtb.7 for ; Fri, 03 Mar 2023 08:15:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677860152; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=zxg6WaevHsYM/OThWM9NfOj3zux1OX11WoVh3tJ3174=; b=vQR2uSDBAxF432qlxmoZkIKH2Z/OL8P6kOdNsRotOr8IhVQiySAL7fuYizEqVNYMcZ IQVgVbNZ6T2V0ryWcppT0xMOjg3RSJwCjBuHXV0D5vigj/prSIroEarwNPLrCUR3P8Bt E9XJ5OQLi6GLx0akxU3rZ9kXmRIceeNd0krRY2W9xjoD7enkxGp2UKnWrZaWfUMRrQUd PKxqLLEvABkcguc5BxdOxpfmrvuJw2Pd/ghVrmN6dyOErIFW4TvKphIj4qCUOTWK1Qbc PUsTrXQ8yyy2XUozsrkqBR4/HYKLInmTlVaa6Bcp1Px/9267TjVbM9IHrLyGtrm1HyIc Ptyw== X-Gm-Message-State: AO0yUKX7p/nlHy2UPTjtbr9B+Tfd9vdMVeEkE4D6xJ5R3grBIr4xM8VZ krFuUzKKAlp52RNCpzoWWCk83zcx0mqY4KS1rzhtp56Q6/+oVlXD+dOi8GcmybGOZuoK2NFYJeT 7U8F3bTdI/QYKVCbMcg== X-Received: by 2002:ac8:7e83:0:b0:3bf:c994:c9b3 with SMTP id w3-20020ac87e83000000b003bfc994c9b3mr3956039qtj.61.1677860152284; Fri, 03 Mar 2023 08:15:52 -0800 (PST) X-Google-Smtp-Source: AK7set8VSNdOuS8w8oRnKwtfjKaazKxJ9RUV9p9pBitxAa63FsHFivYKob2bvl3D8w+1DJyzr2Lnhg== X-Received: by 2002:ac8:7e83:0:b0:3bf:c994:c9b3 with SMTP id w3-20020ac87e83000000b003bfc994c9b3mr3955987qtj.61.1677860151875; Fri, 03 Mar 2023 08:15:51 -0800 (PST) Received: from [192.168.1.108] (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id g186-20020a37b6c3000000b007430494ab92sm1971967qkf.67.2023.03.03.08.15.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 03 Mar 2023 08:15:51 -0800 (PST) Message-ID: Date: Fri, 3 Mar 2023 11:15:49 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Subject: Re: [PATCH] c++, v2: Don't defer local statics initialized with constant expressions [PR108702] To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org References: <5aff4f89-5f00-c71a-5681-3d481a354c9b@redhat.com> From: Jason Merrill In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,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 List-Id: On 3/3/23 10:18, Jakub Jelinek wrote: > 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? OK, thanks. > 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. > > --- 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; }; > > > > Jakub >