From: Martin Liska Date: Mon, 19 Feb 2018 18:29:52 +0000 (+0100) Subject: Fix ubsan in gimple-fold.c (PR tree-optimization/82491). X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6a5aca53278dd43bea2618126f282125c5ca3e02;p=gcc.git Fix ubsan in gimple-fold.c (PR tree-optimization/82491). 2018-02-19 Martin Liska Richard Sandiford PR tree-optimization/82491 * gimple-fold.c (get_base_constructor): Make earlier bail out to prevent ubsan. Co-Authored-By: Richard Sandiford From-SVN: r257816 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 6b5972278f3..7a37db734da 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2018-02-19 Martin Liska + Richard Sandiford + + PR tree-optimization/82491 + * gimple-fold.c (get_base_constructor): Make earlier bail out + to prevent ubsan. + 2018-02-19 Carl Love * config/rs6000/rs6000-builtin.def: Change NEG macro expansions from diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c index e556f050e43..c9dad6f42d1 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -6442,13 +6442,9 @@ get_base_constructor (tree base, poly_int64_pod *bit_offset, if (TREE_CODE (base) == MEM_REF) { - if (!integer_zerop (TREE_OPERAND (base, 1))) - { - if (!tree_fits_shwi_p (TREE_OPERAND (base, 1))) - return NULL_TREE; - *bit_offset += (mem_ref_offset (base).force_shwi () - * BITS_PER_UNIT); - } + poly_offset_int boff = *bit_offset + mem_ref_offset (base) * BITS_PER_UNIT; + if (!boff.to_shwi (bit_offset)) + return NULL_TREE; if (valueize && TREE_CODE (TREE_OPERAND (base, 0)) == SSA_NAME)