[PATCH] Fix libgcc/config/i386/cpuinfo.c warnings (PR target/84945)

Uros Bizjak ubizjak@gmail.com
Mon Apr 16 11:13:00 GMT 2018


On Mon, Apr 16, 2018 at 1:11 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> On Mon, Apr 16, 2018 at 12:50:29PM +0200, Thomas Schwinge wrote:
>> > +#define set_feature(f) \
>> > +  if (f < 32) features |= (1U << f); else features2 |= (1U << (f - 32))
>> >    if (edx & bit_CMOV)
>> > -    features |= (1 << FEATURE_CMOV);
>> > +    set_feature (FEATURE_CMOV);
>>
>>     [...]/libgcc/config/i386/cpuinfo.c: In function 'get_available_features':
>>     [...]/libgcc/config/i386/cpuinfo.c:278:60: warning: left shift count is negative [-Wshift-count-negative]
>>        if (f < 32) features |= (1U << f); else features2 |= (1U << (f - 32))
>>                                                                 ^~
>>     [...]/libgcc/config/i386/cpuinfo.c:281:5: note: in expansion of macro 'set_feature'
>>          set_feature (FEATURE_CMOV);
>>          ^~~~~~~~~~~
>>     [...]/libgcc/config/i386/cpuinfo.c:280:6: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
>>        if (edx & bit_CMOV)
>>           ^
>>     [Many more.]
>
> Oops, missed these.  All of the warnings are false positives (warn on dead
> code) or style warning (-Wdangling-else), not actual code bugs.
>
> The following patch fixes all the warnings without changing code generation,
> we are using set_feature with constant arguments only, so everything is
> folded properly anyway.
>
> Ok for trunk?
>
> 2018-04-16  Jakub Jelinek  <jakub@redhat.com>
>
>         PR target/84945
>         * config/i386/cpuinfo.c (set_feature): Wrap into do while (0) to avoid
>         -Wdangling-else warnings.  Mask shift counts to avoid
>         -Wshift-count-negative and -Wshift-count-overflow false positives.

OK.

Thanks,
Uros.

> --- libgcc/config/i386/cpuinfo.c.jj     2018-03-30 20:37:37.683185248 +0200
> +++ libgcc/config/i386/cpuinfo.c        2018-04-16 13:04:45.239490344 +0200
> @@ -275,7 +275,14 @@ get_available_features (unsigned int ecx
>      }
>
>  #define set_feature(f) \
> -  if (f < 32) features |= (1U << f); else features2 |= (1U << (f - 32))
> +  do                                           \
> +    {                                          \
> +      if (f < 32)                              \
> +       features |= (1U << (f & 31));           \
> +      else                                     \
> +       features2 |= (1U << ((f - 32) & 31));   \
> +    }                                          \
> +  while (0)
>
>    if (edx & bit_CMOV)
>      set_feature (FEATURE_CMOV);
>
>
>         Jakub



More information about the Gcc-patches mailing list