Comment #0 by dlang-bugzilla — 2014-02-13T11:39:54Z
void main()
{
int[1] i, j;
bool b = true;
(b ? i : j) = [4];
assert(i == [4]);
}
Comment #1 by yebblies — 2014-02-15T07:21:21Z
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.
Comment #2 by k.hara.pg — 2014-02-19T01:47:31Z
(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
Comment #3 by yebblies — 2014-02-19T02:07:20Z
(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
Comment #4 by k.hara.pg — 2014-02-19T02:31:26Z
(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.
Comment #5 by yebblies — 2014-02-19T02:38:16Z
(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;
Comment #6 by github-bugzilla — 2014-02-23T14:19:12Z