>Submitter-Id:  net
>Originator:    [EMAIL PROTECTED]
>Organization:  The Debian Project
>Confidential:  no
>Synopsis:      
>Severity:      serious
>Priority:      medium
>Category:      optimization
>Class:         wrong-code
>Release:       3.2.1 (Debian) (Debian unstable)
>Environment:
System: Debian GNU/Linux (unstable)
Architecture: i686
[reproducible with gcc-3.2.1 20021111 and HEAD 20021103]

the following simple code produces a segfault when compiled using gcc
3.2 using the folloing command line:

gcc -march=k6-3 -O3 -ffast-math -funroll-loops -fomit-frame-pointer
-fexpensive-optimizations -fstrict-aliasing -pipe -Wall -Werror
-fno-common -o foo foo.c

---8<---

void *array[4];

int
main ()
{
        int i;

        for (i = 0; i < sizeof (array) / sizeof (array[0]); i++)
                array[i] = 0;
        return 0;
}

---8<---

The following is the resulting asm (-S instead of -o foo). Lines
begining with "*" are annotations. Non-useful lines are omitted.

        movl    $array+4, %eax
        movl    $array, %edx
        cmpl    $array+13, %eax
        movl    $array+12, %ecx
        jb      .L10
        .loc 1 9 0
        movl    $0, (%edx)
        .loc 1 8 0
        addl    $4, %edx
        cmpl    %ecx, %edx
        ja      .L9
.L10:
        subl    $array-1, %ecx
        shrl    $4, %ecx

*                   ^^^   set to 0

        .p2align 5,,7
.L28:
        .loc 1 9 0
        movl    $0, (%edx)
        movl    $0, 4(%edx)
        movl    $0, 8(%edx)
        movl    $0, 12(%edx)
        .loc 1 8 0
        addl    $16, %edx
        loop    .L28

*       ^^^ %ecx is 0 for the first pass and thus this loop becomes
*       effectively infinite causing %edx to overflow the array.

.L9:
        .loc 1 10 0
        ret
[snip]
        .string "GNU C 3.2.1 20020924 (Debian prerelease)"

        
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Installed/Config-files/Unpacked/Failed-config/Half-installed
|/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad)
||/ Name           Version        Description
+++-==============-==============-============================================
ii  binutils       2.12.90.0.1-5  The GNU assembler, linker and binary utiliti
ii  libc6          2.2.5-11.2     GNU C Library: Shared libraries and Timezone
host: i386-linux
Configured with: /home/packages/gcc/3.2/gcc-3.2-3.2.1ds5/src/configure -v 
--enable-languages=c,c++,java,f77,proto,objc,ada --prefix=/usr 
--mandir=/usr/share/man --infodir=/usr/share/info 
--with-gxx-include-dir=/usr/include/c++/3.2 --enable-shared --with-system-zlib 
--enable-nls --without-included-gettext --enable-__cxa_atexit 
--enable-clocale=gnu --enable-java-gc=boehm --enable-objc-gc i386-linux
>Description:
[ Reported to the Debian BTS as report #162919.
  Please CC [EMAIL PROTECTED] on replies.
  Log of report can be found at http://bugs.debian.org/162919 ]
        
>How-To-Repeat:
        
>Fix:
        


Reply via email to