Bug 20906 – unnecessary divide-by-zero errors when constant folding short circuits

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-06-08T02:54:42Z
Last change time
2020-06-16T01:20:31Z
Keywords
pull
Assigned to
No Owner
Creator
Walter Bright

Comments

Comment #0 by bugzilla — 2020-06-08T02:54:42Z
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 by dlang-bot — 2020-06-08T03:23:24Z
@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 by dlang-bot — 2020-06-09T05:17:31Z
@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 by dlang-bot — 2020-06-16T01:20:31Z
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