Bug 16317 – Wrong binop evaluation/load order when optimizing
Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-07-24T11:20:56Z
Last change time
2020-09-06T11:18:37Z
Keywords
backend, industry, pull, wrong-code
Assigned to
No Owner
Creator
kinke
Comments
Comment #0 by kinke — 2016-07-24T11:20:56Z
The runtime assertion fails when specifying `-O`:
-----
int add8ret3(ref int s)
{
s += 8;
return 3;
}
int binAdd(int val)
{
val = val + add8ret3(val);
return val;
}
void main()
{
assert(binAdd(1) == (1 + 3));
static assert(binAdd(1) == (1 + 3));
}
-----
So the left hand side lvalue seems to be loaded after evaluating the right hand side. This can be caused by optimizing `val = val <op> ...` to `val <op>= ...`, which isn't valid for the current evaluation/load order rules.
This came up when fixing a related CTFE issue in https://github.com/dlang/dmd/pull/5966, where I disabled the corresponding tests for now.
(In reply to kinke from comment #0)
> This can be caused by optimizing `val = val <op> ...` to `val <op>= ...`
That is indeed what is happening, in cgelem.d eleq().
Comment #3 by dlang-bot — 2020-09-04T09:42:48Z
@WalterBright created dlang/dmd pull request #11684 "fix Issue 16317 - Wrong binop evaluation/load order when optimizing" fixing this issue:
- fix Issue 16317 - Wrong binop evaluation/load order when optimizing
https://github.com/dlang/dmd/pull/11684
Comment #4 by dlang-bot — 2020-09-06T11:18:37Z
dlang/dmd pull request #11684 "fix Issue 16317 - Wrong binop evaluation/load order when optimizing" was merged into master:
- 9c69ec9731f7473e2302ef687a35b38a53676f39 by Walter Bright:
fix Issue 16317 - Wrong binop evaluation/load order when optimizing
https://github.com/dlang/dmd/pull/11684