5580 – [64-bit] String switch statements broken in 64-bit mode

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 5580 - [64-bit] String switch statements broken in 64-bit mode
Summary: [64-bit] String switch statements broken in 64-bit mode
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: wrong-code
Depends on:
Blocks:
Reported: 2011年02月14日 18:14 UTC by David Simcha
Modified: 2011年02月16日 00:54 UTC (History)
1 user (show)

See Also:


Attachments
Statically linked binary (795.14 KB, application/octet-stream)
2011年02月15日 02:34 UTC, David Simcha
Details
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description David Simcha 2011年02月14日 18:14:05 UTC
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 David Simcha 2011年02月14日 18:28:28 UTC
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 David Simcha 2011年02月15日 02:34:01 UTC
Created attachment 912 [details] 
Statically linked binary
Comment 3 David Simcha 2011年02月15日 02:35:11 UTC
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 David Simcha 2011年02月15日 06:30:28 UTC
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 Walter Bright 2011年02月15日 15:30:18 UTC
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 David Simcha 2011年02月15日 18:10:56 UTC
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.


AltStyle によって変換されたページ (->オリジナル) /