aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortkoenig <tkoenig@138bc75d-0d04-0410-961f-82ee72b054a4>2019-03-03 10:09:32 +0000
committertkoenig <tkoenig@138bc75d-0d04-0410-961f-82ee72b054a4>2019-03-03 10:09:32 +0000
commit2d7efbbfcedfe5154111209265e115ad90571d95 (patch)
tree5d41f93e6d7e05493425ab49d51ec24fc1f1cc3a
parent9e076b07f2a70134dde5604d6d34b1bd185287a7 (diff)
2019-03-03 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/89174 Backport from trunk * trans-expr.c (gfc_find_and_cut_at_last_class_ref): Add is_mold to garguments. If we are dealing with a MOLD, call gfc_expr_to_initialize(). * trans-stmt.c (gfc_trans_allocate): For MOLD, pass is_mold=true to gfc_find_and_cut_at_last_class_ref. * trans.h (gfc_find_and_cut_at_last_class_ref): Add optional argument is_mold with default false. 2019-03-03 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/89174 Backport from trunk * gfortran.dg/allocate_with_mold_3.f90: New test. git-svn-id: https://gcc.gnu.org/svn/gcc/branches/gcc-8-branch@269351 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/fortran/ChangeLog12
-rw-r--r--gcc/fortran/trans-expr.c7
-rw-r--r--gcc/fortran/trans-stmt.c2
-rw-r--r--gcc/fortran/trans.h2
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/gfortran.dg/allocate_with_mold_3.f9021
6 files changed, 46 insertions, 4 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index 62d70465edf..c5624af2328 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,5 +1,17 @@
2019-03-03 Thomas Koenig <tkoenig@gcc.gnu.org>
+ PR fortran/89174
+ Backport from trunk
+ * trans-expr.c (gfc_find_and_cut_at_last_class_ref): Add is_mold
+ to garguments. If we are dealing with a MOLD, call
+ gfc_expr_to_initialize().
+ * trans-stmt.c (gfc_trans_allocate): For MOLD, pass is_mold=true
+ to gfc_find_and_cut_at_last_class_ref.
+ * trans.h (gfc_find_and_cut_at_last_class_ref): Add optional
+ argument is_mold with default false.
+
+2019-03-03 Thomas Koenig <tkoenig@gcc.gnu.org>
+
PR fortran/87689
Backport from trunk
* gfortran.dg/lto/20091028-1_0.f90: Add -Wno-lto-type-mismatch to
diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c
index 4ef9d8953d1..b95cf8ddc4f 100644
--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -352,7 +352,7 @@ gfc_vptr_size_get (tree vptr)
of refs following. */
gfc_expr *
-gfc_find_and_cut_at_last_class_ref (gfc_expr *e)
+gfc_find_and_cut_at_last_class_ref (gfc_expr *e, bool is_mold)
{
gfc_expr *base_expr;
gfc_ref *ref, *class_ref, *tail = NULL, *array_ref;
@@ -394,7 +394,10 @@ gfc_find_and_cut_at_last_class_ref (gfc_expr *e)
e->ref = NULL;
}
- base_expr = gfc_copy_expr (e);
+ if (is_mold)
+ base_expr = gfc_expr_to_initialize (e);
+ else
+ base_expr = gfc_copy_expr (e);
/* Restore the original tail expression. */
if (class_ref)
diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c
index 5b2d4e8279d..eb976c70a3a 100644
--- a/gcc/fortran/trans-stmt.c
+++ b/gcc/fortran/trans-stmt.c
@@ -6606,7 +6606,7 @@ gfc_trans_allocate (gfc_code * code)
/* Use class_init_assign to initialize expr. */
gfc_code *ini;
ini = gfc_get_code (EXEC_INIT_ASSIGN);
- ini->expr1 = gfc_find_and_cut_at_last_class_ref (expr);
+ ini->expr1 = gfc_find_and_cut_at_last_class_ref (expr, true);
tmp = gfc_trans_class_init_assign (ini);
gfc_free_statements (ini);
gfc_add_expr_to_block (&block, tmp);
diff --git a/gcc/fortran/trans.h b/gcc/fortran/trans.h
index 5a2c2352a77..103ad6787ad 100644
--- a/gcc/fortran/trans.h
+++ b/gcc/fortran/trans.h
@@ -412,7 +412,7 @@ tree gfc_class_data_get (tree);
tree gfc_class_vptr_get (tree);
tree gfc_class_len_get (tree);
tree gfc_class_len_or_zero_get (tree);
-gfc_expr * gfc_find_and_cut_at_last_class_ref (gfc_expr *);
+gfc_expr * gfc_find_and_cut_at_last_class_ref (gfc_expr *, bool is_mold = false);
/* Get an accessor to the class' vtab's * field, when a class handle is
available. */
tree gfc_class_vtab_hash_get (tree);
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index cb7ac79afdb..f7b780a3ce4 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,11 @@
2019-03-03 Thomas Koenig <tkoenig@gcc.gnu.org>
+ PR fortran/89174
+ Backport from trunk
+ * gfortran.dg/allocate_with_mold_3.f90: New test.
+
+2019-03-03 Thomas Koenig <tkoenig@gcc.gnu.org>
+
PR fortran/87689
Backport from trunk
* gfortran.dg/lto/20091028-1_0.f90: Add -Wno-lto-type-mismatch to
diff --git a/gcc/testsuite/gfortran.dg/allocate_with_mold_3.f90 b/gcc/testsuite/gfortran.dg/allocate_with_mold_3.f90
new file mode 100644
index 00000000000..797edbe7d49
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/allocate_with_mold_3.f90
@@ -0,0 +1,21 @@
+! { dg-do run }
+! PR fortran/89174 - this used to segfault on execution.
+! Test case by Neil Carlson.
+module mod
+ type :: array_data
+ class(*), allocatable :: mold
+ contains
+ procedure :: push
+ end type
+contains
+ subroutine push(this, value)
+ class(array_data), intent(inout) :: this
+ class(*), intent(in) :: value
+ allocate(this%mold, mold=value) ! <== SEGFAULTS HERE
+ end subroutine
+end module
+
+use mod
+type(array_data) :: foo
+call foo%push(42)
+end