Bug 13237 – Wrong code with "-inline -O"

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-08-01T14:29:00Z
Last change time
2014-08-22T08:05:18Z
Keywords
wrong-code
Assigned to
nobody
Creator
sinkuupump

Comments

Comment #0 by sinkuupump — 2014-08-01T14:29:21Z
introduced by https://github.com/D-Programming-Language/dmd/pull/3819 size_t getLength(int[] arr) { return arr.length; } void main() { int[] arr = [0]; immutable size_t len = getLength(arr); arr.length--; assert(len == 1); // ok if (len) { auto l = len; } assert(len == 1); // len cannot be changed, but produces Assertion failure with "-O -inline" }
Comment #1 by sinkuupump — 2014-08-05T23:39:27Z
Sorry, I forgot to write that this code is reduced from an overload of std.algorithm.find. https://github.com/D-Programming-Language/phobos/blob/master/std/algorithm.d#L4586 The first problem I found was enforce(find("{", "{") == "{"); this fails when it's compiled with -O and -inline.
Comment #2 by bugzilla — 2014-08-06T07:26:16Z
Comment #3 by sinkuupump — 2014-08-06T08:06:28Z
*** Issue 13251 has been marked as a duplicate of this issue. ***
Comment #4 by bugzilla — 2014-08-06T08:33:30Z
sinkuu, I am particularly grateful you posted this bug report, and you even figured out which change caused it. I hate subtle optimizer bugs, and am really glad to get this one fixed before shipping. Thanks!
Comment #5 by github-bugzilla — 2014-08-06T13:47:10Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/02ca8d7c4532cd69ce8a0dfcddf7b394cb196891 fix Issue 13237 Wrong code with -inline -O https://github.com/D-Programming-Language/dmd/commit/0131c148f32f662bd64725b8af58472066fc5781 Merge pull request #3848 from WalterBright/fix13237 fix Issue 13237 Wrong code with -inline -O
Comment #6 by github-bugzilla — 2014-08-07T00:24:00Z
Commit pushed to dmd-1.x at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/955a6d4b89911c6e4cac4594a55158237968208c fix Issue 13237 Wrong code with -inline -O Conflicts: test/runnable/test23.d
Comment #7 by github-bugzilla — 2014-08-08T02:59:22Z
Commit pushed to 2.066 at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/8631eb8f9748d147f5353dc5585632ff3aa6dabc Merge pull request #3848 from WalterBright/fix13237 fix Issue 13237 Wrong code with -inline -O
Comment #8 by github-bugzilla — 2014-08-22T08:05:18Z