Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo


#1856 Code wrongly considered unreachable whn using function pt.

Erik Petrich

I'm compiling the Petit FatFs source (attached) with the following command:

sdcc -mz80 --data-loc 0xC001 --no-std-crt0 --oldralloc --no-peep --code-loc 0x8000 pff.c

My SDCC version is:

mcs51/gbz80/z80/z180/ds390/pic16/pic14/TININative/ds400/hc08 3.0.5 #6899
(Oct 2 2011) (MINGW32)

When building the Petit FatFs code for the Z80 I decided to put some of the low-level disk I/O routines it uses in a separate bank.
So I replaced e.g. this prototype:

DSTATUS disk_initialize(void);

with a define like this:

#define disk_initialize ((DSTATUS (*)(void))0xD689)

(I generate these defines automatically from the map files with a tool)
After doing these changes the compiler incorrectly marks large portions of code as unreachable.

For example, it considers the following return to always be taken:

if (disk_initialize() != 0)
return FR_NOT_READY;

even though that depends on the value returned by disk_initialize.

Attached the code in question.


  • Anonymous

    I should add that I've successfully used the same principle of defined function pointers elsewhere (with the same version of SDCC). I only ran into these problems when using them in PFF.

  • This is not a Z80-specific problem. Compiling using .e.g. --stack-auto -mds400 will give a huge number of unreachable code warnings too.


    • labels: 100692 -->
    • priority: 5 --> 6
    • summary: Z80: Function pointers results in unreachable code --> Code wrongly considered unreachable whn using function pt.
  • Erik Petrich
    Erik Petrich

    Fixed in SDCC 3.0.6 #7010

  • Erik Petrich
    Erik Petrich

    • assigned_to: nobody --> epetrich
    • labels: --> C-Front End
    • milestone: --> fixed
    • status: open --> closed-fixed