aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPaul Thomas <pault@gcc.gnu.org>2017-11-05 14:32:05 +0000
committerPaul Thomas <pault@gcc.gnu.org>2017-11-05 14:32:05 +0000
commit5233d45559d5869fe7dc9705d6c79e6538d8a2ab (patch)
tree4312d6964f57222d5150f716ba8439e6ef4da776 /gcc
parentaea5e9327a49bc73878a547d490bb32ac31df03e (diff)
downloadgcc-5233d45559d5869fe7dc9705d6c79e6538d8a2ab.zip
gcc-5233d45559d5869fe7dc9705d6c79e6538d8a2ab.tar.gz
gcc-5233d45559d5869fe7dc9705d6c79e6538d8a2ab.tar.bz2
re PR fortran/78641 ([OOP] ICE on polymorphic allocatable function in array constructor)
2017-11-05 Paul Thomas <pault@gcc.gnu.org> PR fortran/78641 * resolve.c (resolve_ordinary_assign): Do not add the _data component for class valued array constructors being assigned to derived type arrays. * trans-array.c (gfc_trans_array_ctor_element): Take the _data of class valued elements for assignment to derived type arrays. 2017-11-05 Paul Thomas <pault@gcc.gnu.org> PR fortran/78641 * gfortran.dg/class_66.f90: New test. From-SVN: r254428
Diffstat (limited to 'gcc')
-rw-r--r--gcc/fortran/ChangeLog9
-rw-r--r--gcc/fortran/resolve.c3
-rw-r--r--gcc/fortran/trans-array.c11
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gfortran.dg/class_66.f9028
5 files changed, 55 insertions, 1 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index 1a4da46..cbc8e29 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,5 +1,14 @@
2017-11-05 Paul Thomas <pault@gcc.gnu.org>
+ PR fortran/78641
+ * resolve.c (resolve_ordinary_assign): Do not add the _data
+ component for class valued array constructors being assigned
+ to derived type arrays.
+ * trans-array.c (gfc_trans_array_ctor_element): Take the _data
+ of class valued elements for assignment to derived type arrays.
+
+2017-11-05 Paul Thomas <pault@gcc.gnu.org>
+
PR fortran/81447
PR fortran/82783
* resolve.c (resolve_component): There is no need to resolve
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index 50b4b49..1dde0d3 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -10324,7 +10324,8 @@ resolve_ordinary_assign (gfc_code *code, gfc_namespace *ns)
/* Assign the 'data' of a class object to a derived type. */
if (lhs->ts.type == BT_DERIVED
- && rhs->ts.type == BT_CLASS)
+ && rhs->ts.type == BT_CLASS
+ && rhs->expr_type != EXPR_ARRAY)
gfc_add_data_component (rhs);
bool caf_convert_to_send = flag_coarray == GFC_FCOARRAY_LIB
diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index a357389..59b09fa 100644
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -1580,6 +1580,17 @@ gfc_trans_array_ctor_element (stmtblock_t * pblock, tree desc,
}
}
}
+ else if (GFC_CLASS_TYPE_P (TREE_TYPE (se->expr))
+ && !GFC_CLASS_TYPE_P (gfc_get_element_type (TREE_TYPE (desc))))
+ {
+ /* Assignment of a CLASS array constructor to a derived type array. */
+ if (expr->expr_type == EXPR_FUNCTION)
+ se->expr = gfc_evaluate_now (se->expr, pblock);
+ se->expr = gfc_class_data_get (se->expr);
+ se->expr = build_fold_indirect_ref_loc (input_location, se->expr);
+ se->expr = fold_convert (TREE_TYPE (tmp), se->expr);
+ gfc_add_modify (&se->pre, tmp, se->expr);
+ }
else
{
/* TODO: Should the frontend already have done this conversion? */
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 993dca9..1c92e20 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,10 @@
2017-11-05 Paul Thomas <pault@gcc.gnu.org>
+ PR fortran/78641
+ * gfortran.dg/class_66.f90: New test.
+
+2017-11-05 Paul Thomas <pault@gcc.gnu.org>
+
PR fortran/81447
* gfortran.dg/class_65.f90: New test.
* gfortran.dg/alloc_comp_basics_1.f90: Increase builtin_free
diff --git a/gcc/testsuite/gfortran.dg/class_66.f90 b/gcc/testsuite/gfortran.dg/class_66.f90
new file mode 100644
index 0000000..1843ea7
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/class_66.f90
@@ -0,0 +1,28 @@
+! { dg- do run }
+!
+! Test the fix for PR78641 in which an ICE occured on assignment
+! of a class array constructor to a derived type array.
+!
+! Contributed by Damian Rouson <damian@sourceryinstitute.org>
+!
+ implicit none
+ type foo
+ integer :: i = 99
+ end type
+ type(foo) :: bar(4)
+ class(foo), allocatable :: barfoo
+
+ allocate(barfoo,source = f(11))
+ bar = [f(33), [f(22), barfoo], f(1)]
+ if (any (bar%i .ne. [33, 22, 11, 1])) call abort
+ deallocate (barfoo)
+
+contains
+
+ function f(arg) result(foobar)
+ class(foo), allocatable :: foobar
+ integer :: arg
+ allocate(foobar,source = foo(arg))
+ end function
+
+end program