D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4036 - Segfault with -inline and literal of struct containing union
Summary: Segfault with -inline and literal of struct containing union
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Linux
: P2 normal
Assignee: No Owner
URL:
Keywords: ice-on-valid-code, patch
Depends on:
Blocks:
 
Reported: 2010-04-01 05:34 UTC by Matti Niemenmaa
Modified: 2014-02-15 02:19 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 Matti Niemenmaa 2010-04-01 05:34:25 UTC
struct XY { union { int x, y; } }
struct AHolder {
	XY aa;
	void a(XY x) { aa = x; }
}
struct AB {
	AHolder aHolder;
	XY b;
	void a(XY x) { aHolder.a(x); }
}
struct Main {
	AB ab;

	void setB() { ab.b = XY(); }
	void f() {
		ab.a(XY.init);
		setB();
	}
}

$ dmd -c -inline arst.d
Segmentation fault

Any of the following semantics-preserving changes will fix it:

- Making Main.setB use XY.init instead of XY()
- Inlining ab.a(XY.init) into Main.f
- Inlining setB() into Main.f
- Inlining aHolder.a(x) into AB.a
Comment 1 Don 2010-04-08 23:55:12 UTC
PATCH: Uninitialized variable causing memory corruption.

bug 4036. inline.c, arrayExpressiondoInline(), line 460.
---------
            if (e)
            {
                e = e->doInline(ids);
                newa->data[i] = (void *)e;
            }
+            else
+                newa->data[i] = 0;
Comment 2 Don 2010-05-05 19:08:32 UTC
Fixed DMD2.044