Bug 20143 – ICE in optimizer on real 0/0 returned as double

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2019-08-19T13:21:26Z
Last change time
2022-07-09T16:31:51Z
Keywords
backend, ice, pull
Assigned to
No Owner
Creator
Simen Kjaeraas

Comments

Comment #0 by simen.kjaras — 2019-08-19T13:21:26Z
The below code crashes the compiler with "Internal error: dmd/backend/evalu8.c 1028": // typeof(x) is irrelevant, but it must take at least one parameter real fun(real x) { return 0; } double bug() { // value passed to fun is irrelevant return 0 / fun(0); } void main() { } Source discussion: https://forum.dlang.org/thread/[email protected]
Comment #1 by kozzi11 — 2019-08-19T13:59:54Z
needs to be compiled with enabled inlineing (-inline) and it is not important that return type of `bug` function is double it could be int, but if we change fun tu return double it works as expected
Comment #2 by lance — 2019-08-19T14:08:27Z
(In reply to Daniel Kozak from comment #1) > needs to be compiled with enabled inlineing (-inline) and it is not > important that return type of `bug` function is double it could be int, but > if we change fun tu return double it works as expected It actually has to be compiled with the combination -O -inline. Works fine if compiling with either -O or -inline but not both.
Comment #3 by default_357-line — 2019-08-20T14:18:23Z
This is one for Walter. The proximate cause is that in elem.d, the "0" on the left side of 0 / fun(0) is converted from a long double constant to a double constant sight unseen. (elem.d: shrinkLongDoubleConstantIfPossible) This leaves the operation post inlining standing as "double / long double", which is not a valid operation.
Comment #4 by dlang-bot — 2022-06-07T16:52:54Z
@maxhaton updated dlang/dmd pull request #14192 "Fix Issue 20143 - Backend constant folding did not support division b…" fixing this issue: - Fix Issue 20143 - Backend constant folding did not support division by real. This involved simply adding the correct case to the grand olde switch statement that does the evalu8tion https://github.com/dlang/dmd/pull/14192
Comment #5 by dlang-bot — 2022-06-08T00:10:35Z
dlang/dmd pull request #14192 "Fix Issue 20143 - Backend constant folding did not support division b…" was merged into stable: - 7e2ca1ba2f849ad4a1670ff351702a2806dfd89a by mhh: Fix Issue 20143 - Backend constant folding did not support division by real. This involved simply adding the correct case to the grand olde switch statement that does the evalu8tion https://github.com/dlang/dmd/pull/14192
Comment #6 by dlang-bot — 2022-07-09T16:31:51Z
dlang/dmd pull request #14280 "merge stable" was merged into master: - 6d590f4c88d7ada0743e5bdb4223a7d044924322 by mhh: Fix Issue 20143 - Backend constant folding did not support division by real. This involved simply adding the correct case to the grand olde switch statement that does the evalu8tion https://github.com/dlang/dmd/pull/14280