diff mbox

[fortran,pr65889,v1,6,Regressions,OOP] ICE with sizeof a polymorphic variable

Message ID 20151006162257.4f62cb8e@vepi2
State New
Headers show

Commit Message

Andre Vehreschild Oct. 6, 2015, 2:22 p.m. UTC
Hi all,

the attached patch fixes a 6 regression when the argument of sizeof()
is a pointer to a class object, e.g., when the class object is
intent(out). The patch improves the check if the parameter is a
class object by previously checking whether the argument is the plain
object or a pointer to one and using TREE_OPERAND() once or twice,
respectively.

Bootstraps and regtests ok on x86_64-linux-gnu/f21.

Ok for trunk?

Regards,
	Andre

Comments

Mikael Morin Oct. 6, 2015, 3:52 p.m. UTC | #1
Le 06/10/2015 16:22, Andre Vehreschild a écrit :
> Hi all,
>
> the attached patch fixes a 6 regression when the argument of sizeof()
> is a pointer to a class object, e.g., when the class object is
> intent(out). The patch improves the check if the parameter is a
> class object by previously checking whether the argument is the plain
> object or a pointer to one and using TREE_OPERAND() once or twice,
> respectively.
>
> Bootstraps and regtests ok on x86_64-linux-gnu/f21.
>
> Ok for trunk?
>
Ok. Thanks.

Mikael
diff mbox

Patch

diff --git a/gcc/fortran/trans-intrinsic.c b/gcc/fortran/trans-intrinsic.c
index 35052be..ac61c09 100644
--- a/gcc/fortran/trans-intrinsic.c
+++ b/gcc/fortran/trans-intrinsic.c
@@ -5937,11 +5937,16 @@  gfc_conv_intrinsic_sizeof (gfc_se *se, gfc_expr *expr)
     }
   else if (arg->ts.type == BT_CLASS)
     {
-      /* For deferred length arrays, conv_expr_descriptor returns an
-	 indirect_ref to the component.  */
+      /* Conv_expr_descriptor returns a component_ref to _data component of the
+	 class object.  The class object may be a non-pointer object, e.g.
+	 located on the stack, or a memory location pointed to, e.g. a
+	 parameter, i.e., an indirect_ref.  */
       if (arg->rank < 0
 	  || (arg->rank > 0 && !VAR_P (argse.expr)
-	      && GFC_DECL_CLASS (TREE_OPERAND (argse.expr, 0))))
+	      && ((INDIRECT_REF_P (TREE_OPERAND (argse.expr, 0))
+		   && GFC_DECL_CLASS (TREE_OPERAND (
+					TREE_OPERAND (argse.expr, 0), 0)))
+		  || GFC_DECL_CLASS (TREE_OPERAND (argse.expr, 0)))))
 	byte_size = gfc_class_vtab_size_get (TREE_OPERAND (argse.expr, 0));
       else if (arg->rank > 0)
 	/* The scalarizer added an additional temp.  To get the class' vptr
diff --git a/gcc/testsuite/gfortran.dg/sizeof_5.f90 b/gcc/testsuite/gfortran.dg/sizeof_5.f90
new file mode 100644
index 0000000..0e1496a
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/sizeof_5.f90
@@ -0,0 +1,15 @@ 
+! { dg-do compile }
+!
+! PR fortran/65889
+!
+!
+module m
+  type n
+  end type n
+contains
+  subroutine g(ns)
+    class(n), intent(out), allocatable, dimension(:) :: ns
+    class(n), allocatable, dimension(:) :: tmp
+    write (0,*) sizeof(ns), sizeof(tmp)
+  end subroutine g
+end module m