re PR fortran/17077 (adjustable size arrays crash)
authorPaul Brook <pbrook@gcc.gnu.org>
Fri, 20 Aug 2004 13:31:13 +0000 (13:31 +0000)
committerPaul Brook <pbrook@gcc.gnu.org>
Fri, 20 Aug 2004 13:31:13 +0000 (13:31 +0000)
2004-08-20  Paul Brook  <paul@codesourcery.com>
Canqun Yang  <canqun@nudt.edu.cn>

PR fortran/17077
* trans-array.c (gfc_conv_array_parameter): Pass correct pointer
for automatic arrays.
* trans-types.c (gfc_get_nodesc_array_type): Add comment.
testsuite/
* gfortran.dg/auto_array_1.f90: New test.

From-SVN: r86315

gcc/fortran/ChangeLog
gcc/fortran/trans-array.c
gcc/fortran/trans-types.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/auto_array_1.f90 [new file with mode: 0644]

index 1adf05549cc708920f924d60429c22facf687584..fed67a6cb0789161ba73088613d69841624970c0 100644 (file)
@@ -1,12 +1,20 @@
+2004-08-20  Paul Brook  <paul@codesourcery.com>
+       Canqun Yang  <canqun@nudt.edu.cn>
+
+       PR fortran/17077
+       * trans-array.c (gfc_conv_array_parameter): Pass correct pointer
+       for automatic arrays.
+       * trans-types.c (gfc_get_nodesc_array_type): Add comment.
+
 2004-08-19  Tobias Schlueter  <tobias.schlueter@physik.uni-muenchen.de>
-       (Port from g95)
+       (Port from g95)
 
-       PR fortran/17074
+       PR fortran/17074
        * match.c (match_simple_forall, match_simple_where): Forward-declare.
        (gfc_match_if): Order statement list alphabetically, add WHERE and
-               FORALL, remove double PAUSE.
+       FORALL, remove double PAUSE.
        (gfc_match_simple_where, match_forall_header,
-       gfc_match_simple_forall): New functions.
+       gfc_match_simple_forall): New functions.
        (gfc_match_forall): Use match_forall_header.
        
 2004-08-19  Paul Brook  <paul@codesourcery.com>
index 3abb1959ebe1760db6a4d494d0f2fac9165919c8..5299b4c2cdd17dd20cb0d639244a228670e28933 100644 (file)
@@ -3762,10 +3762,12 @@ gfc_conv_array_parameter (gfc_se * se, gfc_expr * expr, gfc_ss * ss, int g77)
       if (!sym->attr.pointer && sym->as->type != AS_ASSUMED_SHAPE 
           && !sym->attr.allocatable)
         {
-          if (!sym->attr.dummy)
-           se->expr = gfc_build_addr_expr (NULL, tmp);
+         /* Some variables are declared directly, others are declard as
+            pointers and allocated on the heap.  */
+          if (sym->attr.dummy || POINTER_TYPE_P (TREE_TYPE (tmp)))
+            se->expr = tmp;
           else
-            se->expr = tmp;  
+           se->expr = gfc_build_addr_expr (NULL, tmp);
          return;
         }
       if (sym->attr.allocatable)
index 2b4edfc0e2797729922921743c331a2b048bac64..f8a0450ce1fab2a35ef79e537a06c35a31bf6eb7 100644 (file)
@@ -750,6 +750,8 @@ gfc_get_nodesc_array_type (tree etype, gfc_array_spec * as, int packed)
 
   if (packed < 3 || !known_stride)
     {
+      /* For dummy arrays and automatic (heap allocated) arrays we
+        want a pointer to the array.  */
       type = build_pointer_type (type);
       GFC_ARRAY_TYPE_P (type) = 1;
       TYPE_LANG_SPECIFIC (type) = TYPE_LANG_SPECIFIC (TREE_TYPE (type));
index e8d985af0fe01b12cd63e6d4a38424b5d7e117d9..6dd1b04041c7aa4b7da4f644ee0e18f63e466d1e 100644 (file)
@@ -1,3 +1,8 @@
+2004-08-20  Canqun Yang  <canqun@nudt.edu.cn>
+
+       PR fortran/17077
+       * gfortran.dg/auto_array_1.f90: New test.
+
 2004-08-19  Tobias Schlueter  <tobias.schlueter@physik.uni-muenchen.de>
 
        PR fortran/17074
diff --git a/gcc/testsuite/gfortran.dg/auto_array_1.f90 b/gcc/testsuite/gfortran.dg/auto_array_1.f90
new file mode 100644 (file)
index 0000000..64cc113
--- /dev/null
@@ -0,0 +1,38 @@
+! { dg-do run }
+! PR fortran/17077.
+! Automatic arrays are allocated on the heap.  When used as an actual argument
+! we were passing the address of the pointer, not the pointer itself.
+
+program p
+   implicit none
+   integer:: n,m
+
+   n = 3
+   call foo(n)
+contains
+
+   subroutine foo(m)
+      integer:: m,i
+      integer:: z(m,m)
+    
+      z = 0
+
+      call foo1(m,z)
+    
+      ! Check it worked.
+      if (any (z .ne. reshape ((/1, 2, 3, 4, 5, 6, 7, 8, 9/), (/3, 3/)))) &
+        call abort
+    end subroutine foo
+
+    subroutine foo1(n,x)
+       integer:: n,i,j
+       integer:: x(n,n)
+    
+       ! Assign values to x.
+       do i=1,n
+          do j=1,n
+             x(j,i)=j+(i-1)*n
+          enddo
+       enddo
+    end subroutine foo1
+end program