]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR fortran/57522 ([F03] ASSOCIATE construct creates array descriptor with incorrec...
authorPaul Thomas <pault@gcc.gnu.org>
Sun, 9 Feb 2014 20:50:21 +0000 (20:50 +0000)
committerPaul Thomas <pault@gcc.gnu.org>
Sun, 9 Feb 2014 20:50:21 +0000 (20:50 +0000)
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

gcc/fortran/ChangeLog
gcc/fortran/resolve.c
gcc/fortran/trans-stmt.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/associated_target_5.f03 [new file with mode: 0644]

index ab2171a811abcf1dd67bc532483ac5a28d0aca57..89b34abff0f53fd4e13ab3e5aed33ab830213b43 100644 (file)
@@ -1,3 +1,12 @@
+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
index 02621656583acb42f480590c712b98a1cbf993c9..69ec7bf4c18fc95ccfdbff0754d41a756d9264bf 100644 (file)
@@ -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
index 50e9a1a2abf2ccb37b491f382d8d45b41bca0cd9..19e29a74bceafa7f8cd139ad54bb5359e2a0ba52 100644 (file)
@@ -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));
index d70b76235cfaf400d4895ff01caf739378b76d47..7295b9fd9533f6b0e829ad6b482369e95dd6b8ba 100644 (file)
@@ -1,3 +1,8 @@
+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
diff --git a/gcc/testsuite/gfortran.dg/associated_target_5.f03 b/gcc/testsuite/gfortran.dg/associated_target_5.f03
new file mode 100644 (file)
index 0000000..5c29b60
--- /dev/null
@@ -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