public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Jason Merrill <jason@redhat.com>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] c++: Add support for __real__/__imag__ modifications in constant expressions [PR88174]
Date: Fri, 10 Jun 2022 21:57:06 +0200	[thread overview]
Message-ID: <YqOiEptkGLJlD3Kk@tucnak> (raw)
In-Reply-To: <4d9319d5-1890-7c99-6c1b-d940f873a590@redhat.com>

On Fri, Jun 10, 2022 at 01:27:28PM -0400, Jason Merrill wrote:
> > --- gcc/cp/constexpr.cc.jj	2022-06-08 08:21:02.973448193 +0200
> > +++ gcc/cp/constexpr.cc	2022-06-08 17:13:04.986040449 +0200
> > @@ -5707,6 +5707,20 @@ cxx_eval_store_expression (const constex
> >   	  }
> >   	  break;
> > +	case REALPART_EXPR:
> > +	  gcc_assert (probe == target);
> 
> Doesn't this assert mean that complex_expr will always be == valp?

No, even when handling the pushed *PART_EXPR, it will set
valp = &TREE_OPERAND (*valp, index != integer_zero_node);
So, valp will be either &TREE_OPERAND (*complex_expr, 0)
or &TREE_OPERAND (*complex_expr, 1).
As *valp = init; is what is usually then stored and we want to store there
the scalar.

> > @@ -5946,6 +5984,24 @@ cxx_eval_store_expression (const constex
> >   	    = get_or_insert_ctor_field (*valp, indexes[i], index_pos_hints[i]);
> >   	  valp = &cep->value;
> >   	}
> > +      if (complex_part != -1)
> > +	{
> > +	  if (TREE_CODE (*valp) == COMPLEX_CST)
> > +	    *valp = build2 (COMPLEX_EXPR, TREE_TYPE (*valp),
> > +			    TREE_REALPART (*valp),
> > +			    TREE_IMAGPART (*valp));
> > +	  else if (TREE_CODE (*valp) == CONSTRUCTOR
> > +		   && CONSTRUCTOR_NELTS (*valp) == 0
> > +		   && CONSTRUCTOR_NO_CLEARING (*valp))
> > +	    {
> > +	      tree r = build_constructor (TREE_TYPE (TREE_TYPE (*valp)), NULL);
> > +	      CONSTRUCTOR_NO_CLEARING (r) = 1;
> > +	      *valp = build2 (COMPLEX_EXPR, TREE_TYPE (*valp), r, r);
> > +	    }
> > +	  gcc_assert (TREE_CODE (*valp) == COMPLEX_EXPR);
> > +	  complex_expr = valp;
> > +	  valp = &TREE_OPERAND (*valp, complex_part);
> 
> I don't understand this block; shouldn't valp point to the real or imag part
> of the complex number at this point?  How could complex_part be set without
> us handling the complex case in the loop already?

Because for most references, the code will do:
      vec_safe_push (ctors, *valp);
      vec_safe_push (indexes, index);
I chose not to do this for *PART_EXPR, because the COMPLEX_EXPR isn't a
CONSTRUCTOR and code later on e.g. walks all the ctors and accesses
CONSTRUCTOR_NO_CLEARING on them etc.  As the *PART_EXPR is asserted to
be outermost only, complex_expr is a variant of that ctors push and
complex_part of the indexes.
The reason for the above if is just in case the evaluation of the rhs
of the store would store to the complex and could e.g. make it a COMPLEX_CST
again.

> > +	}
> >       }
> >     if (*non_constant_p)
> > @@ -6016,6 +6072,22 @@ cxx_eval_store_expression (const constex
> >   	if (TREE_CODE (TREE_TYPE (elt)) == UNION_TYPE)
> >   	  CONSTRUCTOR_NO_CLEARING (elt) = false;
> >         }
> > +  if (complex_expr)
> 
> I might have added the COMPLEX_EXPR to ctors instead of a separate variable,
> but this is fine too.

See above.
The COMPLEX_EXPR needs special handling (conversion into COMPLEX_CST if it
is constant) anyway.

	Jakub


  reply	other threads:[~2022-06-10 19:57 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-09  8:37 Jakub Jelinek
2022-06-10 17:27 ` Jason Merrill
2022-06-10 19:57   ` Jakub Jelinek [this message]
2022-06-17 17:06     ` [PATCH] c++, v2: " Jakub Jelinek
2022-06-20 20:03       ` Jason Merrill
2022-06-27 16:31         ` Jakub Jelinek
2022-07-04 15:50           ` [PATCH] c++, v3: " Jakub Jelinek
2022-07-05 20:44             ` Jason Merrill
2022-07-05 20:57               ` Jakub Jelinek
2022-07-27  9:09               ` [PATCH] c++, v4: " Jakub Jelinek
2022-08-06 22:41                 ` Jason Merrill

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=YqOiEptkGLJlD3Kk@tucnak \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@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).