On Thursday, 24 January 2013 at 00:01:26 UTC, Walter Bright wrote:
On 1/23/2013 2:15 PM, Stephan wrote:
What would be the prototypic short program that simulates referencing an out of scope stack frame? It would be great to see an example that produces a
deterministic segfault.


Just return a pointer to a local (first passing it through another function in order to hide what you're doing from the compiler).

btw, bug 8832 is an example of one.

OK, I spent quite a while to narrow it down, and I definitely can say that there is a compiler bug related to the optimization switch.
I filed an issue: (9387).

I could not anymore reproduce a seg-fault, but even worse: The optimization switch changes the behavior of the program!, I declared it as "major", since it is not clear whether this bug is even detectable if it doesn't cause a seg-fault. It just changes the behavior, so it seems to me very dangerous!

The program I attached in the bug-report is an implementation of a minimization routine from Numerical Recipes, 3rd edition. This bug is possibly caused by having a large number of local variables, which are somehow written out into memory before moved into registers or something. I looked at the assembly with a colleague but we couldn't find something conclusive.

I hope that you guys can reproduce the bug (simply run "rdmd -O brent_test.d" and compare it with "rdmd brent_test.d") on dmd 2.061. There is nothing exotic in the source-code, only assignments. No pointers, no references, no structs. It must be a compiler bug.

Stephan

Reply via email to