On arm-elf-gcc, I encountered a miscompilation of inline assembly.  The
miscompilation only occurs when compiled with -fweb.  -fno-web makes the sample
compile correctly even with -O3 (and -fnew-ra).

Here is the configuration:
Reading specs from /home/build/gnu/lib/gcc/arm-elf/3.4.3/specs
Configured with: ../gcc-3.4.3/configure --prefix=/home/build/gnu
--target=arm-elf --disable-shared --enable-multilib --enable-interwork
--enable-languages=c --with-headers=../newlib-1.12.0/newlib/libc/include
--with-newlib
Thread model: single
gcc version 3.4.3

The bug occurs on both Cygwin and Linux hosts.

The sample case is attached inline below.

To compile the case, but the sample in test.c and run the following:

$ arm-elf-gcc -O -fweb test.c

Without -fweb:

$ arm-elf-gcc -O test.c

main() function returns zero in case of correct compilation, 2 otherwise.

ciao,
janne

# 1 "test.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "test.c"

typedef signed int HGint32;
typedef signed long long int HGint64;

typedef union
{
    struct
    {
        HGint32 h, l;
    } c;
    HGint64 r;
} HGint64_s;

HGint64 hgMax64 (HGint64 a, HGint64 b)
{
    HGint64_s aa,bb;
    HGint32 tmp;

    aa.r = a;
    bb.r = b;

    asm ("subs  %[tmp],%[al], %[bl]\n\t" "sbcs  %[tmp],%[ah], %[bh]\n\t" "movlt
%[ah], %[bh]\n\t" "movlt %[al], %[bl]\n\t" :



         [tmp] "=r&" (tmp),
         [ah] "+r" (aa.c.h),
         [al] "+r" (aa.c.l) :
         [bh] "r" (bb.c.h),
         [bl] "r" (bb.c.l) :
         "cc");

    return aa.r;
}

int main(void)
{
    HGint64 a = 400;
    HGint64 b = 100;

    if(a != hgMax64(a, b))
        return 2;

    return 0;
}

-- 
           Summary: miscompilation of inline assembler  with -fweb
           Product: gcc
           Version: 3.4.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: janne at hybrid dot fi
                CC: gcc-bugs at gcc dot gnu dot org
GCC target triplet: arm-elf


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18528

Reply via email to