#4315 Converting float to _Bool causes an internal compiler error
1: Sample code that reproduces the problem.
_Bool f(float x)
{
return (_Bool)x;
}
2: Exact command used to run SDCC on this sample code.
sdcc -o /app/output.s -S -mz80 --std-c99 /app/example.c
3: SDCC version tested.
SDCC trunk 4.6.5 #17328 (Linux), on Compiler Explorer (Z80).
Shin Zukeran reported the same failure on sdcc-user on 4 December 2026 with SVN r17339 on Z80, STM8, HC08, MCS51, MOS6502 and PDK14.
4: Observed and expected behaviour.
SDCC reports error 9 (internal compiler error) at SDCCopt.c:598, followed by Caught signal 11: SIGSEGV.
The code should compile successfully. The conversion should yield 0 if x compares equal to zero and 1 otherwise.
Attaching a candidate bug fix created with Codex. It looks okay to me but needs review by another developer.
The attached candidate patch failed testing:
I'm attaching a replacement candidate patch. This one passes all regression tests:
It also passes valdiag tests on all targets including z80:
Please can another developer review the revised candidate fix? It's a small and self-contained change to produce NE_OP instead of CAST in the
geniCodeCastfunction, in the specific case of conversions between values of floating point and Boolean type.The only substantial difference compared to the previous candidate patch is removal of deduplication of calls to
geniCodeRValue (op, false), but I cannot see how that could have had any effect on cases/tst_gcc-torture-execute-20010118-1.c. Consequently, the previous failure remains unexplained.Last edit: Christopher Bazley 16 hours ago
Looks ok to me.
Thanks for reviewing the fix. Committed as [r17350].
Related
Commit: [r17350]