Re: [Patch, fortran v2] PR fortran/84006, PR fortran/100027 - ICE on storage_size with polymorphic argument

2021-04-17 Thread Paul Richard Thomas via Gcc-patches
Hi Jose,

Please take a look at my reply on the PR, which points to PR98534.

Regards

Paul


On Fri, 16 Apr 2021 at 20:47, José Rui Faustino de Sousa via Fortran <
fort...@gcc.gnu.org> wrote:

> Hi All!
>
> Proposed patch to:
> PR84006 - [8/9/10/11 Regression] ICE in storage_size() with CLASS entity
> PR100027 - ICE on storage_size with polymorphic argument
>
> Patch tested only on x86_64-pc-linux-gnu.
>
> Add branch to if clause to handle polymorphic objects, not sure if I got
> all possible variations...
>
> Now with a new and extended test.
>
> Thank you very much.
>
> Best regards,
> José Rui
>
> Fortran: Fix ICE using storage_size intrinsic [PR84006, PR100027]
>
> gcc/fortran/ChangeLog:
>
>  PR fortran/84006
>  PR fortran/100027
>  * trans-intrinsic.c (gfc_conv_intrinsic_storage_size): add if
>  clause branch to handle polymorphic objects.
>
> gcc/testsuite/ChangeLog:
>
>  PR fortran/84006
>  * gfortran.dg/PR84006.f90: New test.
>
>  PR fortran/100027
>  * gfortran.dg/PR100027.f90: New test.
>


-- 
"If you can't explain it simply, you don't understand it well enough" -
Albert Einstein


[Patch, fortran v2] PR fortran/84006, PR fortran/100027 - ICE on storage_size with polymorphic argument

2021-04-16 Thread José Rui Faustino de Sousa via Gcc-patches

Hi All!

Proposed patch to:
PR84006 - [8/9/10/11 Regression] ICE in storage_size() with CLASS entity
PR100027 - ICE on storage_size with polymorphic argument

Patch tested only on x86_64-pc-linux-gnu.

Add branch to if clause to handle polymorphic objects, not sure if I got 
all possible variations...


Now with a new and extended test.

Thank you very much.

Best regards,
José Rui

Fortran: Fix ICE using storage_size intrinsic [PR84006, PR100027]

gcc/fortran/ChangeLog:

PR fortran/84006
PR fortran/100027
* trans-intrinsic.c (gfc_conv_intrinsic_storage_size): add if
clause branch to handle polymorphic objects.

gcc/testsuite/ChangeLog:

PR fortran/84006
* gfortran.dg/PR84006.f90: New test.

PR fortran/100027
* gfortran.dg/PR100027.f90: New test.
diff --git a/configure b/configure
index 504f6410274..1be51708c03 100755
--- a/configure
+++ b/configure
@@ -756,6 +756,7 @@ infodir
 docdir
 oldincludedir
 includedir
+runstatedir
 localstatedir
 sharedstatedir
 sysconfdir
@@ -922,6 +923,7 @@ datadir='${datarootdir}'
 sysconfdir='${prefix}/etc'
 sharedstatedir='${prefix}/com'
 localstatedir='${prefix}/var'
+runstatedir='${localstatedir}/run'
 includedir='${prefix}/include'
 oldincludedir='/usr/include'
 docdir='${datarootdir}/doc/${PACKAGE}'
@@ -1174,6 +1176,15 @@ do
   | -silent | --silent | --silen | --sile | --sil)
 silent=yes ;;
 
+  -runstatedir | --runstatedir | --runstatedi | --runstated \
+  | --runstate | --runstat | --runsta | --runst | --runs \
+  | --run | --ru | --r)
+ac_prev=runstatedir ;;
+  -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \
+  | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \
+  | --run=* | --ru=* | --r=*)
+runstatedir=$ac_optarg ;;
+
   -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
 ac_prev=sbindir ;;
   -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
@@ -1311,7 +1322,7 @@ fi
 for ac_var in	exec_prefix prefix bindir sbindir libexecdir datarootdir \
 		datadir sysconfdir sharedstatedir localstatedir includedir \
 		oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
-		libdir localedir mandir
+		libdir localedir mandir runstatedir
 do
   eval ac_val=\$$ac_var
   # Remove trailing slashes.
@@ -1471,6 +1482,7 @@ Fine tuning of the installation directories:
   --sysconfdir=DIRread-only single-machine data [PREFIX/etc]
   --sharedstatedir=DIRmodifiable architecture-independent data [PREFIX/com]
   --localstatedir=DIR modifiable single-machine data [PREFIX/var]
+  --runstatedir=DIR   modifiable per-process data [LOCALSTATEDIR/run]
   --libdir=DIRobject code libraries [EPREFIX/lib]
   --includedir=DIRC header files [PREFIX/include]
   --oldincludedir=DIR C header files for non-gcc [/usr/include]
diff --git a/gcc/fortran/trans-intrinsic.c b/gcc/fortran/trans-intrinsic.c
index 5e53d1162fa..6536c121f2b 100644
--- a/gcc/fortran/trans-intrinsic.c
+++ b/gcc/fortran/trans-intrinsic.c
@@ -8353,10 +8353,16 @@ gfc_conv_intrinsic_storage_size (gfc_se *se, gfc_expr *expr)
   if (arg->ts.type == BT_CLASS)
 	{
 	  if (arg->rank > 0)
-	tmp = gfc_class_vtab_size_get (
-		 GFC_DECL_SAVED_DESCRIPTOR (arg->symtree->n.sym->backend_decl));
+	{
+	  if (TREE_CODE (argse.expr) == COMPONENT_REF)
+		tmp = TREE_OPERAND (argse.expr, 0);
+	  else
+		tmp = GFC_DECL_SAVED_DESCRIPTOR (
+		  arg->symtree->n.sym->backend_decl);
+	}
 	  else
-	tmp = gfc_class_vtab_size_get (TREE_OPERAND (argse.expr, 0));
+	tmp = TREE_OPERAND (argse.expr, 0);
+	  tmp = gfc_class_vtab_size_get (tmp);
 	  tmp = fold_convert (result_type, tmp);
 	  goto done;
 	}
diff --git a/gcc/testsuite/gfortran.dg/PR100027.f90 b/gcc/testsuite/gfortran.dg/PR100027.f90
new file mode 100644
index 000..4cee549d055
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/PR100027.f90
@@ -0,0 +1,425 @@
+! { dg-do run }
+!
+! Test fix for PR100027
+!
+! in colaboration with Tobias Burnus.
+! 
+
+program main_p
+
+  implicit none
+
+  integer, parameter :: n = 111
+
+  integer, parameter :: ikind = kind(n)
+  integer, parameter :: bsize = 8
+  integer, parameter :: isize = bit_size(n)
+  integer, parameter :: dsize = (n+1)*isize
+  
+  type :: foo_t
+integer :: i
+  end type foo_t
+
+  type, extends(foo_t) :: bar_t
+integer :: j(n)
+  end type bar_t
+  
+  type :: box_t
+class(foo_t), allocatable :: x, y(:)
+  end type box_t
+
+  integer,   target :: ain(n)
+  type(foo_t),   target :: afd(n)
+  type(bar_t),   target :: abd(n)
+  type(box_t),   target :: afx(n)
+  type(box_t),   target :: abx(n)
+  !
+  class(*), pointer :: spu
+  class(*), pointer :: apu(:)
+  !
+  class(foo_t), pointer :: spf
+  class(foo_t), pointer :: apf(:)
+  !
+  class(bar_t), pointer :: spb
+  class(bar_t), pointer :: apb(:)
+  !
+  class(box_t), pointer :: spx
+  class(box_t), pointer :: apx(:)
+  !
+  integer   :: i, j, so, ss
+
+  ain = [(i, i=1,n)]
+