diff options
author | Paul Thomas <pault@gcc.gnu.org> | 2006-10-16 22:29:46 +0000 |
---|---|---|
committer | Paul Thomas <pault@gcc.gnu.org> | 2006-10-16 22:29:46 +0000 |
commit | 5b440a1cf426fa8dc01ebc5453015c09a69e7480 (patch) | |
tree | 36463b2afe69cf810cf47a28df21f64d27c408bc /gcc/fortran | |
parent | f2523ab3c482c8cd066d5760b32eb843829300fa (diff) | |
download | gcc-5b440a1cf426fa8dc01ebc5453015c09a69e7480.zip gcc-5b440a1cf426fa8dc01ebc5453015c09a69e7480.tar.gz gcc-5b440a1cf426fa8dc01ebc5453015c09a69e7480.tar.bz2 |
[multiple changes]
2006-10-17 Paul Thomas <pault@gcc.gnu.org>
PR fortran/20541
* trans-array.c (gfc_trans_array_bounds): Test for and set
negative stride of a non-constant bound array to zero.
PR fortran/29392
* data.c (create_character_intializer): Copy and simplify
the expressions for the start and end of a sub-string
reference.
2006-10-17 Paul Thomas <pault@gcc.gnu.org>
PR fortran/29392
* gfortran.dg/data_char_3.f90: New test.
PR fortran/20541
* gfortran.dg/negative_automatic_size.f90: New test.
From-SVN: r117797
Diffstat (limited to 'gcc/fortran')
-rw-r--r-- | gcc/fortran/ChangeLog | 11 | ||||
-rw-r--r-- | gcc/fortran/data.c | 17 | ||||
-rw-r--r-- | gcc/fortran/trans-array.c | 8 |
3 files changed, 34 insertions, 2 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index a86d161..ac027c7 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,14 @@ +2006-10-17 Paul Thomas <pault@gcc.gnu.org> + + PR fortran/20541 + * trans-array.c (gfc_trans_array_bounds): Test for and set + negative stride of a non-constant bound array to zero. + + PR fortran/29392 + * data.c (create_character_intializer): Copy and simplify + the expressions for the start and end of a sub-string + reference. + 2006-10-16 Kaz Kojima <kkojima@rr.iij4u.or.jp> * io.c (gfc_match_close): Ensure that status is terminated by diff --git a/gcc/fortran/data.c b/gcc/fortran/data.c index e12eccd..2ab6f50 100644 --- a/gcc/fortran/data.c +++ b/gcc/fortran/data.c @@ -167,13 +167,26 @@ create_character_intializer (gfc_expr * init, gfc_typespec * ts, if (ref) { + gfc_expr *start_expr, *end_expr; + gcc_assert (ref->type == REF_SUBSTRING); /* Only set a substring of the destination. Fortran substring bounds are one-based [start, end], we want zero based [start, end). */ - gfc_extract_int (ref->u.ss.start, &start); + start_expr = gfc_copy_expr (ref->u.ss.start); + end_expr = gfc_copy_expr (ref->u.ss.end); + + if ((gfc_simplify_expr (start_expr, 1) == FAILURE) + || (gfc_simplify_expr (end_expr, 1)) == FAILURE) + { + gfc_error ("failure to simplify substring reference in DATA" + "statement at %L", &ref->u.ss.start->where); + return NULL; + } + + gfc_extract_int (start_expr, &start); start--; - gfc_extract_int (ref->u.ss.end, &end); + gfc_extract_int (end_expr, &end); } else { diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c index ba07f02..6fd93dd 100644 --- a/gcc/fortran/trans-array.c +++ b/gcc/fortran/trans-array.c @@ -3540,6 +3540,14 @@ gfc_trans_array_bounds (tree type, gfc_symbol * sym, tree * poffset, gfc_add_modify_expr (pblock, stride, tmp); else stride = gfc_evaluate_now (tmp, pblock); + + /* Make sure that negative size arrays are translated + to being zero size. */ + tmp = build2 (GE_EXPR, boolean_type_node, + stride, gfc_index_zero_node); + tmp = build3 (COND_EXPR, gfc_array_index_type, tmp, + stride, gfc_index_zero_node); + gfc_add_modify_expr (pblock, stride, tmp); } size = stride; |