www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12153] New: Ternary operator on static array lvalues creates copy

reply d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12153

           Summary: Ternary operator on static array lvalues creates copy
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: thecybershadow gmail.com


--- Comment #0 from Vladimir Panteleev <thecybershadow gmail.com> 2014-02-13
21:39:54 EET ---
void main()
{
    int[1] i, j; 
    bool b = true;
    (b ? i : j) = [4];
    assert(i == [4]);
}

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 13 2014
next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12153


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yebblies gmail.com


--- Comment #1 from yebblies <yebblies gmail.com> 2014-02-16 02:21:21 EST ---
Sigh, the backend sees

int[1] i = 0;
int[1] j = 0;
bool b = true;
(b ? i : j)[] = [4];
assert(i == [4]);
return 0;

Another bug caused by lowering static array ops to slice ops.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 15 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12153


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull
           Severity|normal                      |major


--- Comment #2 from Kenji Hara <k.hara.pg gmail.com> 2014-02-19 01:47:31 PST ---
(In reply to comment #1)
 Sigh, the backend sees
 
 int[1] i = 0;
 int[1] j = 0;
 bool b = true;
 (b ? i : j)[] = [4];
 assert(i == [4]);
 return 0;
 
 Another bug caused by lowering static array ops to slice ops.

Translating to the slice ops is not a problem. This is a glue-layer bug for cond expression. https://github.com/D-Programming-Language/dmd/pull/3285 -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 19 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12153



--- Comment #3 from yebblies <yebblies gmail.com> 2014-02-19 21:07:20 EST ---
(In reply to comment #2)
 (In reply to comment #1)
 Sigh, the backend sees
 
 int[1] i = 0;
 int[1] j = 0;
 bool b = true;
 (b ? i : j)[] = [4];
 assert(i == [4]);
 return 0;
 
 Another bug caused by lowering static array ops to slice ops.

Translating to the slice ops is not a problem. This is a glue-layer bug for cond expression.

Sure it is. If instead of converting `a = b` (where lhs is a static array) into `a[] = b[]` the compiler left the lhs intact as a static array, then converting the condexp to an lvalue would have resulted in `*(b ? &i : &j) = [4]` and this bug would not have occurred.
 https://github.com/D-Programming-Language/dmd/pull/3285

-- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 19 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12153



--- Comment #4 from Kenji Hara <k.hara.pg gmail.com> 2014-02-19 02:31:26 PST ---
(In reply to comment #3)
 Sure it is.  If instead of converting `a = b` (where lhs is a static array)
 into `a[] = b[]` the compiler left the lhs intact as a static array, then
 converting the condexp to an lvalue would have resulted in `*(b ? &i : &j) =
 [4]` and this bug would not have occurred.

But in the cond exp, both i and j are already lvalue. So translating lvalue (b ? i : j) to lvalue *(b ? &i : &j) is redundant in front-end layer and will never occur. -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 19 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12153



--- Comment #5 from yebblies <yebblies gmail.com> 2014-02-19 21:38:16 EST ---
(In reply to comment #4)
 (In reply to comment #3)
 Sure it is.  If instead of converting `a = b` (where lhs is a static array)
 into `a[] = b[]` the compiler left the lhs intact as a static array, then
 converting the condexp to an lvalue would have resulted in `*(b ? &i : &j) =
 [4]` and this bug would not have occurred.

But in the cond exp, both i and j are already lvalue. So translating lvalue (b ? i : j) to lvalue *(b ? &i : &j) is redundant in front-end layer and will never occur.

Sure it will. This: int a, b, c; void main() { c ? a : b = c; } results in this getting sent to codegen: *(c ? & a : & b) = c; -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 19 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12153



--- Comment #6 from github-bugzilla puremagic.com 2014-02-23 14:19:12 PST ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/7438d1227a17436077e3df68ba40ef1ff8e0788c
fix Issue 12153 - Ternary operator on static array lvalues creates copy

https://github.com/D-Programming-Language/dmd/commit/ec7cf0a99f791495d142ed8a8799a022c0be84ef
Merge pull request #3285 from 9rnsr/fix12153

Issue 12153 - Ternary operator on static array lvalues creates copy

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 23 2014
prev sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12153


Kenji Hara <k.hara.pg gmail.com> changed:

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


-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 23 2014