This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Don't call gfc_finish_var_decl on length decls (PR fortran/26246)


Hi!

As shown on the attached two testcases, calling gfc_finish_var_decl
is a bad idea for the length decls.  gfc_add_decl_to_function
does all that is needed, we know those decls aren't Cray pointers/pointees,
aren't module variables, aren't threadprivate, etc.

Tested with make check-fortran, full bootstrap will start RSN.
Ok for trunk?

2006-02-13  Andrew Pinski  <pinskia@physics.uc.edu>
	    Jakub Jelinek  <jakub@redhat.com>

	PR fortran/26246
	* trans-decl.c (gfc_get_symbol_decl, gfc_get_fake_result_decl): Use
	gfc_add_decl_to_function rather than gfc_finish_var_decl on length.

	* gfortran.dg/pr26246_1.f90: New test.
	* gfortran.dg/pr26246_2.f90: New test.

--- gcc/fortran/trans-decl.c.jj	2006-02-07 12:52:44.000000000 +0100
+++ gcc/fortran/trans-decl.c	2006-02-13 15:04:57.000000000 +0100
@@ -880,7 +880,7 @@ gfc_get_symbol_decl (gfc_symbol * sym)
 	  if (TREE_CODE (length) == VAR_DECL
 	      && DECL_CONTEXT (length) == NULL_TREE)
 	    {
-	      gfc_finish_var_decl (length, sym);
+	      gfc_add_decl_to_function (length);
 	      gfc_defer_symbol_init (sym);
 	    }
 	}
@@ -1792,7 +1792,7 @@ gfc_get_fake_result_decl (gfc_symbol * s
 	length = sym->ts.cl->backend_decl;
       if (TREE_CODE (length) == VAR_DECL
 	  && DECL_CONTEXT (length) == NULL_TREE)
-	gfc_finish_var_decl (length, sym);
+	gfc_add_decl_to_function (length);
     }
 
   if (gfc_return_by_reference (sym))
--- gcc/testsuite/gfortran.dg/pr26246_2.f90.jj	2006-02-13 15:28:10.000000000 +0100
+++ gcc/testsuite/gfortran.dg/pr26246_2.f90	2006-02-13 15:27:00.000000000 +0100
@@ -0,0 +1,13 @@
+! PR fortran/26246
+! { dg-options "-fdump-tree-original -fno-automatic" }
+! { dg-do compile }
+
+subroutine foo(string, n)
+  implicit none
+  integer :: n
+  character(len=n + 6), intent(in) :: string
+  if (string .eq. 'abc') call abort
+end subroutine foo
+
+! { dg-final { scan-tree-dump-times "static int" 0 "original" } }
+! { dg-final { cleanup-tree-dump "original" } }
--- gcc/testsuite/gfortran.dg/pr26246_1.f90.jj	2006-02-13 15:28:04.000000000 +0100
+++ gcc/testsuite/gfortran.dg/pr26246_1.f90	2006-02-13 15:27:00.000000000 +0100
@@ -0,0 +1,18 @@
+! PR fortran/26246
+! { dg-options "-fdump-tree-original" }
+! { dg-do compile }
+
+module pr26246_1
+  implicit none
+  contains
+    function foo(string)
+    character(*), intent(in) :: string
+    character(len=len(string)+2) :: foo
+    if (index(trim(string), '"').ne.0) then
+      foo = "'" // trim(string) // "'"
+    end if
+  end function foo
+end module pr26246_1
+
+! { dg-final { scan-tree-dump-times "static int" 0 "original" } }
+! { dg-final { cleanup-tree-dump "original" } }

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]