re PR middle-end/26001 (expand uses the wrong part of the string for array accesses)
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. From-SVN: r110465
This commit is contained in:
parent
60ec1aa4bc
commit
f51a281b45
4 changed files with 52 additions and 9 deletions
|
@ -1,3 +1,10 @@
|
|||
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.
|
||||
|
||||
2006-01-31 Andrew Pinski <pinskia@physics.uc.edu>
|
||||
|
||||
* mode-switching.c (optimize_mode_switching): Fix size
|
||||
|
|
37
gcc/expr.c
37
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);
|
||||
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 (index)], mode);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
2006-01-31 Andrew Pinski <pinskia@physics.uc.edu>
|
||||
|
||||
PR middle-end/26001
|
||||
* gfortran.dg/data_char_2.f90: New.
|
||||
|
||||
2006-01-31 Thomas Koenig <Thomas.Koenig@online.de>
|
||||
|
||||
PR fortran/26039
|
||||
|
|
12
gcc/testsuite/gfortran.dg/data_char_2.f90
Normal file
12
gcc/testsuite/gfortran.dg/data_char_2.f90
Normal file
|
@ -0,0 +1,12 @@
|
|||
! { dg-do run }
|
||||
! Test that getting a character from a
|
||||
! string data works.
|
||||
|
||||
CHARACTER*10 INTSTR
|
||||
CHARACTER C1
|
||||
DATA INTSTR / '0123456789' /
|
||||
|
||||
C1 = INTSTR(1:1)
|
||||
if(C1 .ne. '0') call abort()
|
||||
|
||||
end
|
Loading…
Add table
Reference in a new issue