When compiling the following code with dmd -c -release -inline -O resource.d I get the message "Error: variable result used before set" without any line information, and compilation fails. This happens only with the flags above. Removing any of them, or compiling in debug results in good output. I have verified that this error happens both in linux and windows, with dmd 2.052 and since many versions ago. <Speculation> Even GDC crashes compiling this code in release, which makes me think it is in the front end. <Data> I have removed everything i could, and now the code doesn't make much sense, but the file resource.d is: module bug; import std.c.string; class InputStream { public: InputStream opShr(T)( out T result ) { memcpy( &result, &m_data[m_pos], T.sizeof ); m_pos += T.sizeof; return this; } int m_pos; const ubyte[] m_data; } struct GUID { uint m_values[4]; }; struct Header { int ver; int siz; GUID id; } void LoadResourceLegacyHeader( InputStream f, out Header header ) { f >> header.id; }
(In reply to comment #0) > I have removed everything i could, Reduced program: struct Foo { int x; int[3] y; } void baz(out int[3] y2) { y2[0]++; } void spam(out Foo f) { baz(f.y); } void main() {}
(In reply to comment #1) > (In reply to comment #0) > > > I have removed everything i could, > > Reduced program: > > > struct Foo { > int x; > int[3] y; > } > void baz(out int[3] y2) { > y2[0]++; > } > void spam(out Foo f) { > baz(f.y); > } > void main() {} Thanks!
Critical, as per Don request.
Also reproducible with '-inline -noboundscheck -O'. Should be a backend issue in gother.c. -------- struct H { double a; int[3] b; // must not be the first member in a struct, and must be an array with 3 or more members } void g(out int[3] t) { // must take 'out' parameter t[0]=0; // can be any mutating expression } void h (H* x) { // or 'out H' or 'ref H' g(x.b); }
Another test case, which is triggered only on Linux and FreeBSD. ----------------------------------- void test5790d() { int x; int y = *(1 + &x); } ----------------------------------- $ dmd -O -c test5790d.d Error: variable x used before set ----------------------------------- See also https://github.com/D-Programming-Language/dmd/pull/243#issuecomment-1706278.
This is possibly related to: http://d.puremagic.com/issues/show_bug.cgi?id=5239
Confirmed that the reduction in comment 2 still reproduces the problem. It reports y2 as used before set (with no line number). The two fixes to this part of the compiler aren't sufficient to catch this one.
Additional test case using only the -O flag and no -inline or -release flags necessary. import std.typecons; void main(string[] args) { // Errors auto i = Tuple!(string,string)("foo", "bar")[1]; // Ok auto j = Tuple!(string,string)("foo", "bar"); auto k = j[1]; }
(In reply to comment #8) > Additional test case using only the -O flag and no -inline or -release flags > necessary. > > import std.typecons; > > void main(string[] args) { > > // Errors > auto i = Tuple!(string,string)("foo", "bar")[1]; > > // Ok > auto j = Tuple!(string,string)("foo", "bar"); > auto k = j[1]; > } This is a dup of 7263. See it.
(In reply to comment #7) > Confirmed that the reduction in comment 2 still reproduces the problem. It > reports y2 as used before set (with no line number). > > The two fixes to this part of the compiler aren't sufficient to catch this one. Walter already committed a fix for this issue. https://github.com/D-Programming-Language/dmd/commit/68b51f24ec25b20df19a5f53b0252d820d2c4d1d https://github.com/D-Programming-Language/dmd/commit/c5d673247289279a54339dfbb6d27733ed3fd63b And comment#2 code can compile with 2.058head.