When compiling the testcase (strcpy()) with -Os -march=pentium4, GCC generates a 
word-fetch 
instead of a byte-fetch.  This can provoke memory faults (e.g. at the end of a page).

Omitting "-march=pentium4" generates correct code.

Here is the testcase:
------------------------------------------------
char *
mystrcpy(char * __restrict to, const char * __restrict from)
{
  char *save = to;
  
  for (; (*to = *from); ++from, ++to);
  return(save);
}
----------------------------------------------------
And the invocation:  % gcc.fsf.pure.obj/gcc/xgcc -B gcc.fsf.pure.obj/gcc -Os -S 
mystrcpy.c 
-march=pentium4
----------------------------------------------------
And the result (error is marked):
----------------------------------------------------
       .file   "mystrcpy.c"
        .text
.globl mystrcpy
        .type   mystrcpy, @function
mystrcpy:
        pushl   %ebp
        movl    %esp, %ebp
        movl    12(%ebp), %ecx
        movl    8(%ebp), %edx
        jmp     .L2
.L3:
        incl    %ecx
        incl    %edx
.L2:
        movl    (%ecx), %eax            #### should be 'movb'
        movb    %al, (%edx)
        testb   %al, %al
        jne     .L3
        movl    8(%ebp), %eax
        popl    %ebp
        ret
        .size   mystrcpy, .-mystrcpy
        .ident  "GCC: (GNU) 4.0.0 20041015 (experimental)"
        .section        .note.GNU-stack,"",@progbits
----------------------------------------------------------
Also reproducible on i686-apple-darwin.

-- 
           Summary: -march=pentium4 generates word fetch instead of byte
                    fetch
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: stuart at apple dot com
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux
  GCC host triplet: i686-pc-linux
GCC target triplet: i686-pc-linux


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

Reply via email to