D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 20906 - unnecessary divide-by-zero errors when constant folding short circuits
Summary: unnecessary divide-by-zero errors when constant folding short circuits
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2020-06-08 02:54 UTC by Walter Bright
Modified: 2020-06-16 01:20 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Walter Bright 2020-06-08 02:54:42 UTC
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.
Comment 1 Dlang Bot 2020-06-08 03:23:24 UTC
@WalterBright created dlang/dmd pull request #11252 "fix Issue 20906 - unnecessary divide-by-zero errors when constant fol…" fixing this issue:

- fix Issue 20906 - unnecessary divide-by-zero errors when constant folding short circuits

https://github.com/dlang/dmd/pull/11252
Comment 2 Dlang Bot 2020-06-09 05:17:31 UTC
@WalterBright created dlang/druntime pull request #3130 "workaround Issue 20906 - unnecessary divide-by-zero errors when const…" mentioning this issue:

- workaround Issue 20906 - unnecessary divide-by-zero errors when constant folding short circuits

https://github.com/dlang/druntime/pull/3130
Comment 3 Dlang Bot 2020-06-16 01:20:31 UTC
dlang/dmd pull request #11252 "fix Issue 20906 - unnecessary divide-by-zero errors when constant fol…" was merged into master:

- 25e34d5edab438dfd31185c5f0619d145e335805 by Walter Bright:
  fix Issue 20906 - unnecessary divide-by-zero errors when constant folding short circuits

https://github.com/dlang/dmd/pull/11252