public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/40179]  New: Incorrectly use Built-in function to replace the normal function with flag -O1
@ 2009-05-17 17:38 baichangjun at gmail dot com
  2009-05-17 19:10 ` [Bug c/40179] " pinskia at gcc dot gnu dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: baichangjun at gmail dot com @ 2009-05-17 17:38 UTC (permalink / raw)
  To: gcc-bugs

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


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

* [Bug c/40179] Incorrectly use Built-in function to replace the normal function with flag -O1
  2009-05-17 17:38 [Bug c/40179] New: Incorrectly use Built-in function to replace the normal function with flag -O1 baichangjun at gmail dot com
@ 2009-05-17 19:10 ` pinskia at gcc dot gnu dot org
  2009-05-17 23:09 ` baichangjun at gmail dot com
  2009-05-18  0:37 ` pinskia at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-05-17 19:10 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2009-05-17 19:10 -------
This is expected because strlen is a reserved name in the standard (even
without including string.h) except when the compiler moon is set to
freestanding mode (-ffreestanding) or you turn off the builtin.


-- 

pinskia at gcc dot gnu dot org changed:

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


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


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

* [Bug c/40179] Incorrectly use Built-in function to replace the normal function with flag -O1
  2009-05-17 17:38 [Bug c/40179] New: Incorrectly use Built-in function to replace the normal function with flag -O1 baichangjun at gmail dot com
  2009-05-17 19:10 ` [Bug c/40179] " pinskia at gcc dot gnu dot org
@ 2009-05-17 23:09 ` baichangjun at gmail dot com
  2009-05-18  0:37 ` pinskia at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: baichangjun at gmail dot com @ 2009-05-17 23:09 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from baichangjun at gmail dot com  2009-05-17 23:08 -------
It is not expected. I have done some tests with gcc i386, x86_64, amd64 and
powerpc version. only i386 compiler replaces strlen by builtin function. the
other compilers gave a warning msg: "warning: conflicting types for built-in
function 'strlen'", and chose the correct strlen function in test.c.

test result in x86_64 system:
Target: x86_64-linux-gnu
gcc version 4.2.4 (Ubuntu 4.2.4-1ubuntu4)

$ cat test.c
int strlen(char *p)
{
        return 0;
}
main()
{
        return strlen(0);
}
$ gcc -S -O1 test.c
test.c:2: warning: conflicting types for built-in function 'strlen'
$ cat test.s 
        .file   "test.c"
        .text
.globl strlen
        .type   strlen, @function
strlen:
.LFB2:
        movl    $0, %eax
        ret
.LFE2:
        .size   strlen, .-strlen
.globl main
        .type   main, @function
main:
.LFB3:
        movl    $0, %edi
        call    strlen
        rep ; ret
.LFE3:
        .size   main, .-main
.......
        .ident  "GCC: (GNU) 4.2.4 (Ubuntu 4.2.4-1ubuntu4)"
        .section        .note.GNU-stack,"",@progbits
$ 


-- 


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


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

* [Bug c/40179] Incorrectly use Built-in function to replace the normal function with flag -O1
  2009-05-17 17:38 [Bug c/40179] New: Incorrectly use Built-in function to replace the normal function with flag -O1 baichangjun at gmail dot com
  2009-05-17 19:10 ` [Bug c/40179] " pinskia at gcc dot gnu dot org
  2009-05-17 23:09 ` baichangjun at gmail dot com
@ 2009-05-18  0:37 ` pinskia at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-05-18  0:37 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from pinskia at gcc dot gnu dot org  2009-05-18 00:36 -------
Hmm, The warning is a bit weird because the return type of strlen is size_t
which is unsigned int on i686-linux-gnu and unsigned long on x86_64-linux-gnu
but we ignore the signness for some reason.


-- 


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


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

end of thread, other threads:[~2009-05-18  0:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-17 17:38 [Bug c/40179] New: Incorrectly use Built-in function to replace the normal function with flag -O1 baichangjun at gmail dot com
2009-05-17 19:10 ` [Bug c/40179] " pinskia at gcc dot gnu dot org
2009-05-17 23:09 ` baichangjun at gmail dot com
2009-05-18  0:37 ` pinskia at gcc dot gnu dot 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).