re PR fortran/65889 ([6 Regressions] [OOP] ICE with sizeof a polymorphic variable.)
authorAndre Vehreschild <vehre@gcc.gnu.org>
Wed, 7 Oct 2015 10:58:46 +0000 (12:58 +0200)
committerAndre Vehreschild <vehre@gcc.gnu.org>
Wed, 7 Oct 2015 10:58:46 +0000 (12:58 +0200)
gcc/fortran/ChangeLog:

2015-10-07  Andre Vehreschild  <vehre@gcc.gnu.org>

PR fortran/65889
* trans-intrinsic.c (gfc_conv_intrinsic_sizeof): Handle pointer to and
on stack class objects as sizeof parameter.

gcc/testsuite/ChangeLog:

2015-10-07  Andre Vehreschild  <vehre@gcc.gnu.org>

PR fortran/65889
* gfortran.dg/sizeof_5.f90: New test.

From-SVN: r228566

gcc/fortran/ChangeLog
gcc/fortran/trans-intrinsic.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/sizeof_5.f90 [new file with mode: 0644]

index 4dba1deac9e2ca9cefefff22708d33593ec590eb..8d21be5b64e13775febabf96721dff3148115938 100644 (file)
@@ -1,3 +1,9 @@
+2015-10-07  Andre Vehreschild  <vehre@gcc.gnu.org>
+
+       PR fortran/65889
+       * trans-intrinsic.c (gfc_conv_intrinsic_sizeof): Handle pointer to and
+       on stack class objects as sizeof parameter.
+
 2015-10-06  Louis Krupp <louis.krupp@zoho.com>
        PR fortran/65766
        * resolve.c (gfc_resolve_substring_charlen): For derived type,
index 35052bebb8ee322c3dc5a8f1da9aaa4cb3a09d06..ac61c096a99e064d90bd3a5009e5502e701e4d3e 100644 (file)
@@ -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
index 1882fbd03dc453551a6bd2213f70e7a669efc87a..2b7094692cd93b6937d2f0292a0021bae334b4b9 100644 (file)
@@ -1,3 +1,8 @@
+2015-10-07  Andre Vehreschild  <vehre@gcc.gnu.org>
+
+       PR fortran/65889
+       * gfortran.dg/sizeof_5.f90: New test.
+
 2015-10-06  Jeff Law  <law@redhat.com>
 
        * gcc.c-torture/compile/pr67816.c: New test.
diff --git a/gcc/testsuite/gfortran.dg/sizeof_5.f90 b/gcc/testsuite/gfortran.dg/sizeof_5.f90
new file mode 100644 (file)
index 0000000..0e1496a
--- /dev/null
@@ -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