[Issue 5581] [64-bit] Wrong code with bitwise operations on bools
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Feb 15 11:31:47 PST 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5581
--- Comment #1 from David Simcha <dsimcha at yahoo.com> 2011-02-15 11:29:13 PST ---
I think this is actually a long-standing, hard to reproduce, non-deterministic
codegen bug that strikes on 32-bit as well, though due to the non-deterministic
nature of it, under different circumstances. Here's some code that segfaults
on 32 with stock DMD 2.051, only with -O -inline -release enabled. This is
slightly less reduced than the 64 version because anytime I try to reduce it
more, the bug goes away.
import std.stdio;
bool comp(long a, long b) { return a < b; }
size_t medianOf3(T)(T[] data) {
// Removing this print statement changes the result.
stderr.writeln(data[0], '\t', data[$ / 2], '\t', data[$ - 1]);
immutable size_t mid = data.length / 2;
immutable uint result = ((cast(uint) (comp(data[0], data[mid]))) << 2) |
((cast(uint) (comp(data[0], data[$ - 1]))) << 1) |
(cast(uint) (comp(data[mid], data[$ - 1])));
assert(result != 2 && result != 5 && result < 8); // Cases 2, 5 can't
happen.
switch(result) {
case 1: // 001
case 6: // 110
return data.length - 1;
case 3: // 011
case 4: // 100
return 0;
case 0: // 000
case 7: // 111
return mid;
default:
assert(0);
}
assert(0);
}
void main() {
long[] stuff = [4602111750194969114, 4591797823464657051,
4579622497201165564];
medianOf3(stuff);
}
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list