SH1 target fails to drop significant bits on storing a shift.

Richard Hodson hodsonr@dionecorp.com
Mon Jun 22 08:10:00 GMT 1998


The following code fragment from egcs release 1.0.2 treats the unsigned char
as if it were an unsigned short, causing the loop to terminate after twice the
correct number of iterations.

Target compiler version is:

[hodsonr@sparehead1 hodsonr]$ xgcc -v
Reading specs from /usr/local/lib/gcc-lib/sh-hitachi-hms/egcs-2.90.27/specs
gcc version egcs-2.90.27 980315 (egcs-1.0.2 release)


Host is a redhat 4.2 i686 box, cross compiling from gcc 2.7.2.1:

[hodsonr@sparehead1 hodsonr]$ gcc -v
Reading specs from /usr/lib/gcc-lib/i386-linux/2.7.2.1/specs
gcc version 2.7.2.1 

---------------

unsigned int
bad_shift()
{
        unsigned char   mask;
        unsigned int    result;

        result = 0;
        for( mask = 0x01; mask != 0; mask <<= 1 )
        {
                result |= mask;
        }

/* Expect to return 0xff, actually returns 0xffff */
        return( result );
}

------------

        .file   "example.c"
        .data
! GNU C version egcs-2.90.27 980315 (egcs-1.0.2 release) (sh-hitachi-hms)
compiled by GNU C version 2.7.2.1.
! options passed:  -O2
! options enabled:  -fdefer-pop -fcse-follow-jumps -fcse-skip-blocks
! -fexpensive-optimizations -fthread-jumps -fstrength-reduce -fpeephole
! -fforce-mem -ffunction-cse -finline -fkeep-static-consts -fcaller-saves
! -freg-struct-return -fdelayed-branch -frerun-cse-after-loop
! -frerun-loop-opt -fschedule-insns2 -fsjlj-exceptions -fcommon
! -fverbose-asm -fgnu-linker -fregmove -falias-check -fargument-alias

gcc2_compiled.:
___gnu_compiled_c:
        .text
        .align 2
        .global _bad_shift
_bad_shift:
        mov.l   r14,@-r15
        mov     #0,r0
        mov     #1,r1
        mov     r15,r14
        .align 2
L5:
        or      r1,r0
        add     r1,r1
        extu.w  r1,r1		;<--- Wrong storage type here.
        tst     r1,r1
        bf      L5
        mov     r14,r15
        rts
        mov.l   @r15+,r14



-- 

Richard Hodson,             | "Adding more people to an already late project
Embedded Software Engineer  | is like trying to put out a fire by dousing it
                            | with gasolene" - Frederick Brooks




More information about the Gcc-bugs mailing list