www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20893] New: [REG 2.087] 32-bit arithmetic goes wrong

https://issues.dlang.org/show_bug.cgi?id=20893

          Issue ID: 20893
           Summary: [REG 2.087] 32-bit arithmetic goes wrong
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Severity: regression
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: gassa mail.ru

Somewhat reduced test case:

-----
module bug_example;

int f (int n) {
        foreach (i; 0..n) {
        }
        return 10;
}

int c (int a, int b) {
        return (f(a) * 1L * f(b)) % 1000;
}

void main () {
        auto a = [2];
        foreach (n; a) {
                int res = c(n - 1, n);
                import std.stdio: writeln;
                writeln(res);
        }
}
-----

Compile with "dmd -O -inline".

With 2.086.0, it produces the correct result (100).
With 2.087.1 and further, the result is wrong (10).
The bug shows with "-m32" and with "-m32mscoff"; no bug seen with "-m64".

The "* 1L *" part is conversion to long for multiplication.
Goes the same with "cast(long) f(a)" instead.
After "% 1000", it is (well, should have been) safe to treat the result as int.

Ivan Kazmenko.

--
Jun 01