public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Nathaniel Shead <nathanieloshead@gmail.com>
To: Jason Merrill <jason@redhat.com>
Cc: gcc-patches@gcc.gnu.org, Patrick Palka <ppalka@redhat.com>
Subject: Re: [PATCH v4 1/3] c++: Track lifetimes in constant evaluation [PR70331,PR96630,PR98675]
Date: Sat, 22 Jul 2023 15:28:47 +1000	[thread overview]
Message-ID: <ZLtpD95D/pmML4ok@Thaum.localdomain> (raw)
In-Reply-To: <9e81ff7d-5f20-eae9-32f7-7d1806bd2a29@redhat.com>

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.

  reply	other threads:[~2023-07-22  5:28 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-20  9:33 [PATCH v4 0/3] c++: Track lifetimes in constant evaluation [PR70331, ...] Nathaniel Shead
2023-07-20  9:35 ` [PATCH v4 1/3] c++: Track lifetimes in constant evaluation [PR70331,PR96630,PR98675] Nathaniel Shead
2023-07-20 14:42   ` Jason Merrill
2023-07-22  5:28     ` Nathaniel Shead [this message]
2023-07-20  9:36 ` [PATCH v4 2/3] c++: Improve constexpr error for dangling local variables [PR110619] Nathaniel Shead
2023-07-20 15:46   ` Jason Merrill
2023-07-21  5:39     ` Nathaniel Shead
2023-07-21 21:44       ` Jason Merrill
2023-07-22  5:20         ` Nathaniel Shead
2023-07-20  9:37 ` [PATCH v4 3/3] c++: Improve location information in constant evaluation Nathaniel Shead
2023-07-20 17:00   ` Jason Merrill
2023-07-22  5:26     ` Nathaniel Shead

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZLtpD95D/pmML4ok@Thaum.localdomain \
    --to=nathanieloshead@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    --cc=ppalka@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).