Bug 12503 – Bad optimization with scope(success) and return statement

Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-04-01T10:28:00Z
Last change time
2014-08-28T04:10:24Z
Keywords
ice, pull, wrong-code
Assigned to
yebblies
Creator
dlang-bugzilla

Comments

Comment #0 by dlang-bugzilla — 2014-04-01T10:28:04Z
//////////// test.d /////////// void check(string a, string b) { assert(a != b); } void fun(string a) { auto b = a; scope(success) check(a, b); a = null; return; } void main() { fun("foo"); } /////////////////////////////// When compiled with -O, the assert fails. (a still has the same value as b). When compiled with -m64, the compiler ICEs: Internal error: ..\ztc\cgobj.c 1479
Comment #1 by k.hara.pg — 2014-04-09T08:45:10Z
The lowered code generated by front-end will cause same issue. void fun(string a) { string b = a; bool __os1 = false; try { try { a = null; return ; } catch (Throwable __o2) { __os1 = true; throw __o2; } } finally { if (!__os1) assert(a != b); } } void main() { fun("foo"); } It seems to be caused by "copy propagation" in dmd-backed optimizer, done by copyprop() in dmd/src/backend/gopher.c.
Comment #2 by yebblies — 2014-07-29T09:56:20Z
The glue layer sets up the block successors wrong. https://github.com/D-Programming-Language/dmd/pull/3826
Comment #3 by github-bugzilla — 2014-08-15T18:39:26Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/ee659d780bcc2b2d6c29c3930cc122ff481e9465 Fix Issue 12503 - Bad optimization with scope(success) and return statement The current code only lists the finally block as a successor of the return statement when the return directly inside the finally's try block. https://github.com/D-Programming-Language/dmd/commit/426845f8efa66f85300fad45396666faf57b24e1 Merge pull request #3826 from yebblies/issue12503 Issue 12503 - Bad optimization with scope(success) and return statement
Comment #4 by github-bugzilla — 2014-08-28T04:10:24Z
Commit pushed to 2.066 at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/31d0aa4f61ed1ab051c4b48bee235d5d3d0002c0 Merge pull request #3826 from yebblies/issue12503 Issue 12503 - Bad optimization with scope(success) and return statement