[Issue 20906] New: unnecessary divide-by-zero errors when constant folding short circuits

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jun 8 02:54:42 UTC 2020


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 at puremagic.com
          Reporter: bugzilla at 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.

--


More information about the Digitalmars-d-bugs mailing list