[hatari-devel] Compiling Hatari with Clang (from LLVM project) and the resulting signed comparison warnings

Eero Tamminen eerot at users.berlios.de
Sun May 22 11:15:00 CEST 2011


Hi,

As there was recently an article series on effects of having undefined
behavior in C program:
	http://blog.llvm.org/

For fun I compiled Hatari with Clang:
	http://clang.llvm.org/

Only thing you need to do is:
	CC=clang ../configure

(I first tried using -O4 which enables link time optimization too,
but that apparently needs the new Gold linker.)


There was a large amount of unsigned vs. signed comparison warnings:

/home/eero/work/hatari/src/floppy.c:607:13: warning: comparison of integers 
of different signs: 'short' and 'Uint16' (aka 'unsigned short') [-Wsign-
compare]
                if (Count > nSectorsPerTrack)
                    ~~~~~ ^ ~~~~~~~~~~~~~~~~
/home/eero/work/hatari/src/floppy.c:686:13: warning: comparison of integers 
of different signs: 'short' and 'Uint16' (aka 'unsigned short') [-Wsign-
compare]         
                if (Count > nSectorsPerTrack)
                    ~~~~~ ^ ~~~~~~~~~~~~~~~~

-> As Count given to Floppy_ReadSectors() & Floppy_WriteSectors() is
   always 1, either the count could be removed and function renamed
   *Sectors -> *Sector, or it could be changed to Uint16.

Which one I should do?



/home/eero/work/hatari/src/fdc.c:1615:24: warning: comparison of integers of 
different signs: 'short' and 'unsigned short' [-Wsign-compare]
                if (nReadWriteSector > nReadWriteSectorsPerTrack)   /* 
Advance into next track? */
                    ~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~
/home/eero/work/hatari/src/fdc.c:1654:24: warning: comparison of integers of 
different signs: 'short' and 'unsigned short' [-Wsign-compare]                          
                if (nReadWriteSector > nReadWriteSectorsPerTrack)   /* 
Advance to next track? */
                    ~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~

/home/eero/work/hatari/src/msa.c:132:21: warning: comparison of integers of 
different signs: 'short' and 'Uint16' (aka 'unsigned short') [-Wsign-
compare]
        if (pMSAHeader->ID == SDL_SwapBE16(0x0E0F))
            ~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~~~~~~~



/home/eero/work/hatari/src/falcon/dsp_cpu.c:1529:19: warning: comparison of 
integers of different signs: 'Sint16' (aka 'short') and 'Uint16' (aka 
'unsigned short')
      [-Wsign-compare]
        if (orig_modifier>modulo) {
            ~~~~~~~~~~~~~^~~~~~~
/home/eero/work/hatari/src/falcon/dsp_cpu.c:1530:18: warning: comparison of 
integers of different signs: 'Sint16' (aka 'short') and 'Uint16' (aka 
'unsigned short')  
      [-Wsign-compare]
                while (modifier>bufsize) {
                       ~~~~~~~~^~~~~~~~
/home/eero/work/hatari/src/falcon/dsp_cpu.c:1542:19: warning: comparison of 
integers of different signs: 'Sint16' (aka 'short') and 'Uint16' (aka 
'unsigned short')  
      [-Wsign-compare]
        if (orig_modifier!=modulo) {
            ~~~~~~~~~~~~~^ ~~~~~~
/home/eero/work/hatari/src/falcon/dsp_cpu.c:1543:12: warning: comparison of 
integers of different signs: 'Sint16' (aka 'short') and 'Uint16' (aka 
'unsigned short')  
      [-Wsign-compare]
                if (r_reg>hibound) {
                    ~~~~~^~~~~~~~
/home/eero/work/hatari/src/falcon/dsp_cpu.c:1545:19: warning: comparison of 
integers of different signs: 'Sint16' (aka 'short') and 'Uint16' (aka 
'unsigned short')  
      [-Wsign-compare]
                } else if (r_reg<lobound) {
                           ~~~~~^~~~~~~~


(And a huge amount of unused variables & argument warnings from
uae-cpu/cpuemu.c.)


	- Eero



More information about the hatari-devel mailing list