diff options
author | Thomas Koenig <tkoenig@gcc.gnu.org> | 2010-09-06 19:43:58 +0000 |
---|---|---|
committer | Thomas Koenig <tkoenig@gcc.gnu.org> | 2010-09-06 19:43:58 +0000 |
commit | f884552b4f02a94b32d070715a91787753f6128b (patch) | |
tree | f6863c4f091e031bf4d0aaf4be1d0d4b3816ca9b /gcc | |
parent | f973b6486953e926ee6795c879af3986e81967b1 (diff) | |
download | gcc-f884552b4f02a94b32d070715a91787753f6128b.zip gcc-f884552b4f02a94b32d070715a91787753f6128b.tar.gz gcc-f884552b4f02a94b32d070715a91787753f6128b.tar.bz2 |
re PR fortran/34145 (single_char_string.f90 fails with -fdefault-integer-8)
2010-09-06 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/34145
* trans-expr.c (gfc_conv_substring): If start and end
of the string reference are equal, set the length to one.
2010-09-06 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/34145
* gfortran.dg/char_length_17.f90: New test.
From-SVN: r163932
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/fortran/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/fortran/trans-expr.c | 20 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gfortran.dg/char_length_17.f90 | 15 |
4 files changed, 40 insertions, 6 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 26974bb..d35cedc 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2010-09-06 Thomas Koenig <tkoenig@gcc.gnu.org> + + PR fortran/34145 + * trans-expr.c (gfc_conv_substring): If start and end + of the string reference are equal, set the length to one. + 2010-09-06 Tobias Burnus <burnus@net-b.de> PR fortran/45560 diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c index 8f1bddc..479c807 100644 --- a/gcc/fortran/trans-expr.c +++ b/gcc/fortran/trans-expr.c @@ -463,12 +463,20 @@ gfc_conv_substring (gfc_se * se, gfc_ref * ref, int kind, gfc_free (msg); } - tmp = fold_build2_loc (input_location, MINUS_EXPR, gfc_charlen_type_node, - end.expr, start.expr); - tmp = fold_build2_loc (input_location, PLUS_EXPR, gfc_charlen_type_node, - build_int_cst (gfc_charlen_type_node, 1), tmp); - tmp = fold_build2_loc (input_location, MAX_EXPR, gfc_charlen_type_node, tmp, - build_int_cst (gfc_charlen_type_node, 0)); + /* If the start and end expressions are equal, the length is one. */ + if (ref->u.ss.end + && gfc_dep_compare_expr (ref->u.ss.start, ref->u.ss.end) == 0) + tmp = build_int_cst (gfc_charlen_type_node, 1); + else + { + tmp = fold_build2_loc (input_location, MINUS_EXPR, gfc_charlen_type_node, + end.expr, start.expr); + tmp = fold_build2_loc (input_location, PLUS_EXPR, gfc_charlen_type_node, + build_int_cst (gfc_charlen_type_node, 1), tmp); + tmp = fold_build2_loc (input_location, MAX_EXPR, gfc_charlen_type_node, + tmp, build_int_cst (gfc_charlen_type_node, 0)); + } + se->string_length = tmp; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 4805390..362f5d1 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2010-09-06 Thomas Koenig <tkoenig@gcc.gnu.org> + + PR fortran/34145 + * gfortran.dg/char_length_17.f90: New test. + 2010-09-06 Dodji Seketeli <dodji@redhat.com> PR c++/45200 diff --git a/gcc/testsuite/gfortran.dg/char_length_17.f90 b/gcc/testsuite/gfortran.dg/char_length_17.f90 new file mode 100644 index 0000000..5752dd1 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/char_length_17.f90 @@ -0,0 +1,15 @@ +! { dg-do compile } +! { dg-options "-fdump-tree-original" } +! PR 34145 - the length of the string should be simplified to one, +! no library call for string comparison is necessary. +program main + character (len=5) :: c + integer(kind=8) :: i + i = 3 + c(i:i) = 'a' + c(i+1:i+1) = 'b' + if (c(i:i) /= 'a') call abort () + if (c(i+1:i+1) /= 'b') call abort () +end program main +! { dg-final { scan-tree-dump-times "gfortran_compare_string" 0 "original" } } +! { dg-final { cleanup-tree-dump "original" } } |