Bug 5238 – PATCH: fix return of uninitialised var in interpret.c

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
All
Creation time
2010-11-18T16:17:00Z
Last change time
2010-12-08T17:35:55Z
Assigned to
nobody
Creator
s.d.hammett

Attachments

IDFilenameSummaryContent-TypeSize
820interpret.c.diffPATCH: fix return of uninitialised var in interpret.ctext/plain426
821bug5238-test.diffchanges to runnable/interpret.dtext/plain599

Comments

Comment #0 by s.d.hammett — 2010-11-18T16:17:58Z
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.
Comment #5 by bugzilla — 2010-12-07T15:20:17Z
Comment #6 by bugzilla — 2010-12-08T17:35:55Z
Marking this as fixed since it passes the test suite, including the revised interpret.d