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 A70943858410 for ; Fri, 14 Jul 2023 15:17:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A70943858410 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=1689347822; 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=dvGp6BnNwbIsyxwgcMcUZQTIr1Nm+6EP/YJAYTkfJHw=; b=KQ0oplfZ3xDYy39SocOyxtmDiW8Kca8f2hzWuthdw84rSkiCQ2h2add2axt0fwZ+2jud9a GFOoov8TDvrj1X5PJBESLAPyev3NhncyHGpQ4fwbS74yy4EWLjtFKUQwizbqunvFApFxEC N0//qIRdyFNSawVOj2P3qn5JqRDoUYQ= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-609-fuMhtHqDMf-bvPfc3uKQsA-1; Fri, 14 Jul 2023 11:17:01 -0400 X-MC-Unique: fuMhtHqDMf-bvPfc3uKQsA-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-635e0889cc5so20970286d6.2 for ; Fri, 14 Jul 2023 08:17:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689347820; x=1691939820; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:subject:from:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dvGp6BnNwbIsyxwgcMcUZQTIr1Nm+6EP/YJAYTkfJHw=; b=NUOvp5j5onjmtcPeC90RGQhcZ/Yjen8X1YmDz8bfySlezmcJ7UI8bXMU3tHOFAFzay uO/UBZTJIhkHhiKzFLD/UqTOKpYoyn+3SHunqLxtvBdlm4SsY9o5hs024/NmNEKps0Ie cUKnZq/84jaW/6qF3m0TcP8tZFHNjWdVmoQ2a/Reru5ta5XLz6/RHIIPHPNWH7sbSTQT mMThL/F3lQ1LcSjQcik8z/8dsCR/6S3VDJLK47dsWniYv16QrXVfWaZeW2++4xNzUK30 1WAOeBAWAdZ9jBflWyjBtHyj6HCkEV02o3LfpK6v+N+8Zj6iYhQCEl2kvKL1LiMSQH8Q rr2A== X-Gm-Message-State: ABy/qLYoEmnhzSYv+52NSrwOV6/L3pxw+i/ekxMLpJ7IMOh9cvQbwHOh ECutuRorVEDk9uBYhZT5vYt5MfyPcDX83XGcERaBZMspikJ1PJWj/ODh8wc20yrCNL4QAO2h3Cy 2/njS1VMls2iQGbRIyA== X-Received: by 2002:a0c:f24c:0:b0:63c:6d10:8659 with SMTP id z12-20020a0cf24c000000b0063c6d108659mr1834848qvl.46.1689347820651; Fri, 14 Jul 2023 08:17:00 -0700 (PDT) X-Google-Smtp-Source: APBJJlHFJpgdtt20iCPtBQIbi6uxES2uOmNud+T8D00RC5Fyaub4ndh0TLkYD7hxGb/gvwDzWXFa3A== X-Received: by 2002:a0c:f24c:0:b0:63c:6d10:8659 with SMTP id z12-20020a0cf24c000000b0063c6d108659mr1834833qvl.46.1689347820329; Fri, 14 Jul 2023 08:17:00 -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 b10-20020a0cf04a000000b0063c79938606sm151381qvl.120.2023.07.14.08.16.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 14 Jul 2023 08:16:59 -0700 (PDT) Message-ID: <1abfe7ac-1d9e-da4c-3f09-9e446b7ca3ff@redhat.com> Date: Fri, 14 Jul 2023 11:16:58 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 From: Jason Merrill Subject: Re: [PATCH v3 1/3] c++: Track lifetimes in constant evaluation [PR70331,PR96630,PR98675] To: Nathaniel Shead , gcc-patches@gcc.gnu.org Cc: Patrick Palka References: 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=-12.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,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 6/30/23 23:28, Nathaniel Shead via Gcc-patches wrote: > This adds rudimentary lifetime tracking in C++ constexpr contexts, Thanks! I'm not seeing either a copyright assignment or DCO certification for you; please see https://gcc.gnu.org/contribute.html#legal for more information. > diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc > index cca0435bafc..bc59b4aab67 100644 > --- a/gcc/cp/constexpr.cc > +++ b/gcc/cp/constexpr.cc > @@ -1188,7 +1190,12 @@ public: > if (!already_in_map && modifiable) > modifiable->add (t); > } > - void remove_value (tree t) { values.remove (t); } > + void remove_value (tree t) > + { > + if (DECL_P (t)) > + outside_lifetime.add (t); > + values.remove (t); What if, instead of removing the variable from one hash table and adding it to another, we change the value to, say, void_node? > + /* Also don't cache a call if we return a pointer to an expired > + value. */ > + if (cacheable && (cp_walk_tree_without_duplicates > + (&result, find_expired_values, > + &ctx->global->outside_lifetime))) > + cacheable = false; I think we need to reconsider cacheability in general; I think we only want to cache calls that are themselves valid constant expressions, in that the return value is a "permitted result of a constant expression" (https://eel.is/c++draft/expr.const#13). A pointer to an automatic variable is not, whether or not it is currently within its lifetime. That is, only cacheable if reduced_constant_expression_p (result). I'm experimenting with this now, you don't need to mess with it. > @@ -7085,7 +7138,7 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, > case PARM_DECL: > if (lval && !TYPE_REF_P (TREE_TYPE (t))) > /* glvalue use. */; > - else if (tree v = ctx->global->get_value (r)) > + else if (tree v = ctx->global->get_value (t)) I agree with this change, but it doesn't have any actual effect, right? I'll go ahead and apply it separately. > @@ -7328,17 +7386,28 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, > auto_vec cleanups; > vec *prev_cleanups = ctx->global->cleanups; > ctx->global->cleanups = &cleanups; > - r = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 0), > + > + auto_vec save_exprs; Now that we're going to track temporaries for each full-expression, I think we shouldn't also need to track them for loops and calls. Jason