diff options
author | Richard Guenther <rguenther@suse.de> | 2007-08-24 09:41:17 +0000 |
---|---|---|
committer | Richard Biener <rguenth@gcc.gnu.org> | 2007-08-24 09:41:17 +0000 |
commit | 9c219b9bb34eafa7d9f42e3ffc5e73f77e397a75 (patch) | |
tree | 075bb7598ac3d2840c86bc617c31db2cf5b37ec2 /gcc/expr.c | |
parent | 1651030c4233d2bc976a89a5ac746969de805162 (diff) | |
download | gcc-9c219b9bb34eafa7d9f42e3ffc5e73f77e397a75.zip gcc-9c219b9bb34eafa7d9f42e3ffc5e73f77e397a75.tar.gz gcc-9c219b9bb34eafa7d9f42e3ffc5e73f77e397a75.tar.bz2 |
expr.c (get_inner_reference): Do computation of bitoffset from offset in a way we can detect overflow reliably.
2007-08-23 Richard Guenther <rguenther@suse.de>
* expr.c (get_inner_reference): Do computation of bitoffset
from offset in a way we can detect overflow reliably.
From-SVN: r127762
Diffstat (limited to 'gcc/expr.c')
-rw-r--r-- | gcc/expr.c | 32 |
1 files changed, 20 insertions, 12 deletions
@@ -5782,7 +5782,6 @@ get_inner_reference (tree exp, HOST_WIDE_INT *pbitsize, enum machine_mode mode = VOIDmode; tree offset = size_zero_node; tree bit_offset = bitsize_zero_node; - tree tem; /* First get the mode, signedness, and size. We do this from just the outermost expression. */ @@ -5825,6 +5824,8 @@ get_inner_reference (tree exp, HOST_WIDE_INT *pbitsize, *pbitsize = tree_low_cst (size_tree, 1); } + *pmode = mode; + /* Compute cumulative bit-offset for nested component-refs and array-refs, and find the ultimate containing object. */ while (1) @@ -5909,18 +5910,25 @@ get_inner_reference (tree exp, HOST_WIDE_INT *pbitsize, done: /* If OFFSET is constant, see if we can return the whole thing as a - constant bit position. Otherwise, split it up. */ - if (host_integerp (offset, 0) - && 0 != (tem = size_binop (MULT_EXPR, - fold_convert (bitsizetype, offset), - bitsize_unit_node)) - && 0 != (tem = size_binop (PLUS_EXPR, tem, bit_offset)) - && host_integerp (tem, 0)) - *pbitpos = tree_low_cst (tem, 0), *poffset = 0; - else - *pbitpos = tree_low_cst (bit_offset, 0), *poffset = offset; + constant bit position. Make sure to handle overflow during + this conversion. */ + if (host_integerp (offset, 0)) + { + double_int tem = double_int_mul (tree_to_double_int (offset), + uhwi_to_double_int (BITS_PER_UNIT)); + tem = double_int_add (tem, tree_to_double_int (bit_offset)); + if (double_int_fits_in_shwi_p (tem)) + { + *pbitpos = double_int_to_shwi (tem); + *poffset = NULL_TREE; + return exp; + } + } + + /* Otherwise, split it up. */ + *pbitpos = tree_low_cst (bit_offset, 0); + *poffset = offset; - *pmode = mode; return exp; } |