Bug 6698 – Regression(2.053): segfault with naked asm in inner function
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2011-09-20T05:04:00Z
Last change time
2011-10-24T13:39:10Z
Keywords
wrong-code
Assigned to
nobody
Creator
clugdbug
Comments
Comment #0 by clugdbug — 2011-09-20T05:04:39Z
This comes from the test suite, fail_compilation/fail135.d
The code actually worked for a very long time (since around DMD1.000), but wasn't compiling because it had a missing import for printf.
// segfault on 0.150
void fail135()
{
int i = 0;
void fn()
{
asm
{
naked;
lea EAX, i;
mov [EAX], 42;
ret;
}
}
fn();
assert(i==42);
}
void main()
{
fail135();
}
Comment #1 by clugdbug — 2011-10-17T23:32:27Z
I'm actually not sure if this should really work, or not. It may simply be code that was relying on undefined behaviour.
Despite nominally being a "regression", it should be given low priority.
Comment #2 by clugdbug — 2011-10-24T02:01:24Z
This is not caused by the compiler. The change seems to have been caused by a change in druntime between 2.052 and 2.053.
This code didn't actually work before. If you change the assert to:
assert(i==49);
(which should fail), it doesn't fail!
This code is actually clobbering the return address.
The test case is bug 701, which hasn't been fixed. The bug is that this test case is in the test suite.