This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: out of bound warning in non-builtin strcmp() with a fixed argument with two characters.
Ian Lance Taylor-3 wrote:
>
> 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
>
>
Wow. Macros are never pretty, but this one must take some sort of prize for
ugliness, with five nested ?: operators.
John Boncek
--
View this message in context: http://www.nabble.com/out-of-bound-warning-in-non-builtin-strcmp%28%29-with-a-fixed-argument--%09with-two-characters.-tp25922602p25933129.html
Sent from the gcc - Help mailing list archive at Nabble.com.