]> gcc.gnu.org Git - gcc.git/commitdiff
Fix undefined behavior spotted by the sanitizer
authorEric Botcazou <ebotcazou@adacore.com>
Fri, 5 Mar 2021 11:38:49 +0000 (12:38 +0100)
committerEric Botcazou <ebotcazou@adacore.com>
Fri, 5 Mar 2021 11:47:28 +0000 (12:47 +0100)
gcc/
PR rtl-optimization/99376
* rtlanal.c (nonzero_bits1) <arithmetic operators>: If the number
of low-order zero bits is too large, set the result to 0 directly.

gcc/rtlanal.c

index d1240b0b7c5a8ffcc0e505c4ccc078270175bf53..a8ea1d72636f293f602c6b4da3f102734eff3f2f 100644 (file)
@@ -5053,11 +5053,17 @@ nonzero_bits1 (const_rtx x, scalar_int_mode mode, const_rtx known_x,
            gcc_unreachable ();
          }
 
+       /* Note that mode_width <= HOST_BITS_PER_WIDE_INT, see above.  */
        if (result_width < mode_width)
          nonzero &= (HOST_WIDE_INT_1U << result_width) - 1;
 
        if (result_low > 0)
-         nonzero &= ~((HOST_WIDE_INT_1U << result_low) - 1);
+         {
+           if (result_low < HOST_BITS_PER_WIDE_INT)
+             nonzero &= ~((HOST_WIDE_INT_1U << result_low) - 1);
+           else
+             nonzero = 0;
+         }
       }
       break;
 
This page took 0.067858 seconds and 5 git commands to generate.