Created attachment 820
PATCH: fix return of uninitialised var in interpret.c
As summary:
triggered by test/runnable/interpret.d, line 2034
Comment #1 by braddr — 2010-11-18T21:15:05Z
With this patch applied on my system, I still fail to pass runnable/interpret.d with -O, but now a few lines later at 2110:
2106 int goodfoo3()
2107 {
2108 S[4] w = void; // uninitialized array of structs
2109 w[$-2].x = 217; // initialize one member
2110 return w[2].x;
2111 }
2112 static assert(goodfoo3()==217);
Simon, did you find this due to a failure with no changes to interpret.d or with -O added to the set of compilation flags to test?
Comment #2 by braddr — 2010-11-18T21:24:56Z
changing 2109 below to just w[2] rather than w[$-2] (same array index) makes that problem go away. And with that change, the entire test passes, which is great. Just leaves one bug to find. :)
Oh, and the error is:
runnable/interpret.d(2110): Error: variable w used before set
Comment #3 by braddr — 2010-11-18T22:15:48Z
Created attachment 821
changes to runnable/interpret.d
The problem is with the optimizer, not ctfe. Switching to this form, so that there's no code for the optimizer to chew on and complain about works:
static assert(is(typeof(Compileable!(
(){
S[4] w = void; // uninitialized array of structs
w[$-2].x = 217; // initialize one member
return w[2].x;
}()).OK
)));
I'll file a separate bug report for that.
Adding a patch for runnable/interpret.d to be applied in addition to simon's changes.
Comment #4 by s.d.hammett — 2010-11-19T06:21:24Z
(In reply to comment #1)
> With this patch applied on my system, I still fail to pass runnable/interpret.d
> with -O, but now a few lines later at 2110:
>
> 2106 int goodfoo3()
> 2107 {
> 2108 S[4] w = void; // uninitialized array of structs
> 2109 w[$-2].x = 217; // initialize one member
> 2110 return w[2].x;
> 2111 }
> 2112 static assert(goodfoo3()==217);
>
> Simon, did you find this due to a failure with no changes to interpret.d or
> with -O added to the set of compilation flags to test?
Neither.
I've build DMD with Visual studio; the vc compiler does a pretty good
job of detected these sorts of bugs in debug builds.
I'll run the rest of the tests when I get home, see if there are any
other gotchas lurking.