D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6698 - Regression(2.053): segfault with naked asm in inner function
Summary: Regression(2.053): segfault with naked asm in inner function
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Windows
: P2 regression
Assignee: No Owner
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2011-09-20 05:04 UTC by Don
Modified: 2011-10-24 13:39 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Don 2011-09-20 05:04:39 UTC
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 Don 2011-10-17 23:32:27 UTC
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 Don 2011-10-24 02:01:24 UTC
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.