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.

Reply via email to