The following code hits the assert(0) when -release is disabled or segfaults when -release is enabled when compiled on Linux in 64-bit mode:
void main(string[] args) {
auto str = "foo";
switch(str) {
case "foo":
break;
default:
assert(0);
}
}
Comment #1 by dsimcha — 2011-02-14T18:28:28Z
This one actually looks to be related to some dynamic library or system call or something. I just noticed that, regardless of what computer I compile it on, I can only reproduce it on certain computers, those with ancient Linux distributions. The uname -a for the two that I can reproduce it on are:
Linux io11.cis.jhu.edu 2.6.9-89.33.1.ELsmp #1 SMP Thu Dec 2 10:54:14 EST 2010 x86_64 x86_64 x86_64 GNU/Linux
Linux io19.cis.jhu.edu 2.6.9-78.0.13.plus.c4largesmp #1 SMP Tue Jan 20 22:49:51 EST 2009 x86_64 x86_64 x86_64 GNU/Linux
Comment #2 by dsimcha — 2011-02-15T02:34:01Z
Created attachment 912
Statically linked binary
Comment #3 by dsimcha — 2011-02-15T02:35:11Z
Not sure if this will help, but here's a statically linked binary with debugging symbols. This can reproduce the bug on any computer.
Comment #4 by dsimcha — 2011-02-15T06:30:28Z
My gut feeling is that this is related to Bug 5581, as both invoke calls to memcmp() according to my reading of the disassembly and tracking down of the function calls in the runtime. However, 5581 seems to be reproducible everywhere. If you can't reproduce this, I suggest fixing 5581 first. Once 5581 is fixed, I'll retest this bug on a machine that I was able to reproduce it on and hopefully it will be fixed, too.
Comment #5 by bugzilla — 2011-02-15T15:30:18Z
I can't reproduce a problem on Ubuntu, and I examined the assembler generated for druntime/src/rt/switch_.d and nothing obviously wrong jumped out at me.
One thing you can try on the failing machines is to copy switch_.d into a local directory, compile it with the test case, and verify the failure. Then add some print statements to switch_.d to try and see where it goes wrong.
Comment #6 by dsimcha — 2011-02-15T18:10:56Z
Unfortunately this appears to be a Heisenbug. When I put print statements in
to figure out what's going on and call the switch statement function manually,
it starts working. However, the one hint I did get from mucking around in
switch_.d is that replacing the memcmp() call with a manual for loop and
recompiling druntime solves the problem. Not sure if this is due to the
Heisenbug nature of this thing or if it indicates that the memcmp() call is the
culprit.