Bug 23631 - construct to memory and memcpy instead of memset
Summary: construct to memory and memcpy instead of memset
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.0.2
: P2 normal
Target Milestone: 4.1.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-08-30 10:11 UTC by etienne_lorrain
Modified: 2006-01-23 16:16 UTC (History)
2 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description etienne_lorrain 2005-08-30 10:11:41 UTC
A global .rodata constant is created in the following case
 and then memcpy() to the variable in the stack, instead
 of just calling the intended memset.

etienne@cygne:~/projet/gujin$ cat > tmp.c
int
sub (int i)
{
  int array[1000000] = { 0 };

  sub2 (&array[i]);
}

etienne@cygne:~/projet/gujin$ ~/projet/toolchain/bin/gcc -S -Os tmp.c -o tmp.s
etienne@cygne:~/projet/gujin$ cat tmp.s
        .file   "tmp.c"
        .section        .rodata
        .align 32
        .type   C.0.1134, @object
        .size   C.0.1134, 4000000
C.0.1134:
        .zero   4000000
        .text
.globl sub
        .type   sub, @function
sub:
        pushl   %ebp
        movl    %esp, %ebp
        pushl   %ebx
        subl    $4000000, %esp
        pushl   $4000000
        pushl   $C.0.1134
        leal    -4000004(%ebp), %ebx
        pushl   %ebx
        call    memcpy
        movl    8(%ebp), %eax
        leal    (%ebx,%eax,4), %eax
        pushl   %eax
        call    sub2
        addl    $16, %esp
        movl    -4(%ebp), %ebx
        leave
        ret
        .size   sub, .-sub
        .ident  "GCC: (GNU) 4.0.2 20050811 (prerelease)"
        .section        .note.GNU-stack,"",@progbits
etienne@cygne:~/projet/gujin$ ~/projet/toolchain/bin/gcc -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../configure --prefix=/home/etienne/projet/toolchain --enable-
l
anguages=c
Thread model: posix
gcc version 4.0.2 20050811 (prerelease)

  See also the thread at:
http://gcc.gnu.org/ml/gcc/2005-08/msg00660.html
  Thanks to Jim Wilson (GNU Tools Support, http://www.specifix.com) for the
 reduced test case and the analysis of the bug in gcc@gcc.gnu.org list.

  Etienne.
Comment 1 Andrew Pinski 2005-08-30 10:39:15 UTC
The issue is the same as PR 23477.

*** This bug has been marked as a duplicate of 23477 ***
Comment 2 etienne_lorrain 2006-01-16 10:36:54 UTC
  Same bug still present in gcc version 4.0.3 20051201 (prerelease) (Debian 4.0.2-5).
 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23477 is itself corrected, but this current bug has never been corrected.
Comment 3 Andrew Pinski 2006-01-20 20:51:11 UTC
PR 23477  was fixed in 4.1.0 and not 4.0.3.  This is still a dup of that bug.

*** This bug has been marked as a duplicate of 23477 ***
Comment 4 etienne_lorrain 2006-01-23 09:56:00 UTC
(In reply to comment #3)
> PR 23477  was fixed in 4.1.0 and not 4.0.3.  This is still a dup of that bug.
> *** This bug has been marked as a duplicate of 23477 ***

  For me, 23477 is fixed in "GCC: (GNU) 4.0.3 20051201 (prerelease) (Debian 4.0.2-5)" (this bug is in C++ so compile with g++); but the current bug 23631
is still present (use pure C).

  Etienne.
Comment 5 Andrew Pinski 2006-01-23 16:16:01 UTC
Fixed in 4.1.0.