This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix -fno-automatic with variable length arrays (PR fortran/28415)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: fortran at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Thu, 5 Oct 2006 12:38:47 -0400
- Subject: [PATCH] Fix -fno-automatic with variable length arrays (PR fortran/28415)
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
We ICE on the testcase below with -fno-automatic, because arr is made
TREE_STATIC and gfc_trans_auto_array_allocation asserts that it is not
if it has POINTER_TYPE.
Either we can drop that assert, there isn't in
gfc_trans_auto_array_allocation really anything that would rely on it
being an automatic variable, but IMHO it is better just not make
TREE_STATIC what doesn't make sense at all. That includes the POINTER_TYPE
variable that is assigned __builtin_alloca (which has no value after it the
current function leaves) and also includes e.g. all artificial variables
(string lengths, etc.).
Ok for trunk?
2006-10-05 Jakub Jelinek <jakub@redhat.com>
PR fortran/28415
* trans-decl.c (gfc_finish_var_decl): With -fno-automatic, don't
make artificial variables or pointer to variable automatic array
TREE_STATIC.
* gfortran.dg/pr28415.f90: New test.
--- gcc/fortran/trans-decl.c.jj 2006-10-05 00:27:43.000000000 +0200
+++ gcc/fortran/trans-decl.c 2006-10-05 18:09:39.000000000 +0200
@@ -511,7 +511,14 @@ gfc_finish_var_decl (tree decl, gfc_symb
/* Keep variables larger than max-stack-var-size off stack. */
if (!sym->ns->proc_name->attr.recursive
&& INTEGER_CST_P (DECL_SIZE_UNIT (decl))
- && !gfc_can_put_var_on_stack (DECL_SIZE_UNIT (decl)))
+ && !gfc_can_put_var_on_stack (DECL_SIZE_UNIT (decl))
+ /* Don't put variable length auto array pointers off stack. */
+ && (TREE_CODE (TREE_TYPE (decl)) != POINTER_TYPE
+ || sym->attr.dimension == 0
+ || sym->as->type != AS_EXPLICIT
+ || sym->attr.pointer
+ || sym->attr.allocatable)
+ && !DECL_ARTIFICIAL (decl))
TREE_STATIC (decl) = 1;
/* Handle threadprivate variables. */
--- gcc/testsuite/gfortran.dg/pr28415.f90.jj 2006-10-05 18:25:19.000000000 +0200
+++ gcc/testsuite/gfortran.dg/pr28415.f90 2006-10-05 18:14:14.000000000 +0200
@@ -0,0 +1,22 @@
+! PR fortran/28415
+! { dg-do run }
+! { dg-options "-O2 -fno-automatic" }
+
+ program foo
+ integer arrlen
+ arrlen = 30
+ call bar(arrlen)
+ stop
+ end
+
+ subroutine bar(arg)
+ integer arg
+ double precision arr(arg)
+ do i = 1, arg
+ arr(i) = 1.0d0
+ enddo
+ do i = 1, arg
+ write(*,*) i, arr(i)
+ enddo
+ return
+ end
Jakub