This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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

--- Comment #10 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to shiyan from comment #7)
> (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 of the function.
> Thank you for the suggestion. Yes, I know -fno-builtin can work around it. I
> can think of many possible ways to work around it....but whatever, it is a
> bug. As I known, redefining a function (override?) is not supported in
> standard C, but first most of compiler supports this including GCC itself
> and second it should behaviour consistently as a compiler. It is really
> crazy that it will not work when N=1 only.

Well there are other functions which GCC optimizes only for some input (some
constant arguments too).  This is an acceptable behavior due to overloading the
function is undefined behavior.  GCC in this case is optimizing
strncmp(s1,"def",1); to *s1-'d' .


Note if I move the definition of s1 to the global scope and remove const, I get
constaint behavior between 32 and 64bits.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]