Menu ▾ ▴

#4315 Converting float to _Bool causes an internal compiler error

closed-fixed
None
Z80
5
11 hours ago
1 day ago
No

1: Sample code that reproduces the problem.

   _Bool f(float x)
   {
       return (_Bool)x;
   }

Compiler Explorer reproducer

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.

Related

Wiki: SDCC 4.7.0 Release

Discussion

  • Christopher Bazley

    Attaching a candidate bug fix created with Codex. It looks okay to me but needs review by another developer.

     
    • Christopher Bazley

      Christopher Bazley - 17 hours ago

      The attached candidate patch failed testing:

      Summary for 'ucz80'                  :      1 failures, 37673 tests, 6582 test cases,  7541803 bytes, 1543008380 ticks
         Failure: cases/tst_gcc-torture-execute-20010118-1.c
      
       
      • Christopher Bazley

        Christopher Bazley - 16 hours ago

        I'm attaching a replacement candidate patch. This one passes all regression tests:

        Summary for 'ucz80'                  :      0 failures, 37683 tests, 6585 test cases,  7542963 bytes, 1543068513 ticks
        

        It also passes valdiag tests on all targets including z80:

        Summary for 'z80'                    :      0 failures,  1958 tests, 1484 test cases,        0 bytes,          0 ticks
        

        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 geniCodeCast function, 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
        • Philipp Klaus Krause

          Looks ok to me.

           
          • Christopher Bazley

            Christopher Bazley - 11 hours ago

            Thanks for reviewing the fix. Committed as [r17350].

             

            Related

            Commit: [r17350]

  • Christopher Bazley

    Christopher Bazley - 11 hours ago
    • status: open --> closed-fixed
    • assigned_to: Christopher Bazley
     

Log in to post a comment.