[Issue 2421] New: Struct assignment is broken (nulls target before evaluating source)
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Oct 17 11:22:50 PDT 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2421
Summary: Struct assignment is broken (nulls target before
evaluating source)
Product: DGCC aka GDC
Version: 0.24
Platform: PC
OS/Version: Linux
Status: NEW
Keywords: wrong-code
Severity: normal
Priority: P2
Component: glue layer
AssignedTo: dvdfrdmn at users.sf.net
ReportedBy: fvbommel at wxs.nl
When you assign a struct value to a struct variable, the variable is under some
circumstances nulled before evaluating the value. This leads to miscompilation
if fields of the value depend on those of the variable.
Test case:
-----
module test;
// Some lib-independence
version(Tango) {
import tango.io.Stdout;
void show(Foo f) {
Stdout.formatln("{} : {}", f.p, f.flag);
}
} else {
import std.stdio;
void show(Foo f) {
writefln("%s : %s", f.p, f.flag);
}
}
struct Foo {
void* p;
bool flag;
}
void main() {
// Random non-zero values
auto f = Foo(&show, true);
// Prints correct non-zero values
show(f);
// Set to fresh copy of itself...
f = Foo(f.p, f.flag);
// prints {null} : false
show(f);
}
-----
This seems to be as minimal as I can make it.
Removing either field makes the problem go away, as does replacing the pointer
with an int or float (but replacing the pointer with an object reference or
double doesn't).
$ gdc --version
gdc (GCC) 4.1.3 20070831 (prerelease gdc 0.25, using dmd 1.021) (Ubuntu
0.25-4.1.2-16ubuntu1)
--
More information about the D.gnu
mailing list