diff options
author | pinskia <pinskia@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-02-01 01:03:52 +0000 |
---|---|---|
committer | pinskia <pinskia@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-02-01 01:03:52 +0000 |
commit | 19160d6035c93835c4a588414589405145b1b871 (patch) | |
tree | e83f3620b518a00126b9852a9bbf074173c665d6 /gcc/expr.c | |
parent | 613768ea32fcb8305a6be574aa5966f0b54ef668 (diff) | |
download | gcc-19160d6035c93835c4a588414589405145b1b871.tar.gz |
2006-01-31 Andrew Pinski <pinskia@physics.uc.edu>
PR middle-end/26001
* gfortran.dg/data_char_2.f90: New.
2006-01-31 Andrew Pinski <pinskia@physics.uc.edu>
PR middle-end/26001
* expr.c (expand_expr_real_1) <case ARRAY_REF>:
Use the corrected index for the character
out of the string constant.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@110465 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/expr.c')
-rw-r--r-- | gcc/expr.c | 39 |
1 files changed, 29 insertions, 10 deletions
diff --git a/gcc/expr.c b/gcc/expr.c index e10171f9181..362ab8b5756 100644 --- a/gcc/expr.c +++ b/gcc/expr.c @@ -7126,17 +7126,36 @@ expand_expr_real_1 (tree exp, rtx target, enum machine_mode tmode, break; } } - else if (TREE_CODE (init) == STRING_CST - && 0 > compare_tree_int (index, - TREE_STRING_LENGTH (init))) + else if(TREE_CODE (init) == STRING_CST) { - tree type = TREE_TYPE (TREE_TYPE (init)); - enum machine_mode mode = TYPE_MODE (type); - - if (GET_MODE_CLASS (mode) == MODE_INT - && GET_MODE_SIZE (mode) == 1) - return gen_int_mode (TREE_STRING_POINTER (init) - [TREE_INT_CST_LOW (index)], mode); + tree index1 = index; + tree low_bound = array_ref_low_bound (exp); + index1 = fold_convert (sizetype, TREE_OPERAND (exp, 1)); + + /* Optimize the special-case of a zero lower bound. + + We convert the low_bound to sizetype to avoid some problems + with constant folding. (E.g. suppose the lower bound is 1, + and its mode is QI. Without the conversion,l (ARRAY + +(INDEX-(unsigned char)1)) becomes ((ARRAY+(-(unsigned char)1)) + +INDEX), which becomes (ARRAY+255+INDEX). Opps!) */ + + if (! integer_zerop (low_bound)) + index1 = size_diffop (index1, fold_convert (sizetype, + low_bound)); + + if (0 > compare_tree_int (index1, + TREE_STRING_LENGTH (init))) + { + tree type = TREE_TYPE (TREE_TYPE (init)); + enum machine_mode mode = TYPE_MODE (type); + + if (GET_MODE_CLASS (mode) == MODE_INT + && GET_MODE_SIZE (mode) == 1) + return gen_int_mode (TREE_STRING_POINTER (init) + [TREE_INT_CST_LOW (index1)], + mode); + } } } } |