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.