Package: gcc
Version: 4:4.1.1-15

GCC miscompiles the following code :-

extern void extfunc(void);
extern unsigned extvar;

static void inner(char *a, unsigned b)
{
        if (b)
                extfunc();
        else
                extvar = (unsigned) a;
}

void outer(unsigned a, unsigned b)
{
        char c;

        c = a;

        inner(&c, b);
}

/*
 * with Debian Etch gcc
 *
 * gcc -O2 -c -o test.o test.c
 *
 * objdump -d test.o
 *
 * the initialisation of "c" that is needed
 * for the assignment to "extvar" is done
 * in the wrong leg of the if() !!
 *

test.o:     file format elf32-littlearm

Disassembly of section .text:

00000000 <outer>:
   0:   e52de004        str     lr, [sp, #-4]!
   4:   e3510000        cmp     r1, #0  ; 0x0
   8:   e24dd004        sub     sp, sp, #4      ; 0x4
   c:   059f301c        ldreq   r3, [pc, #28]   ; 30 <.text+0x30>
  10:   028d2003        addeq   r2, sp, #3      ; 0x3
  14:   05832000        streq   r2, [r3]
  18:   1a000001        bne     24 <outer+0x24>
  1c:   e28dd004        add     sp, sp, #4      ; 0x4
  20:   e8bd8000        ldmia   sp!, {pc}
  24:   e5cd0003        strb    r0, [sp, #3]
  28:   ebfffffe        bl      0 <extfunc>
  2c:   eafffffa        b       1c <outer+0x1c>
  30:   00000000        andeq   r0, r0, r0

*/

/*

Using built-in specs.
Target: arm-linux-gnu
Configured with: ../src/configure -v --enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu --enable-libstdcxx-debug --enable-mpfr --enable-checking=release arm-linux-gnu
Thread model: posix
gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)

*/

/*
 * same but with Debian Etch gcc-3.4
 *
 * this one is correct
 *

test.o:     file format elf32-littlearm

Disassembly of section .text:

00000000 <outer>:
   0:   e52de004        str     lr, [sp, #-4]!
   4:   e3510000        cmp     r1, #0  ; 0x0
   8:   059f3020        ldreq   r3, [pc, #32]   ; 30 <.text+0x30>
   c:   e24dd004        sub     sp, sp, #4      ; 0x4
  10:   e28d2004        add     r2, sp, #4      ; 0x4
  14:   e5620001        strb    r0, [r2, #-1]!
  18:   05832000        streq   r2, [r3]
  1c:   1a000001        bne     28 <outer+0x28>
  20:   e28dd004        add     sp, sp, #4      ; 0x4
  24:   e8bd8000        ldmia   sp!, {pc}
  28:   ebfffffe        bl      0 <extfunc>
  2c:   eafffffb        b       20 <outer+0x20>
  30:   00000000        andeq   r0, r0, r0

*/




--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to