[Issue 20162] New: Bug in optimization of remainder operation
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Aug 24 14:53:24 UTC 2019
https://issues.dlang.org/show_bug.cgi?id=20162
Issue ID: 20162
Summary: Bug in optimization of remainder operation
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: major
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: hos at hos.ac
The following code produces weird results:
----
import std.stdio;
long f(long a) {
return a % 1000000;
}
void main() {
foreach (i; 0 .. 2) {
writeln(typeid((i != 0) ? -1 : +1));
writeln(i, " ", ((i != 0) ? -1 : +1), " ", f((i != 0) ? -1 : +1));
}
foreach (i; 0 .. 2) {
foreach (j; 0 .. 2) {
writeln(typeid((i != 0) ? -1 : +1));
writeln(i, " ", j, " ", ((i != 0) ? -1 : +1), " ", f((i != 0) ? -1 :
+1));
}
}
}
----
(https://ideone.com/kyPT72)
Its outputs are:
int
0 1 1
int
1 -1 -1
int
0 0 1 1
int
0 1 1 1
int
1 0 -1 967295
int
1 1 -1 967295
printing (2^32 - 1) mod 1000000 instead of -1, only for the nested for-loop.
This happens only with -m64 and -O options.
--
More information about the Digitalmars-d-bugs
mailing list