re PR target/84945 (UBSAN: gcc/config/i386/i386.c:33312:22: runtime error: shift...
authorJakub Jelinek <jakub@redhat.com>
Mon, 16 Apr 2018 11:22:40 +0000 (13:22 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 16 Apr 2018 11:22:40 +0000 (13:22 +0200)
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.

From-SVN: r259398

libgcc/ChangeLog
libgcc/config/i386/cpuinfo.c

index a715f0b074e2c71d19e5cd63dc96d889e5bdd53b..aeaa65391677b8765e9118dfa0fd24960297507c 100644 (file)
@@ -1,3 +1,10 @@
+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.
+
 2018-04-06  Ruslan Bukin  <br@bsdpad.com>
 
        * config.host (riscv*-*-freebsd*): Add RISC-V FreeBSD support.
index 1dac110a79ac6a4a554f0267faf843dddad5d053..86953db2743f55b47298dfd223fdbd4847d6ae59 100644 (file)
@@ -275,7 +275,14 @@ get_available_features (unsigned int ecx, unsigned int edx,
     }
 
 #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);