I implemented another 'strlen' function with the same name, I didn't include
the 'stdio.h' file, but when I used -O1 flag, the function has been replaced by
"repnz scasb" without warning. 

Test case is following:

$ cat test.c
int strlen(char* p)
{
        return 0; 
}
main()
{
        return strlen(0);
}
$ gcc -S -O1 test.c
$ cat test.s 
        .file   "test.c"
        .text
.globl strlen
        .type   strlen, @function
strlen:
        pushl   %ebp
        movl    %esp, %ebp
        movl    $0, %eax
        popl    %ebp
        ret
        .size   strlen, .-strlen
.globl main
        .type   main, @function
main:
        leal    4(%esp), %ecx
        andl    $-16, %esp
        pushl   -4(%ecx)
        pushl   %ebp
        movl    %esp, %ebp
        subl    $8, %esp
        movl    %ecx, (%esp)
        movl    %edi, 4(%esp)
        movl    $0, %edi
        movl    $0, %eax
        movl    $-1, %ecx
        repnz scasb
        notl    %ecx
        leal    -1(%ecx), %eax
        movl    (%esp), %ecx
        movl    4(%esp), %edi
        movl    %ebp, %esp
        popl    %ebp
        leal    -4(%ecx), %esp
        ret
        .size   main, .-main
        .ident  "GCC: (GNU) 4.3.2 20081105 (Red Hat 4.3.2-7)"
        .section        .note.GNU-stack,"",@progbits
$


-- 
           Summary: Incorrectly use Built-in function to replace the normal
                    function with flag -O1
           Product: gcc
           Version: 4.3.2
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: baichangjun at gmail dot com
GCC target triplet: i386-redhat-linux


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

Reply via email to