public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch, fortran, pr65889, v1] [6 Regressions] [OOP] ICE with sizeof a polymorphic variable
@ 2015-10-06 14:23 Andre Vehreschild
  2015-10-06 15:53 ` Mikael Morin
  0 siblings, 1 reply; 3+ messages in thread
From: Andre Vehreschild @ 2015-10-06 14:23 UTC (permalink / raw)
  To: GCC-Fortran-ML, GCC-Patches-ML

[-- Attachment #1: Type: text/plain, Size: 494 bytes --]

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
-- 
Andre Vehreschild * Email: vehre ad gmx dot de 

[-- Attachment #2: pr65889_1.clog --]
[-- Type: text/plain, Size: 313 bytes --]

gcc/fortran/ChangeLog:

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

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

gcc/testsuite/ChangeLog:

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

	* gfortran.dg/sizeof_5.f90: New test.



[-- Attachment #3: pr65889_1.patch --]
[-- Type: text/x-patch, Size: 1679 bytes --]

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Patch, fortran, pr65889, v1] [6 Regressions] [OOP] ICE with sizeof a polymorphic variable
  2015-10-06 14:23 [Patch, fortran, pr65889, v1] [6 Regressions] [OOP] ICE with sizeof a polymorphic variable Andre Vehreschild
@ 2015-10-06 15:53 ` Mikael Morin
  2015-10-07 11:00   ` [Patch, fortran, pr65889, commited] " Andre Vehreschild
  0 siblings, 1 reply; 3+ messages in thread
From: Mikael Morin @ 2015-10-06 15:53 UTC (permalink / raw)
  To: Andre Vehreschild, GCC-Fortran-ML, GCC-Patches-ML

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Patch, fortran, pr65889, commited] [6 Regressions] [OOP] ICE with sizeof a polymorphic variable
  2015-10-06 15:53 ` Mikael Morin
@ 2015-10-07 11:00   ` Andre Vehreschild
  0 siblings, 0 replies; 3+ messages in thread
From: Andre Vehreschild @ 2015-10-07 11:00 UTC (permalink / raw)
  To: Mikael Morin; +Cc: GCC-Fortran-ML, GCC-Patches-ML, Paul Richard Thomas

[-- Attachment #1: Type: text/plain, Size: 826 bytes --]

Hi Mikael, hi Paul, hi all,

Mikael, Paul: Thanks for timely review.

Committed as r228566.

Regards,
	Andre

On Tue, 6 Oct 2015 17:52:55 +0200
Mikael Morin <mikael.morin@sfr.fr> wrote:

> 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


-- 
Andre Vehreschild * Email: vehre ad gmx dot de 

[-- Attachment #2: submit.diff --]
[-- Type: text/x-patch, Size: 2617 bytes --]

Index: gcc/fortran/ChangeLog
===================================================================
--- gcc/fortran/ChangeLog	(Revision 228565)
+++ gcc/fortran/ChangeLog	(Arbeitskopie)
@@ -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: gcc/fortran/trans-intrinsic.c
===================================================================
--- gcc/fortran/trans-intrinsic.c	(Revision 228565)
+++ gcc/fortran/trans-intrinsic.c	(Arbeitskopie)
@@ -5937,11 +5937,16 @@
     }
   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: gcc/testsuite/ChangeLog
===================================================================
--- gcc/testsuite/ChangeLog	(Revision 228565)
+++ gcc/testsuite/ChangeLog	(Arbeitskopie)
@@ -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.
Index: gcc/testsuite/gfortran.dg/sizeof_5.f90
===================================================================
--- gcc/testsuite/gfortran.dg/sizeof_5.f90	(Revision 0)
+++ gcc/testsuite/gfortran.dg/sizeof_5.f90	(Arbeitskopie)
@@ -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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-10-07 11:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-06 14:23 [Patch, fortran, pr65889, v1] [6 Regressions] [OOP] ICE with sizeof a polymorphic variable Andre Vehreschild
2015-10-06 15:53 ` Mikael Morin
2015-10-07 11:00   ` [Patch, fortran, pr65889, commited] " Andre Vehreschild

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).