www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 13784] New: Wrong code with modulo operation and


          Issue ID: 13784
           Summary: Wrong code with modulo operation and optimisations
           Product: D
           Version: D1 & D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: public dicebot.lv

assertions passes when compiled with no flags and fails when compiled with -O

long modulo24 (long ticks)
    const TicksPerDay = 864000000000;
    ticks %= TicksPerDay;
    if (ticks < 0)
        ticks += TicksPerDay;
    return ticks;

    assert (modulo24(-141600000000) == 722400000000);

Checking assembly reveals wrong optimisation via replacing modulo with

Issue present in both D1 and D2 compilers. Workaround is to avoid modulo
operation with negative numbers.

Nov 27 2014