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

--- Comment #7 from shiyan <shiyan2016 at 126 dot com> ---
(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.

Also, all other mainstream compiler can work well. And it cannot work with -O0
also, which means it is not an optimization of code generation. Maybe it just
replace strncmp(s1, s2, 1) with (*s1-*s2), I am not sure of the implementation,
but maybe it just do something like this.

Thanks,
Shiyan

Reply via email to