From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-il1-x130.google.com (mail-il1-x130.google.com [IPv6:2607:f8b0:4864:20::130]) by sourceware.org (Postfix) with ESMTPS id 2FB54385841B for ; Sat, 22 Jul 2023 05:28:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2FB54385841B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-il1-x130.google.com with SMTP id e9e14a558f8ab-3487d75e4c5so12939305ab.0 for ; Fri, 21 Jul 2023 22:28:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690003731; x=1690608531; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=mgoELK4aP+90DKjHnuTvPNuL9eZoZGI/bsCMmjbAeMs=; b=VD4iWrUPpH9mnc0Iu608gQFIhkG+9RfmEdfd1AM0YohrJOASFZGaDnVnEEVl0M86Le bOmeUcj1mFlGfHEtDdJx42CTfivvMTNxi5lV+FIQa6ZsLJE3MqXA6p14lJhhGo72pfZ0 P88RSfYEUQEsB9KonVAQpUF2QtlL1qv0tKs2gN0vzKs+AGnTwpe4/HxG0l/um49w9pif iHqM3cy7bCBCUnUt2uh9lcQi/uxdU7zEorT7xa+jKpMNL3/6EAm/2tCMX9MDIlVx/s5V MlvzzgKtF/MRsGPp/T1jHv+BDVI5gVNRHgIDVpbGt34gQLqDzRpUI9vntMarY3BDniLc N2gA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690003731; x=1690608531; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=mgoELK4aP+90DKjHnuTvPNuL9eZoZGI/bsCMmjbAeMs=; b=VTADvXR76/R+4FigszeiaYKBYFaCi5S2QkAiJLog9LaSsbvTM4hdOYXJAcYAd7hVwy WRK9EKFVIsecinlAUqneCFnnE1JDKnEaAPGjw8fk77sRmHq1XEzVNQQEcvHq1sAxHaai HnnlCDOISiTcyL5vGBNeOeL1NUCSevJe5CJQ9rnkEinruJgbg0T8Ih+KXQHv9eqrP/J+ 07y1seT9j2lIrOLYCqLSX6rnZWpwLc3Tn9amug4xqo3MmfjtO7c/68oSzGpPoyHCUz8T kAa6WcXWC5fpaVnJlzhJtsLjvHI+GnhoPFAh289eEbh9kv4FE9jepoG2z1hy1p5SJCBO /liw== X-Gm-Message-State: ABy/qLaNhRtpYeFL7in/pQl5o3T9N0Bt+WtYdlAK2g2CQ6QSJCAA4GRa xI9N6fxYCbOKLrS9D6UxnuPEjcdOW9I= X-Google-Smtp-Source: APBJJlEIiPKVanBjTY8VrC6CIQjGoySto6Cc/KFcYHO1sBJoABX5+zJV2lnfq/kKj9H5nvZU8Frgvg== X-Received: by 2002:a05:6e02:1290:b0:345:d284:5c49 with SMTP id y16-20020a056e02129000b00345d2845c49mr2144784ilq.5.1690003731416; Fri, 21 Jul 2023 22:28:51 -0700 (PDT) Received: from Thaum.localdomain (59-102-120-25.tpgi.com.au. [59.102.120.25]) by smtp.gmail.com with ESMTPSA id y2-20020a170902b48200b001b53953f306sm4419937plr.178.2023.07.21.22.28.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jul 2023 22:28:50 -0700 (PDT) Date: Sat, 22 Jul 2023 15:28:47 +1000 From: Nathaniel Shead To: Jason Merrill Cc: gcc-patches@gcc.gnu.org, Patrick Palka Subject: Re: [PATCH v4 1/3] c++: Track lifetimes in constant evaluation [PR70331,PR96630,PR98675] Message-ID: References: <9e81ff7d-5f20-eae9-32f7-7d1806bd2a29@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9e81ff7d-5f20-eae9-32f7-7d1806bd2a29@redhat.com> X-Spam-Status: No, score=-5.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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 Thu, Jul 20, 2023 at 10:42:29AM -0400, Jason Merrill wrote: > 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. Thanks, this is very helpful to know. I'll keep this in mind. > > @@ -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 > Yup you're right; I didn't properly read the documentation on what a CONST_DECL was and misunderstood. I'll fix this up for the next version.