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



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



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




 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






 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





 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






 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




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


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