From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 49FB3385840A; Wed, 3 Nov 2021 19:42:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 49FB3385840A From: "jakub at gcc dot 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 7.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Nov 2021 19:42:02 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D70796 --- Comment #6 from Jakub Jelinek --- 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 =3D i + 1; i =3D 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 aft= er 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 temporar= ies. But, qux needs some other fix. B::B (&p, TARGET_EXPR , TARGET_EXPR ) 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 =3D is_gimple_val, fb =3D fb_rvalue; else { test =3D is_gimple_lvalue, fb =3D fb_either; /* Also strip a TARGET_EXPR that would force an extra copy. */ if (TREE_CODE (*arg_p) =3D=3D TARGET_EXPR) { tree init =3D TARGET_EXPR_INITIAL (*arg_p); if (init && !VOID_TYPE_P (TREE_TYPE (init))) *arg_p =3D 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 gimplif= y.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_EFFEC= TS arguments.=