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 A934C3858025 for ; Thu, 20 Jul 2023 14:42:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A934C3858025 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=1689864154; 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=VHxqv5HRYCVsO8BOf4OS4uy96nu8Aiv53G3yR19ExJM=; b=fXKNpsmeuf1UrmGsM2P4ImyYeSgFfILuQq8tcJ6SmJWYhTDUFmI+2+kssieF45my/Ykxp/ EZlnRMFOtrWx3/wLLjhrEzFXjS8bX2Om0kzmjpBOeRqnizaOEflCdFHe+OqQ4tVTI2eg7J 87byy6H2YyeYWon5oThZnjLmfkR5BfI= Received: from mail-oi1-f198.google.com (mail-oi1-f198.google.com [209.85.167.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-519-pgOODrK6MN-p690mXWpEew-1; Thu, 20 Jul 2023 10:42:31 -0400 X-MC-Unique: pgOODrK6MN-p690mXWpEew-1 Received: by mail-oi1-f198.google.com with SMTP id 5614622812f47-3a1bcdd0966so1650329b6e.2 for ; Thu, 20 Jul 2023 07:42:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689864151; x=1690468951; 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=VHxqv5HRYCVsO8BOf4OS4uy96nu8Aiv53G3yR19ExJM=; b=i/BLaK+B6wbUxUVT5UqCZor9m+nH+Bjxg9ksvpImaaewTdKgZLYs0xnmSAwFX6ujsP 0lVgk2aUfrf2rDMlugHKgk3XJX0FHAy/XHFEzZEQHQT2CPBj7bhmXUFW7LQVI+rv5zQr 05ZZdE3oTjc9QQvBZ6Iy+G4azw2TfxiYbL/gddLQvZdYgf/yeB8b77pFv1W673pH7kQG UPXkERrAnjmy8xxcSugQLcgkMb0vj9fTnay8WD7LVu3FwaeY32gjrbeVbjRSLSmrttDX 1CEtMt5fXWw+S9KlmvvhJilfi8Gbxg0F7ESJzZzHJ8CVUPe93oe7RJjYMsj7gBoy+Am9 5/6w== X-Gm-Message-State: ABy/qLY0s1J4z41OApXhi2YmTpDMYh16Tpib7or8muHNMvtS2uIxP7Ai JFDZUkuqa1qUqis4fWIsLL/yK5O1fdEVtWWMtSaar11uFhW/6g8rLzf5VcbrsBS1XyhZPEE7mDT 8a5A7V/mQXnu3mWmx1g== X-Received: by 2002:a05:6808:1387:b0:3a3:6506:2ec2 with SMTP id c7-20020a056808138700b003a365062ec2mr2363271oiw.35.1689864151123; Thu, 20 Jul 2023 07:42:31 -0700 (PDT) X-Google-Smtp-Source: APBJJlGveu7nXS5caLc4IMFKOuEeojq7Acyta2EoTZzb/jZR1W1ns0mGs5Z69B2DzZeCbFx8IMCKzQ== X-Received: by 2002:a05:6808:1387:b0:3a3:6506:2ec2 with SMTP id c7-20020a056808138700b003a365062ec2mr2363254oiw.35.1689864150819; Thu, 20 Jul 2023 07:42:30 -0700 (PDT) Received: from [192.168.1.108] (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id t9-20020a0cde09000000b00631ecb1052esm407760qvk.74.2023.07.20.07.42.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 20 Jul 2023 07:42:30 -0700 (PDT) Message-ID: <9e81ff7d-5f20-eae9-32f7-7d1806bd2a29@redhat.com> Date: Thu, 20 Jul 2023 10:42:29 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH v4 1/3] c++: Track lifetimes in constant evaluation [PR70331,PR96630,PR98675] To: Nathaniel Shead , gcc-patches@gcc.gnu.org Cc: Patrick Palka References: 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_H4,RCVD_IN_MSPIKE_WL,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 List-Id: On 7/20/23 05:35, Nathaniel Shead wrote: > This adds rudimentary lifetime tracking in C++ constexpr contexts, > allowing the compiler to report errors with using values after their > backing has gone out of scope. We don't yet handle other ways of > accessing values outside their lifetime (e.g. following explicit > destructor calls). Incidentally, much of that should be straightforward to handle by no longer ignoring clobbers here: > case MODIFY_EXPR: > if (cxx_dialect < cxx14) > goto fail; > if (!RECUR (TREE_OPERAND (t, 0), any)) > return false; > /* Just ignore clobbers. */ > if (TREE_CLOBBER_P (TREE_OPERAND (t, 1))) > return true; Assignment from a clobber represents end of lifetime to the middle-end. This can be a follow-up patch. > @@ -7051,10 +7065,17 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, > return ctx->ctor; > if (VAR_P (t)) > if (tree v = ctx->global->get_value (t)) > - { > - r = v; > - break; > - } > + { > + r = v; > + break; > + } > + if (ctx->global->is_outside_lifetime (t)) > + { > + if (!ctx->quiet) > + outside_lifetime_error (loc, t); > + *non_constant_p = true; > + break; > + } Shouldn't this new check also be under the if (VAR_P (t))? A CONST_DECL can't go out of scope. Jason