diff mbox

[Fortran] PR52059 - Scalarizing fix - only add array ref to a variable

Message ID 4F2869A9.8000107@net-b.de
State New
Headers show

Commit Message

Tobias Burnus Jan. 31, 2012, 10:22 p.m. UTC
Dear all,

I have no idea about the scalarizer, but the attached patch fixes the 
test case and somehow adding an array ref to a scalar looks odd to me ...

(Before the regression-causing patch, only the "else" branch existed.)

Build and regtested on x86-64-linux.
OK for the trunk?

Tobias

Comments

Mikael Morin Feb. 1, 2012, 11:57 a.m. UTC | #1
On 31.01.2012 23:22, Tobias Burnus wrote:
> Dear all,
>
> I have no idea about the scalarizer, but the attached patch fixes the
> test case and somehow adding an array ref to a scalar looks odd to me ...
>
??
The condition is about an array without array ref, isn't it?
We can't access the "array" part of the "data" union without checking 
before that it is an array.

To be clear the added if branch is there to catch temporaries created by 
the trans-stmt.c part of the regressing patch.  Those had no array ref, 
but gfc_conv_variable (they are temporaries for variables) expects one.
I thought I would have to revert the trans-expr.c part and try to detect 
temporaries somewhere else, but it seems your patch would do just fine.

> (Before the regression-causing patch, only the "else" branch existed.)
>
> Build and regtested on x86-64-linux.
> OK for the trunk?
>
OK, and thanks for it.

Mikael

PS: gfc_conv_derived_to_class has only the "else" branch, but has to 
handle elementals too; I wouldn't be surprised if there was a problem 
with it.
diff mbox

Patch

2012-01-31  Tobias Burnus

	PR fortran/52059
	* trans-expr.c (gfc_conv_procedure_call): Add array ref
	only to variables.

2012-01-31  Tobias Burnus

	PR fortran/52059
	* gfortran.dg/elemental_function_1.f90: New.

Index: gcc/fortran/trans-expr.c
===================================================================
--- gcc/fortran/trans-expr.c	(Revision 183775)
+++ gcc/fortran/trans-expr.c
@@ -3519,21 +3519,21 @@  gfc_conv_procedure_call (gfc_se * se, gf
 	     CLASS object.  */
 	  gfc_init_se (&parmse, se);
 	  gfc_conv_derived_to_class (&parmse, e, fsym->ts);
 	}
       else if (se->ss && se->ss->info->useflags)
 	{
 	  /* An elemental function inside a scalarized loop.  */
 	  gfc_init_se (&parmse, se);
 	  parm_kind = ELEMENTAL;
 
-	  if (se->ss->dimen > 0
+	  if (se->ss->dimen > 0 && e->expr_type == EXPR_VARIABLE
 	      && se->ss->info->data.array.ref == NULL)
 	    {
 	      gfc_conv_tmp_array_ref (&parmse);
 	      if (e->ts.type == BT_CHARACTER)
 		gfc_conv_string_parameter (&parmse);
 	      else
 		parmse.expr = gfc_build_addr_expr (NULL_TREE, parmse.expr);
 	    }
 	  else
 	    gfc_conv_expr_reference (&parmse, e);
Index: gcc/testsuite/gfortran.dg/elemental_function_1.f90
===================================================================
--- gcc/testsuite/gfortran.dg/elemental_function_1.f90	(Revision 0)
+++ gcc/testsuite/gfortran.dg/elemental_function_1.f90
@@ -0,0 +1,22 @@ 
+! { dg-do compile }
+!
+! PR fortran/52059
+!
+!
+
+subroutine baz
+  real(kind=8) :: a(99), b
+  interface bar
+    function bar (x, y)
+      integer, intent(in) :: x, y
+      real(kind=8), dimension((y-x)) :: bar
+    end function bar
+  end interface
+  b = 1.0_8
+  a = foo (bar(0,35) / dble(34), b)
+contains
+  elemental real(kind=8) function foo(x, y)
+    real(kind=8), intent(in) :: x, y
+    foo = 1
+  end function foo
+end subroutine baz