diff mbox

[Fortran] PR 48800 - fix "IMPORT :: symbol"

Message ID 4DBB3193.1020200@net-b.de
State New
Headers show

Commit Message

Tobias Burnus April 29, 2011, 9:45 p.m. UTC
Nearly obvious patch. Build and regtested on x86-64-linux.

OK for the trunk?

Tobias

Comments

Jerry DeLisle April 30, 2011, 3:31 p.m. UTC | #1
On 04/29/2011 02:45 PM, Tobias Burnus wrote:
> Nearly obvious patch. Build and regtested on x86-64-linux.
>
> OK for the trunk?
>
> Tobias

Thats a oneliner.  OK

Thanks,

Jerry
Mikael Morin May 1, 2011, 7:08 p.m. UTC | #2
> --- a/gcc/fortran/decl.c
> +++ b/gcc/fortran/decl.c
> @@ -2995,7 +2995,7 @@ gfc_match_import (void)
>                gfc_error ("Type name '%s' at %C is ambiguous", name);
>                return MATCH_ERROR;
>             }
> -         else if (gfc_current_ns->proc_name->ns->parent !=  NULL
> +         else if (!sym && gfc_current_ns->proc_name->ns->parent !=  NULL
>                    && gfc_find_symbol (name,
>                                        gfc_current_ns->proc_name->ns-
>parent,
>                                        1, &sym))
> 
I think sym could be used uninitialized.
In the if condition before, if gfc_current_ns->parent ==  NULL, the call to 
gfc_find_symbol (which either sets or clears sym) is skipped.
If you clear sym in the declaration, your patch is probably useless (not sure 
however, as there is a loop around the whole lot). 
I have the feeling that sym should be cleared first thing in the loop body. 

Mikael
diff mbox

Patch

2011-04-30  Tobias Burnus  <burnus@net-b.de>

	PR fortran/48800
	* decl.c (gfc_match_import): Don't try to find the
	symbol if already found.

2011-04-30  Tobias Burnus  <burnus@net-b.de>

	PR fortran/48800
	* gfortran.dg/interface_36.f90: New.

diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
index 9901fb1..dfbca29 100644
--- a/gcc/fortran/decl.c
+++ b/gcc/fortran/decl.c
@@ -2995,7 +2995,7 @@  gfc_match_import (void)
 	       gfc_error ("Type name '%s' at %C is ambiguous", name);
 	       return MATCH_ERROR;
 	    }
-	  else if (gfc_current_ns->proc_name->ns->parent !=  NULL
+	  else if (!sym && gfc_current_ns->proc_name->ns->parent !=  NULL
 		   && gfc_find_symbol (name,
 				       gfc_current_ns->proc_name->ns->parent,
 				       1, &sym))
--- /dev/null	2011-04-29 18:38:34.095891993 +0200
+++ gcc/gcc/testsuite/gfortran.dg/interface_36.f90	2011-04-29 19:10:43.000000000 +0200
@@ -0,0 +1,28 @@ 
+! { dg-do compile }
+!
+! PR fortran/48800
+!
+! Contributed by Daniel Carrera
+!
+     pure function runge_kutta_step(t, r_, dr, h) result(res)
+         real, intent(in) :: t, r_(:), h
+         real, dimension(:), allocatable :: k1, k2, k3, k4, res
+         integer :: N
+
+         interface
+             pure function dr(t, r_)  ! { dg-error "cannot have a deferred shape" }
+                 real, intent(in) :: t, r_(:)
+                 real :: dr(:)
+             end function
+         end interface
+
+         N = size(r_)
+         allocate(k1(N),k2(N),k3(N),k4(N),res(N))
+
+         k1 = dr(t, r_)
+         k2 = dr(t + h/2, r_ + k1*h/2)
+         k3 = dr(t + h/2, r_ + k2*h/2)
+         k4 = dr(t + h  , r_ + k3*h)
+
+         res = r_ + (k1 + 2*k2 + 2*k3 + k4) * h/6
+     end function