public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: Jakub Jelinek <jakub@redhat.com>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [C++ PATCH] Fix __builtin_{is_constant_evaluated,constant_p} handling in static_assert (PR c++/86524, PR c++/88446)
Date: Fri, 21 Dec 2018 02:51:00 -0000	[thread overview]
Message-ID: <4abcfe78-7e84-5188-6616-ddba47d9a5bd@redhat.com> (raw)
In-Reply-To: <20181220222719.GS23305@tucnak>

On 12/20/18 5:27 PM, Jakub Jelinek wrote:
> On Thu, Dec 20, 2018 at 04:47:29PM -0500, Jason Merrill wrote:
>>> So are you ok with what is in the patch below, i.e.
>>>          {
>>>            bool non_cst_p = false, ovf_p = false;
>>>            tree a = cxx_eval_constant_expression (&new_ctx, args[i], false,
>>>                                                   &non_cst_p, &ovf_p);
>>>            if ((!non_cst_p && !ovf_p) || !ctx->manifestly_const_eval)
>>>              args[i] = a;
>>>          }
>>> , or perhaps without the || !ctx->manifestly_const_eval?
>>
>> I don't see how that makes a difference from what was there before; if the
>> argument to cxx_eval_constant_expression is non-constant, it returns the
>> argument unchanged.
> 
> If that is guaranteed, then it is ok to keep it as is I guess.
> Will change it then.
> 
>>> So, if the
>>> argument is a constant expression, fold to that, if it is not, just do
>>> cp_fully_fold on it if it is __builtin_constant_p, otherwise nothing?
>>
>> Hmm, cp_fully_fold probably also needs to add a manifestly_const_eval
>> parameter to pass along to maybe_constant_value.
> 
> But if we need cp_fully_fold, doesn't that mean that the earlier
> cxx_eval_constant_expression failed and thus the argument is not a constant
> expression?  Should __builtin_is_constant_evaluated () evaluate to true
> even if the argument is not a constant expression?

Ah, no, good point.

> Say if there is
> int v;
> constexpr int foo (void)
> {
>    return __builtin_constant_p (v * (__builtin_is_constant_evaluated () ? 1 : 0));
> }
> Because v is not a constant expression,
> v * (__builtin_is_constant_evaluated () ? 1 : 0) shouldn't be either.
> 
> cp_fully_fold does:
>    /* FIXME cp_fold ought to be a superset of maybe_constant_value so we don't
>       have to call both.  */
>    if (cxx_dialect >= cxx11)
>      {
>        x = maybe_constant_value (x);
>        /* Sometimes we are given a CONSTRUCTOR but the call above wraps it into
>           a TARGET_EXPR; undo that here.  */
>        if (TREE_CODE (x) == TARGET_EXPR)
>          x = TARGET_EXPR_INITIAL (x);
>        else if (TREE_CODE (x) == VIEW_CONVERT_EXPR
>                 && TREE_CODE (TREE_OPERAND (x, 0)) == CONSTRUCTOR
>                 && TREE_TYPE (TREE_OPERAND (x, 0)) == TREE_TYPE (x))
>          x = TREE_OPERAND (x, 0);
>      }
>    return cp_fold_rvalue (x);
> Is there a reason to call that maybe_constant_value at all when we've called
> cxx_eval_constant_expression first?  Wouldn't cp_fold_rvalue (or
> c_fully_fold with false as last argument) be sufficient there?

I think that would be better, yes.

Jason

  reply	other threads:[~2018-12-21  2:49 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-12 22:30 Jakub Jelinek
2018-12-19 10:19 ` Patch ping (Re: [C++ PATCH] Fix __builtin_{is_constant_evaluated,constant_p} handling in static_assert (PR c++/86524, PR c++/88446)) Jakub Jelinek
2018-12-20 19:49 ` [C++ PATCH] Fix __builtin_{is_constant_evaluated,constant_p} handling in static_assert (PR c++/86524, PR c++/88446) Jason Merrill
2018-12-20 21:26   ` Jakub Jelinek
2018-12-20 21:28     ` Jason Merrill
2018-12-20 21:43       ` Jakub Jelinek
2018-12-20 21:47         ` Jason Merrill
2018-12-20 22:41           ` Jakub Jelinek
2018-12-21  2:51             ` Jason Merrill [this message]
2018-12-21  9:05               ` [C++ PATCH] Fix __builtin_{is_constant_evaluated,constant_p} handling in static_assert (PR c++/86524, PR c++/88446, take 2) Jakub Jelinek
2018-12-21 19:31                 ` 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=4abcfe78-7e84-5188-6616-ddba47d9a5bd@redhat.com \
    --to=jason@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@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).