diff options
author | Eric Botcazou <ebotcazou@adacore.com> | 2021-03-05 12:38:49 +0100 |
---|---|---|
committer | Eric Botcazou <ebotcazou@adacore.com> | 2021-03-05 12:47:28 +0100 |
commit | 28354bc22bd66648891a875ee08ca2b27debf2a2 (patch) | |
tree | b43b40b41ae00495bb1794bfe9c8fed15c784c85 /gcc | |
parent | 6ddedd3efa3fe482f76a4037521a06b3ac9f2a8b (diff) | |
download | gcc-28354bc22bd66648891a875ee08ca2b27debf2a2.zip gcc-28354bc22bd66648891a875ee08ca2b27debf2a2.tar.gz gcc-28354bc22bd66648891a875ee08ca2b27debf2a2.tar.bz2 |
Fix undefined behavior spotted by the sanitizer
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.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rtlanal.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/gcc/rtlanal.c b/gcc/rtlanal.c index d1240b0..a8ea1d7 100644 --- a/gcc/rtlanal.c +++ b/gcc/rtlanal.c @@ -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; |