public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug d/101282] New: d: RHS value lost when a target_expr appears in a cond_expr
@ 2021-07-01 10:36 ibuclaw at gdcproject dot org
  2021-07-02 22:44 ` [Bug d/101282] d: RHS value lost when a target_expr modifies LHS " cvs-commit at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: ibuclaw at gdcproject dot org @ 2021-07-01 10:36 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 101282
           Summary: d: RHS value lost when a target_expr appears in a
                    cond_expr
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: d
          Assignee: ibuclaw at gdcproject dot org
          Reporter: ibuclaw at gdcproject dot org
  Target Milestone: ---

The assignment ends up looking like:

a = opCmp (&a, 0) < 0 ? TARGET_EXPR <D.4074, opUnary (&a) [return slot
optimization]> : a;

---
void main()
{
    struct CrippledInt
    {
        int impl;
        CrippledInt opUnary(string op : "-")()
        {
            return CrippledInt(-impl);
        }
        int opCmp(int i) { return (impl < i) ? -1 : (impl > i) ? 1 : 0; }
    }
    auto a = CrippledInt(120);
    a = -a;
    assert(a.impl == -120);
    a = a >= 0 ? a : -a;
    assert(a.impl == 120); // fails
}

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug d/101282] d: RHS value lost when a target_expr modifies LHS in a cond_expr
  2021-07-01 10:36 [Bug d/101282] New: d: RHS value lost when a target_expr appears in a cond_expr ibuclaw at gdcproject dot org
@ 2021-07-02 22:44 ` cvs-commit at gcc dot gnu.org
  2021-07-02 22:45 ` cvs-commit at gcc dot gnu.org
  2021-07-02 22:47 ` ibuclaw at gdcproject dot org
  2 siblings, 0 replies; 4+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-07-02 22:44 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Iain Buclaw <ibuclaw@gcc.gnu.org>:

https://gcc.gnu.org/g:c77230856eac2d28eb7bf10985846885c3c8727b

commit r12-1993-gc77230856eac2d28eb7bf10985846885c3c8727b
Author: Iain Buclaw <ibuclaw@gdcproject.org>
Date:   Sat Jul 3 00:13:29 2021 +0200

    d: RHS value lost when a target_expr modifies LHS in a cond_expr

    To prevent the RHS of an assignment modifying the LHS before the
    assignment proper, a target_expr is forced so that function calls that
    return with slot optimization modify the temporary instead.  This did
    not work for conditional expressions however, to give one example.  So
    now the RHS is always forced to a temporary.

            PR d/101282

    gcc/d/ChangeLog:

            * d-codegen.cc (build_assign): Force target_expr on RHS for non-POD
            assignment expressions.

    gcc/testsuite/ChangeLog:

            * gdc.dg/torture/pr101282.d: New test.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug d/101282] d: RHS value lost when a target_expr modifies LHS in a cond_expr
  2021-07-01 10:36 [Bug d/101282] New: d: RHS value lost when a target_expr appears in a cond_expr ibuclaw at gdcproject dot org
  2021-07-02 22:44 ` [Bug d/101282] d: RHS value lost when a target_expr modifies LHS " cvs-commit at gcc dot gnu.org
@ 2021-07-02 22:45 ` cvs-commit at gcc dot gnu.org
  2021-07-02 22:47 ` ibuclaw at gdcproject dot org
  2 siblings, 0 replies; 4+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-07-02 22:45 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Iain Buclaw
<ibuclaw@gcc.gnu.org>:

https://gcc.gnu.org/g:f67d7f9416be37c34c4188866fb3d10c1dbc7a2a

commit r11-8686-gf67d7f9416be37c34c4188866fb3d10c1dbc7a2a
Author: Iain Buclaw <ibuclaw@gdcproject.org>
Date:   Sat Jul 3 00:13:29 2021 +0200

    d: RHS value lost when a target_expr modifies LHS in a cond_expr

    To prevent the RHS of an assignment modifying the LHS before the
    assignment proper, a target_expr is forced so that function calls that
    return with slot optimization modify the temporary instead.  This did
    not work for conditional expressions however, to give one example.  So
    now the RHS is always forced to a temporary.

            PR d/101282

    gcc/d/ChangeLog:

            * d-codegen.cc (build_assign): Force target_expr on RHS for non-POD
            assignment expressions.

    gcc/testsuite/ChangeLog:

            * gdc.dg/torture/pr101282.d: New test.

    (cherry picked from commit c77230856eac2d28eb7bf10985846885c3c8727b)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug d/101282] d: RHS value lost when a target_expr modifies LHS in a cond_expr
  2021-07-01 10:36 [Bug d/101282] New: d: RHS value lost when a target_expr appears in a cond_expr ibuclaw at gdcproject dot org
  2021-07-02 22:44 ` [Bug d/101282] d: RHS value lost when a target_expr modifies LHS " cvs-commit at gcc dot gnu.org
  2021-07-02 22:45 ` cvs-commit at gcc dot gnu.org
@ 2021-07-02 22:47 ` ibuclaw at gdcproject dot org
  2 siblings, 0 replies; 4+ messages in thread
From: ibuclaw at gdcproject dot org @ 2021-07-02 22:47 UTC (permalink / raw)
  To: gcc-bugs

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

Iain Buclaw <ibuclaw at gdcproject dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #3 from Iain Buclaw <ibuclaw at gdcproject dot org> ---
Fixed.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-07-02 22:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-01 10:36 [Bug d/101282] New: d: RHS value lost when a target_expr appears in a cond_expr ibuclaw at gdcproject dot org
2021-07-02 22:44 ` [Bug d/101282] d: RHS value lost when a target_expr modifies LHS " cvs-commit at gcc dot gnu.org
2021-07-02 22:45 ` cvs-commit at gcc dot gnu.org
2021-07-02 22:47 ` ibuclaw at gdcproject dot org

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).