public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/70796] [DR 1030] Initialization order with braced-init-lists still broken
Date: Wed, 03 Nov 2021 19:42:01 +0000	[thread overview]
Message-ID: <bug-70796-4-3rwzv5Zfx0@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-70796-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70796

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
cp_gimplify_expr uses for CALL_EXPR_REVERSE_ARGS and CALL_EXPR_ORDERED_ARGS
(and for !CALL_EXPR_OPERATOR_SYNTAX method calls) gimplify_arg, but that
clearly isn't enough once there are any TREE_SIDE_EFFECTS on any of the
arguments.
Because e.g. for the ++i, ++i arguments for scalar non-addressable VAR_DECL i,
we end up with:
      i = i + 1;
      i = i + 1;
      C::C (&p, i, i);
which is wrong, is_gimple_val is true on i, but we really need to gimplify the
argument using gimplify_to_rvalue with is_gimple_val test if is_gimple_reg_type
(TREE_TYPE (arg)) and any of the args that are supposed to be evaluated after
it has TREE_SIDE_EFFECTS set.
That seems an easy change and would be (except for -O0) even cheap.
This would fix foo in the #c5 testcase.
bar works because i is addressable and thus gimplification already forces it
into  SSA_NAME or temporary.
baz works because the (int &) casts also force
C::C (&p, *( ++i;, (int &) &i;), *( ++i;, (int &) &i;))
before gimplification, so it is again gimplified into SSA_NAMEs or temporaries.
But, qux needs some other fix.
B::B (&p, TARGET_EXPR <D.2274, *(const struct A &) A::operator++ (&i)>,
TARGET_EXPR <D.2275, *(const struct A &) A::operator++ (&i)>)
The problem is that gimplify_arg optimizes:
  /* In general, we allow lvalues for function arguments to avoid
     extra overhead of copying large aggregates out of even larger
     aggregates into temporaries only to copy the temporaries to
     the argument list.  Make optimizers happy by pulling out to
     temporaries those types that fit in registers.  */
  if (is_gimple_reg_type (TREE_TYPE (*arg_p)))
    test = is_gimple_val, fb = fb_rvalue;
  else
    {
      test = is_gimple_lvalue, fb = fb_either;
      /* Also strip a TARGET_EXPR that would force an extra copy.  */
      if (TREE_CODE (*arg_p) == TARGET_EXPR)
        {
          tree init = TARGET_EXPR_INITIAL (*arg_p);
          if (init
              && !VOID_TYPE_P (TREE_TYPE (init)))
            *arg_p = init;
        }
    }
where the stripping of the TARGET_EXPR avoids the copy that is needed.
So perhaps add some ordered argument to gimplify_arg, in calls from gimplify.c
pass false, and in calls from cp_gimplify_expr pass true if the current
argument in the desired evaluation order is followed by any TREE_SIDE_EFFECTS
arguments.

  parent reply	other threads:[~2021-11-03 19:42 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-70796-4@http.gcc.gnu.org/bugzilla/>
2021-11-03 13:30 ` matthijsvanduin at gmail dot com
2021-11-03 13:46 ` jason at gcc dot gnu.org
2021-11-03 18:56 ` jakub at gcc dot gnu.org
2021-11-03 19:42 ` jakub at gcc dot gnu.org [this message]
2021-11-19  9:09 ` cvs-commit at gcc dot gnu.org
2021-11-19  9:13 ` jakub at gcc dot gnu.org
2021-11-29  8:50 ` cvs-commit at gcc dot gnu.org
2022-05-10  8:21 ` cvs-commit at gcc dot gnu.org
2022-05-11  6:23 ` cvs-commit at gcc dot gnu.org
2022-05-11  6:32 ` jakub at gcc dot gnu.org

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=bug-70796-4-3rwzv5Zfx0@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /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).