Bug 14829 – [REG2.066.0] wrong code with -O -inline

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-07-26T11:19:00Z
Last change time
2017-07-22T12:36:15Z
Keywords
wrong-code
Assigned to
nobody
Creator
ag0aep6g

Comments

Comment #0 by ag0aep6g — 2015-07-26T11:19:47Z
Reduced from issue 14827. ---- int[] save(int[] a) {return a;} bool isWhite(int c) {return c != 1;} int decodeImpl(int[] str) { if (true) return 1; } int[] stripLeft(int[] str) { while (true) { int[] s = str.save; int dc = decodeImpl(str); str = str[1 .. $]; bool w = isWhite(dc); assert(!w); /* passes */ if (!w) return s; } } void main () { assert ([2].stripLeft == [2]); /* fails with -O -inline */ } ----
Comment #1 by code — 2015-07-26T18:12:30Z
Oh, this might be difficult to fix. The compiler leaves out the int[] s = str.save; code and uses the same variable for s and str.
Comment #2 by k.hara.pg — 2015-07-27T04:28:34Z
It's a regression from 2.066.0. Introduced in: https://github.com/D-Programming-Language/dmd/pull/3819
Comment #3 by bugzilla — 2015-07-27T07:03:42Z
Thanks, guys, for reducing it and for finding which PR caused it. Looks like the ball is in my court.
Comment #4 by bugzilla — 2015-07-27T07:35:04Z
Somewhat smaller test case that only requires -O to fail: int decodeImpl(int[] str) { return 1; } int[] stripLeft(int[] str) { while (true) { int[] a = str; int[] s = a; int dc = decodeImpl(str); str = str[1 .. $]; bool w = dc != 1; if (!w) return s; } } void main () { int[1] a = 2; assert (stripLeft(a)[0] == 2); // fails with -O }
Comment #5 by bugzilla — 2015-07-27T19:46:20Z
Even smaller: int stripLeft(int str, int dc) { while (true) { int a = str; int s = a; str += 1; if (dc) return s; } } void main () { assert (stripLeft(3, 1) == 3); // fails with -O }
Comment #6 by bugzilla — 2015-07-27T22:06:21Z
Comment #7 by github-bugzilla — 2015-07-28T00:06:05Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/bc2ae82f62fa1df91040c874542e8e6b9746178b fix Issue 14829 - [REG2.066.0] wrong code with -O -inline https://github.com/D-Programming-Language/dmd/commit/88bb355e8245c8fa6c1017a116cc8ea36c601a41 Merge pull request #4841 from WalterBright/fix14829 fix Issue 14829 - [REG2.066.0] wrong code with -O -inline
Comment #8 by bugzilla — 2015-07-28T02:47:47Z
*** Issue 14827 has been marked as a duplicate of this issue. ***
Comment #9 by github-bugzilla — 2015-07-28T10:10:36Z
Commits pushed to stable at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/758561893df09001cc8a1d9b0352633087fb3793 fix Issue 14829 - [REG2.066.0] wrong code with -O -inline https://github.com/D-Programming-Language/dmd/commit/1dae1145eb63709586c65902f5bdd44b01c42479 Merge pull request #4842 from 9rnsr/fix14829 Cherry-pick issue 14829 fix from master branch
Comment #10 by github-bugzilla — 2015-07-30T12:05:50Z
Comment #11 by github-bugzilla — 2015-07-30T20:29:07Z
Commit pushed to dmd-1.x at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/52dc462188c66960d88cb8afd5c0f3a746adc8a8 Merge pull request #4841 from WalterBright/fix14829 fix Issue 14829 - [REG2.066.0] wrong code with -O -inline
Comment #12 by github-bugzilla — 2017-07-22T12:36:15Z