www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20906] New: unnecessary divide-by-zero errors when constant

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

          Issue ID: 20906
           Summary: unnecessary divide-by-zero errors when constant
                    folding short circuits
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: bugzilla digitalmars.com

The following code should not exhibit divide-by-zero errors because short
circuit evaluation should not execute the divides:

int test()
{
    int x = 0;
    int a = x && 1 / x;
    int b = !x || 1 / x;
    int c = x ? 1 / x : 1;
    int d = !x ? 1 : 1 / x;
    return a | b | c;
}

This happens in the backend because the optimizer propagates the 0 value of x.

--
Jun 07