Re: out of bound warning in non-builtin strcmp() with a fixed argument with two characters.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>:
> 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


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux