On June 19, 2017 7:46:03 PM GMT+02:00, Jakub Jelinek <ja...@redhat.com> wrote:
>Hi!
>
>Another easy to fix bug reported by bootstrap-ubsan.
>We check that rhsunitoffset fits into shwi, but even if it does,
>8x that might not, in which case we trigger UB.
>Fixed by doing the multiplication in unsigned HWI type to make it well
>defined.
>
>Bootstrapped/regtested on x86_64-linux and i686-linux (both normal
>and bootstrap-ubsan), ok for trunk?

OK.

Richard.

>2017-06-19  Jakub Jelinek  <ja...@redhat.com>
>
>       * tree-ssa-structalias.c (get_constraint_for_ptr_offset): Multiply
>       in UWHI to avoid undefined overflow.
>
>--- gcc/tree-ssa-structalias.c.jj      2017-05-24 11:59:06.000000000 +0200
>+++ gcc/tree-ssa-structalias.c 2017-06-19 14:10:50.989594911 +0200
>@@ -3087,7 +3087,7 @@ get_constraint_for_ptr_offset (tree ptr,
>       {
>         /* Make sure the bit-offset also fits.  */
>         HOST_WIDE_INT rhsunitoffset = soffset.to_shwi ();
>-        rhsoffset = rhsunitoffset * BITS_PER_UNIT;
>+        rhsoffset = rhsunitoffset * (unsigned HOST_WIDE_INT) BITS_PER_UNIT;
>         if (rhsunitoffset != rhsoffset / BITS_PER_UNIT)
>           rhsoffset = UNKNOWN_OFFSET;
>       }
>
>       Jakub

Reply via email to