out of bound warning in non-builtin strcmp() with a fixed argument with two characters.
Alfonso Cepeda Caballos
cepeda@gmail.com
Fri Oct 16 18:03:00 GMT 2009
It seems that there already was a bug about this:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35903
It's old, but active. I have put the test case in that bug.
Thanks for your help.
2009/10/16 Ian Lance Taylor <iant@google.com>:
> You didn't mention the machine you are using, nor the version of gcc.
> However, I hypothesize that you are using GNU/Linux. On GNU/Linux,
> <string.h> includes <bits/string2.h>. When optimizing,
> <bits/string2.h> defines strcmp as a macro, as follows:
>
> # define strcmp(s1, s2) \
> __extension__ \
> ({ size_t __s1_len, __s2_len; \
> (__builtin_constant_p (s1) && __builtin_constant_p (s2) \
> && (__s1_len = strlen (s1), __s2_len = strlen (s2), \
> (!__string2_1bptr_p (s1) || __s1_len >= 4) \
> && (!__string2_1bptr_p (s2) || __s2_len >= 4)) \
> ? __builtin_strcmp (s1, s2) \
> : (__builtin_constant_p (s1) && __string2_1bptr_p (s1) \
> && (__s1_len = strlen (s1), __s1_len < 4) \
> ? (__builtin_constant_p (s2) && __string2_1bptr_p (s2) \
> ? __builtin_strcmp (s1, s2) \
> : __strcmp_cg (s1, s2, __s1_len)) \
> : (__builtin_constant_p (s2) && __string2_1bptr_p (s2) \
> && (__s2_len = strlen (s2), __s2_len < 4) \
> ? (__builtin_constant_p (s1) && __string2_1bptr_p (s1) \
> ? __builtin_strcmp (s1, s2) \
> : __strcmp_gc (s1, s2, __s2_len)) \
> : __builtin_strcmp (s1, s2)))); })
>
> The warning is coming from a reference in that macro. At a guess, the
> macro somehow gets too complicated for gcc to sort out that some code
> is never executed. I'm not sure why that only occurs in one case but
> not the others.
>
> It's probably worth filing a bug report on this. Please follow the
> directions at http://gcc.gnu.org/bugs.html . In particular, please
> include the preprocessed source code. Thanks.
>
> Ian
>
--
Alfonso Cepeda
More information about the Gcc-help
mailing list