Bug 22587 – ternary with function call and assert(0) leads to cod1 assertion
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2021-12-12T03:54:53Z
Last change time
2022-12-15T22:49:57Z
Keywords
backend, pull
Assigned to
No Owner
Creator
mhh
Comments
Comment #0 by maxhaton — 2021-12-12T03:54:53Z
---
int front()
{
return empty ? 1 : assert(0);
}
bool empty()
{
return 0;
}
---
Yields: Assertion `retregs || !*pretregs' failed
Seems to crash LDC as well so maybe it's invalid code, that being said GDC seems to do just fine.
Comment #1 by maxhaton — 2021-12-17T17:43:11Z
---
int front(int param)
{
return param ? 1 : assert(0);
}
---
also triggers it
Comment #2 by maxhaton — 2022-01-09T02:58:36Z
More detail, seems to require -O to go boom
Comment #3 by hinoda2002 — 2022-01-14T12:38:25Z
*** Issue 22675 has been marked as a duplicate of this issue. ***
Comment #4 by kdevel — 2022-08-04T10:11:27Z
(In reply to mhh from comment #2)
> More detail, seems to require -O to go boom
z1.d
----
void foo (int i)
{
int j = i == 1
? 7
: assert (0);
}
$ dmd z1
Illegal instruction
$ dmd --version
DMD64 D Compiler v2.100.0
Copyright (C) 1999-2022 by The D Language Foundation, All Rights Reserved written by Walter Bright
Comment #5 by dlang-bot — 2022-12-15T06:25:28Z
@maxhaton created dlang/dmd pull request #14698 "Fix Issue 23549, 22587 - Lower certain noreturn expressions to a comm…" fixing this issue:
- Fix Issue 23549, 22587 - Lower certain noreturn expressions to a comma expression rather than a cast.
This avoids a backend segfault.
GDC already does this lowering so it may have to be made optional via a frontend parameter.
https://github.com/dlang/dmd/pull/14698
Comment #6 by dlang-bot — 2022-12-15T13:46:02Z
dlang/dmd pull request #14698 "Fix Issue 23549, 22587 - Lower certain noreturn expressions to a comm…" was merged into stable:
- 5dd1f2942482d730418af8d7d3c5f754122116b8 by mhh:
Fix Issue 23549, 22587 - Lower certain noreturn expressions to a comma expression rather than a cast.
This avoids a backend segfault.
GDC already does this lowering so it may have to be made optional via a frontend parameter.
https://github.com/dlang/dmd/pull/14698
Comment #7 by dlang-bot — 2022-12-15T22:49:57Z
dlang/dmd pull request #14701 "merge stable" was merged into master:
- d836c8bcec16205644e3aacf15f1a1cf7d655dd5 by mhh:
Fix Issue 23549, 22587 - Lower certain noreturn expressions to a comma expression rather than a cast.
This avoids a backend segfault.
GDC already does this lowering so it may have to be made optional via a frontend parameter.
https://github.com/dlang/dmd/pull/14701