aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPaul Thomas <pault@gcc.gnu.org>2014-02-09 20:50:21 +0000
committerPaul Thomas <pault@gcc.gnu.org>2014-02-09 20:50:21 +0000
commit68b1c5e1f21c973090165c34e59122567b1c03df (patch)
tree71d00773068e77202184e9ae61605c3cd362ea64 /gcc
parent56c78e5c22f59741aba3aac3fa89452895be36bf (diff)
downloadgcc-68b1c5e1f21c973090165c34e59122567b1c03df.zip
gcc-68b1c5e1f21c973090165c34e59122567b1c03df.tar.gz
gcc-68b1c5e1f21c973090165c34e59122567b1c03df.tar.bz2
re PR fortran/57522 ([F03] ASSOCIATE construct creates array descriptor with incorrect stride for derived type array component)
2014-02-09 Paul Thomas <pault@gcc.gnu.org> PR fortran/57522 * resolve.c (resolve_assoc_var): Set the subref_array_pointer attribute for the 'associate-name' if necessary. * trans-stmt.c (trans_associate_var): If the 'associate-name' is a subref_array_pointer, assign the element size of the associate variable to 'span'. 2014-02-09 Paul Thomas <pault@gcc.gnu.org> PR fortran/57522 * gfortran.dg/associated_target_5.f03 : New test From-SVN: r207646
Diffstat (limited to 'gcc')
-rw-r--r--gcc/fortran/ChangeLog9
-rw-r--r--gcc/fortran/resolve.c2
-rw-r--r--gcc/fortran/trans-stmt.c11
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gfortran.dg/associated_target_5.f0340
5 files changed, 67 insertions, 0 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index ab2171a..89b34ab 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,5 +1,14 @@
2014-02-09 Paul Thomas <pault@gcc.gnu.org>
+ PR fortran/57522
+ * resolve.c (resolve_assoc_var): Set the subref_array_pointer
+ attribute for the 'associate-name' if necessary.
+ * trans-stmt.c (trans_associate_var): If the 'associate-name'
+ is a subref_array_pointer, assign the element size of the
+ associate variable to 'span'.
+
+2014-02-09 Paul Thomas <pault@gcc.gnu.org>
+
PR fortran/59026
* trans-expr.c (gfc_conv_procedure_call): Pass the value of the
actual argument to a formal argument with the value attribute
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index 0262165..69ec7bf 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -7820,6 +7820,8 @@ resolve_assoc_var (gfc_symbol* sym, bool resolve_target)
sym->attr.target = tsym->attr.target
|| gfc_expr_attr (target).pointer;
+ if (is_subref_array (target))
+ sym->attr.subref_array_pointer = 1;
}
/* Get type if this was not already set. Note that it can be
diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c
index 50e9a1a..19e29a7 100644
--- a/gcc/fortran/trans-stmt.c
+++ b/gcc/fortran/trans-stmt.c
@@ -1192,6 +1192,17 @@ trans_associate_var (gfc_symbol *sym, gfc_wrapped_block *block)
dim, gfc_index_one_node);
}
+ /* If this is a subreference array pointer associate name use the
+ associate variable element size for the value of 'span'. */
+ if (sym->attr.subref_array_pointer)
+ {
+ gcc_assert (e->expr_type == EXPR_VARIABLE);
+ tmp = e->symtree->n.sym->backend_decl;
+ tmp = gfc_get_element_type (TREE_TYPE (tmp));
+ tmp = fold_convert (gfc_array_index_type, size_in_bytes (tmp));
+ gfc_add_modify (&se.pre, GFC_DECL_SPAN(desc), tmp);
+ }
+
/* Done, register stuff as init / cleanup code. */
gfc_add_init_cleanup (block, gfc_finish_block (&se.pre),
gfc_finish_block (&se.post));
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index d70b762..7295b9f 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,10 @@
2014-02-09 Paul Thomas <pault@gcc.gnu.org>
+ PR fortran/57522
+ * gfortran.dg/associated_target_5.f03 : New test
+
+2014-02-09 Paul Thomas <pault@gcc.gnu.org>
+
PR fortran/59026
* gfortran.dg/elemental_by_value_1.f90 : New test
diff --git a/gcc/testsuite/gfortran.dg/associated_target_5.f03 b/gcc/testsuite/gfortran.dg/associated_target_5.f03
new file mode 100644
index 0000000..5c29b60
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/associated_target_5.f03
@@ -0,0 +1,40 @@
+! { dg-do run }
+! Test the fix for PR57522, in which the associate name had a
+! 'span' of an INTEGER rather than that of 'mytype'.
+!
+! Contributed by A Briolat <alan.briolat@gmail.com>
+!
+program test_associate
+ type mytype
+ integer :: a = 1, b = 2
+ end type
+ type(mytype) :: t(4), u(2,2)
+ integer :: c(4)
+ t%a = [0, 1, 2, 3]
+ t%b = [4, 5, 6, 7]
+ associate (a => t%a)
+! Test 'a' is OK on lhs and/or rhs of assignments
+ c = a - 1
+ if (any (c .ne. [-1,0,1,2])) call abort
+ a = a + 1
+ if (any (a .ne. [1,2,3,4])) call abort
+ a = t%b
+ if (any (a .ne. t%b)) call abort
+! Test 'a' is OK as an actual argument
+ c = foo(a)
+ if (any (c .ne. t%b + 10)) call abort
+ end associate
+! Make sure that the fix works for multi-dimensional arrays...
+ associate (a => u%a)
+ if (any (a .ne. reshape ([1,1,1,1],[2,2]))) call abort
+ end associate
+! ...and sections
+ associate (a => t(2:3)%b)
+ if (any (a .ne. [5,6])) call abort
+ end associate
+contains
+ function foo(arg) result(res)
+ integer :: arg(4), res(4)
+ res = arg + 10
+ end function
+end program