This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/58240] New: GCC optimize strncmp when N=1 incorrectly
- From: "shiyan2016 at 126 dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sun, 25 Aug 2013 14:44:25 +0000
- Subject: [Bug c/58240] New: GCC optimize strncmp when N=1 incorrectly
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58240
Bug ID: 58240
Summary: GCC optimize strncmp when N=1 incorrectly
Product: gcc
Version: 4.7.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: shiyan2016 at 126 dot com
Hi,
I have found a weird bug of GCC. I am trying to overwrite the C 'strncmp'
function, but I get different results when N=1 and N>1, see below test case:
/*
bug of strncmp when N=1
gcc: 4.7.2
*/
#include <stdio.h>
int strncmp(const char *s1,const char *s2,int n){
printf("strncmp\n");
return 0;
}
int main() {
const char *s1="def";
int ret;
printf("test\n");
ret=strncmp(s1,"def",1); // bug: "strncmp" is not printed!!!
printf("test\n");
ret=strncmp(s1,"def",2);
return 0;
}
To reproduce:
$gcc --version
gcc (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$gcc 1.c
$./a.out
test
test
strncmp
$
It will print "strncmp" when N=2, but not printed when N=1. From my
overservation, it seems strncmp(*,*,1) is optimized without calling to strncmp
at all.
Please try to check the behaviour and see whether it is a front-end bug.
By the way, the same test case can work as expected with MS compiler and Intel
compiler.