public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/48790] New: ARM GCC divide/modulo bug
@ 2011-04-27 11:59 the.metyl at gmail dot com
  2011-04-27 12:42 ` [Bug c/48790] ARM GCC divide/modulo causes Illegal instruction rguenth at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: the.metyl at gmail dot com @ 2011-04-27 11:59 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: ARM GCC divide/modulo bug
           Product: gcc
           Version: 4.3.3
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: the.metyl@gmail.com


I've found a strange gcc bug in the Sourcery G++ Lite 2009q1-203. Invalid
instruction is generated while executing this code:

    len   = 9;
    width = 8;

    if ((len % width) == 0) 
        printf("fail\n");
    else 
        printf("ok\n");        

Strange is that if the code was in main, sometimes it passed throught without
any problems, but when I've put the code into function it always fails to
compute 9 modulo 8. I don’t see anything wrong in assembly generated by gcc
(maybe there is some stack handling problem in the __aeabi_idivmod function)
Any ideas what's wrong with the toolchain's gcc would really help... 

This is how the assembly looks like (of the testcase function)

testcase:
        .fnstart
.LFB2:
        @ args = 0, pretend = 0, frame = 16
        @ frame_needed = 1, uses_anonymous_args = 0
        stmfd   sp!, {fp, lr}
        .save {fp, lr}
.LCFI0:
        .setfp fp, sp, #4
        add     fp, sp, #4
.LCFI1:
        .pad #16
        sub     sp, sp, #16
.LCFI2:
        str     r0, [fp, #-8]
        str     r1, [fp, #-12]
        ldr     r3, [fp, #-8]
        mov     r0, r3
        ldr     r1, [fp, #-12]
        bl      __aeabi_idivmod
        mov     r3, r1
        cmp     r3, #0
        bne     .L2
        ldr     r0, .L6
        bl      puts
        b       .L5
.L2:
        ldr     r0, .L6+4
        bl      puts
.L5:
        sub     sp, fp, #4
        ldmfd   sp!, {fp, pc}
.L7:
        .align  2
.L6:
        .word   .LC0
        .word   .LC1
.LFE2:
        .fnend


Full Test example for reproducing the bug (Should write 2 ok into screen, but
it generates Illegal Instruction instead: 

#include <stdio.h>

int testcase(int len, int width)
{
    /* This generates Illegal instruction (always) */
    if ((len % width) == 0) 
        printf("fail\n");
    else 
        printf("ok\n");    
}

int main(int argc, char *argv[])
{
    int len, width;

    len   = 9;
    width = 8;

    /* This generates Illegal instruction (sometimes ???) */    
    if ((len % width) == 0) 
        printf("fail\n");
    else 
        printf("ok\n");        


    testcase(len, width);    

    return 0;
}


# arm-none-linux-gnueabi-gcc-4.3.3 --v
Using built-in specs.
Target: arm-none-linux-gnueabi
Configured with:
/scratch/mitchell/builds/4.3-arm-none-linux-gnueabi-respin/src/gcc-4.3/configure
--build=i686-pc-linux-gnu --host=i686-pc-linux-gnu
--target=arm-none-linux-gnueabi --enable-threads --disable-libmudflap
--disable-libssp --disable-libstdcxx-pch --with-gnu-as --with-gnu-ld
--with-specs='%{funwind-tables|fno-unwind-tables|mabi=*|ffreestanding|nostdlib:;:-funwind-tables}'
--enable-languages=c,c++ --enable-shared --enable-symvers=gnu
--enable-__cxa_atexit --with-pkgversion='Sourcery G++ Lite 2009q1-203'
--with-bugurl=https://support.codesourcery.com/GNUToolchain/ --disable-nls
--prefix=/opt/codesourcery
--with-sysroot=/opt/codesourcery/arm-none-linux-gnueabi/libc
--with-build-sysroot=/scratch/mitchell/builds/4.3-arm-none-linux-gnueabi-respin/lite/install/arm-none-linux-gnueabi/libc
--with-gmp=/scratch/mitchell/builds/4.3-arm-none-linux-gnueabi-respin/lite/obj/host-libs-2009q1-203-arm-none-linux-gnueabi-i686-pc-linux-gnu/usr
--with-mpfr=/scratch/mitchell/builds/4.3-arm-none-linux-gnueabi-respin/lite/obj/host-libs-2009q1-203-arm-none-linux-gnueabi-i686-pc-linux-gnu/usr
--disable-libgomp --enable-poison-system-directories
--with-build-time-tools=/scratch/mitchell/builds/4.3-arm-none-linux-gnueabi-respin/lite/install/arm-none-linux-gnueabi/bin
--with-build-time-tools=/scratch/mitchell/builds/4.3-arm-none-linux-gnueabi-respin/lite/install/arm-none-linux-gnueabi/bin
Thread model: posix
gcc version 4.3.3 (Sourcery G++ Lite 2009q1-203)


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c/48790] ARM GCC divide/modulo causes Illegal instruction
  2011-04-27 11:59 [Bug c/48790] New: ARM GCC divide/modulo bug the.metyl at gmail dot com
@ 2011-04-27 12:42 ` rguenth at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-04-27 12:42 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID

--- Comment #1 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-04-27 12:36:48 UTC ---
Please report bugs for custom GCC versions to its vendor, in this case
--with-bugurl=https://support.codesourcery.com/GNUToolchain/


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-04-27 12:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-27 11:59 [Bug c/48790] New: ARM GCC divide/modulo bug the.metyl at gmail dot com
2011-04-27 12:42 ` [Bug c/48790] ARM GCC divide/modulo causes Illegal instruction rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).