summaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorpault <pault@138bc75d-0d04-0410-961f-82ee72b054a4>2014-02-01 18:50:41 +0000
committerpault <pault@138bc75d-0d04-0410-961f-82ee72b054a4>2014-02-01 18:50:41 +0000
commite6b9055742c9e58d717bedf78c374a484d919849 (patch)
tree0754839255200a09b43ee9c4cd2f13648314144e /gcc
parent69811c67b5668fd9ff2705e363f1e39f9a337d14 (diff)
downloadgcc-e6b9055742c9e58d717bedf78c374a484d919849.tar.gz
2014-02-01 Paul Thomas <pault@gcc.gnu.org>
PR fortran/59906 * trans-stmt.c (gfc_add_loop_ss_code): In the case of character SS_REFERENCE, use gfc_conv_string_parameter to ensure that a pointer to the string is stored. * trans-expr.c (gfc_conv_expr_reference): Likewise, use gfc_conv_string_parameter to ensure that a pointer to is passed to the elemental function. 2014-02-01 Paul Thomas <pault@gcc.gnu.org> PR fortran/59906 * gfortran.dg/elemental_subroutine_9.f90 : New test git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@207389 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc')
-rw-r--r--gcc/fortran/ChangeLog10
-rw-r--r--gcc/fortran/trans-array.c5
-rw-r--r--gcc/fortran/trans-expr.c8
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gfortran.dg/elemental_subroutine_9.f9039
5 files changed, 66 insertions, 1 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index 577d7784d2c..5e3a48a65d7 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,13 @@
+2014-02-01 Paul Thomas <pault@gcc.gnu.org>
+
+ PR fortran/59906
+ * trans-stmt.c (gfc_add_loop_ss_code): In the case of character
+ SS_REFERENCE, use gfc_conv_string_parameter to ensure that a
+ pointer to the string is stored.
+ * trans-expr.c (gfc_conv_expr_reference): Likewise, use
+ gfc_conv_string_parameter to ensure that a pointer to is passed
+ to the elemental function.
+
2014-01-28 Paul Thomas <pault@gcc.gnu.org>
PR fortran/59414
diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index 0f5375dba95..8e7b75ed601 100644
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -2491,6 +2491,11 @@ gfc_add_loop_ss_code (gfc_loopinfo * loop, gfc_ss * ss, bool subscript,
a reference to the value. */
gfc_conv_expr (&se, expr);
}
+
+ /* Ensure that a pointer to the string is stored. */
+ if (expr->ts.type == BT_CHARACTER)
+ gfc_conv_string_parameter (&se);
+
gfc_add_block_to_block (&outer_loop->pre, &se.pre);
gfc_add_block_to_block (&outer_loop->post, &se.post);
if (gfc_is_class_scalar_expr (expr))
diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c
index 1e156ff9c02..12da0a0025e 100644
--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -6350,7 +6350,13 @@ gfc_conv_expr_reference (gfc_se * se, gfc_expr * expr)
/* Returns a reference to the scalar evaluated outside the loop
for this case. */
gfc_conv_expr (se, expr);
- se->expr = gfc_build_addr_expr (NULL_TREE, se->expr);
+
+ if (expr->ts.type == BT_CHARACTER
+ && expr->expr_type != EXPR_FUNCTION)
+ gfc_conv_string_parameter (se);
+ else
+ se->expr = gfc_build_addr_expr (NULL_TREE, se->expr);
+
return;
}
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index b4c6fdd5c13..8af85b50c0e 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2014-02-01 Paul Thomas <pault@gcc.gnu.org>
+
+ PR fortran/59906
+ * gfortran.dg/elemental_subroutine_9.f90 : New test
+
2014-02-01 Richard Sandiford <rdsandiford@googlemail.com>
* gcc.dg/tree-ssa/ssa-dom-thread-4.c: Adjust expected MIPS output.
diff --git a/gcc/testsuite/gfortran.dg/elemental_subroutine_9.f90 b/gcc/testsuite/gfortran.dg/elemental_subroutine_9.f90
new file mode 100644
index 00000000000..8f574bf595e
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/elemental_subroutine_9.f90
@@ -0,0 +1,39 @@
+! { dg-do run }
+!
+! PR fortran/59906
+!
+! Contributed by H Anlauf <anlauf@gmx.de>
+!
+! Failed generate character scalar for scalarized loop for elemantal call.
+!
+program x
+ implicit none
+ call y('bbb')
+contains
+
+ subroutine y(str)
+ character(len=*), intent(in) :: str
+ character(len=len_trim(str)) :: str_aux
+ character(len=3) :: str3 = 'abc'
+
+ str_aux = str
+
+ ! Compiled but did not give correct result
+ if (any (str_cmp((/'aaa','bbb'/), str) .neqv. [.FALSE.,.TRUE.])) call abort
+
+ ! Did not compile
+ if (any (str_cmp((/'bbb', 'aaa'/), str_aux) .neqv. [.TRUE.,.FALSE.])) call abort
+
+ ! Verify patch
+ if (any (str_cmp((/'bbb', 'aaa'/), str3) .neqv. [.FALSE.,.FALSE.])) call abort
+ if (any (str_cmp((/'bbb', 'aaa'/), 'aaa') .neqv. [.FALSE.,.TRUE.])) call abort
+
+ end subroutine y
+
+ elemental logical function str_cmp(str1, str2)
+ character(len=*), intent(in) :: str1
+ character(len=*), intent(in) :: str2
+ str_cmp = (str1 == str2)
+ end function str_cmp
+
+end program x