[Bug c/58240] New: GCC optimize strncmp when N=1 incorrectly

2013-08-25 Thread shiyan2016 at 126 dot com
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

[Bug c/58240] GCC optimize strncmp when N=1 incorrectly

2013-08-25 Thread shiyan2016 at 126 dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58240 --- Comment #2 from shiyan --- (In reply to Paolo Carlini from comment #1) > I can't reproduce this. Hi, What is your GCC version? I am using gcc4.7.2. My OS information are as below: $lsb_release -a No LSB modules are available. Distributor ID:

[Bug c/58240] GCC optimize strncmp when N=1 incorrectly

2013-08-25 Thread shiyan2016 at 126 dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58240 --- Comment #7 from shiyan --- (In reply to Marc Glisse from comment #4) > -fno-builtin (or some better such option)? > strncmp is a standard function, your code redefining it has undefined > behavior. gcc optimizes based on the standard behavior

[Bug c/58240] GCC optimize strncmp when N=1 incorrectly

2013-08-25 Thread shiyan2016 at 126 dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58240 --- Comment #8 from shiyan --- (In reply to Jakub Jelinek from comment #6) > The testcase is clearly bogus. You are not using the result of either of > the strncmp calls, strncmp is a pure function, so it is fine not to call it > at all. Hi Jeli

[Bug c/58240] GCC optimize strncmp when N=1 incorrectly

2013-08-25 Thread shiyan2016 at 126 dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58240 --- Comment #9 from shiyan --- (In reply to Paolo Carlini from comment #5) > Closing then. Hi Carlini, I still think it is a bug. I know the test case is not practical. In fact, I will not use such code in real case. But from compiler's side, th

[Bug c/58240] GCC optimize strncmp when N=1 incorrectly

2013-08-26 Thread shiyan2016 at 126 dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58240 --- Comment #13 from shiyan --- Hi all, Thank you for all your explanation. This seems more like a philosophical discussion :) I do can understand what GCC is doing (as I mentioned, it may be optimized to *s1-*s2). And I know that this is som