aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorAndre Vehreschild <vehre@gcc.gnu.org>2024-07-18 14:53:31 +0200
committerAndre Vehreschild <vehre@gcc.gnu.org>2024-08-21 08:38:56 +0200
commit515730fd65a03c5f92f9ab6438d023aee8cfbecf (patch)
tree3622924f93f90de13c7b081bfd8e0f26a5d7c478 /gcc
parent34292a1ae89a13baf974ff2ecb21dcf89aab4617 (diff)
downloadgcc-515730fd65a03c5f92f9ab6438d023aee8cfbecf.zip
gcc-515730fd65a03c5f92f9ab6438d023aee8cfbecf.tar.gz
gcc-515730fd65a03c5f92f9ab6438d023aee8cfbecf.tar.bz2
Fortran: Fix ICE in sizeof(coarray) [PR77518]
Use se's class_container where present in sizeof(). PR fortran/77518 gcc/fortran/ChangeLog: * trans-intrinsic.cc (gfc_conv_intrinsic_sizeof): Use class_container of se when set. gcc/testsuite/ChangeLog: * gfortran.dg/coarray/sizeof_1.f90: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/fortran/trans-intrinsic.cc13
-rw-r--r--gcc/testsuite/gfortran.dg/coarray/sizeof_1.f9027
2 files changed, 37 insertions, 3 deletions
diff --git a/gcc/fortran/trans-intrinsic.cc b/gcc/fortran/trans-intrinsic.cc
index fd2da46..0ecb043 100644
--- a/gcc/fortran/trans-intrinsic.cc
+++ b/gcc/fortran/trans-intrinsic.cc
@@ -8216,10 +8216,17 @@ gfc_conv_intrinsic_sizeof (gfc_se *se, gfc_expr *expr)
else if (arg->rank > 0
|| (arg->rank == 0
&& arg->ref && arg->ref->type == REF_COMPONENT))
- /* The scalarizer added an additional temp. To get the class' vptr
- one has to look at the original backend_decl. */
- byte_size = gfc_class_vtab_size_get (
+ {
+ /* The scalarizer added an additional temp. To get the class' vptr
+ one has to look at the original backend_decl. */
+ if (argse.class_container)
+ byte_size = gfc_class_vtab_size_get (argse.class_container);
+ else if (DECL_LANG_SPECIFIC (arg->symtree->n.sym->backend_decl))
+ byte_size = gfc_class_vtab_size_get (
GFC_DECL_SAVED_DESCRIPTOR (arg->symtree->n.sym->backend_decl));
+ else
+ gcc_unreachable ();
+ }
else
gcc_unreachable ();
}
diff --git a/gcc/testsuite/gfortran.dg/coarray/sizeof_1.f90 b/gcc/testsuite/gfortran.dg/coarray/sizeof_1.f90
new file mode 100644
index 0000000..b26f841
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/coarray/sizeof_1.f90
@@ -0,0 +1,27 @@
+!{ dg-do run }
+
+! Check that pr77518 is fixed.
+! Based on code by Gerhard Steinmetz <gerhard.steinmetz.fortran@t-online.de>
+
+program coarray_sizeof_1
+ type t
+ end type
+ type t2
+ integer :: v = 42
+ end type
+ type t3
+ type(t2) :: s
+ integer :: n = 1
+ end type
+
+ class(t), allocatable :: z[:]
+ class(t2), allocatable :: z2[:]
+ class(t3), allocatable :: z3[:]
+
+ if (sizeof(z) /= 0) stop 1
+ if (sizeof(z2) /= sizeof(integer)) stop 2
+ allocate(z3[*])
+ if (sizeof(z3) /= sizeof(z2) + sizeof(integer)) stop 3
+ if (sizeof(z3%s) /= sizeof(z2)) stop 4
+end
+