Hi all, attached patch fixes a segfault when allocating a coarray of a type that has allocatable components. Before the patch the compiler tried to ref the component to nullify from the coarray's base address and not from its .data component. The proposed patch fixes this by preventing the nullify of the components in the array_allocate() for coarrays, because the components are nullified again afterwards by copying a fully nullified copy of the type to the coarray's data component.
There albeit is an alternative to this patch: trans-array.c: 5556+ - tmp = gfc_nullify_alloc_comp (expr->ts.u.derived, se->expr, + tmp = gfc_nullify_alloc_comp (expr->ts.u.derived, coarray ? + pointer : se->expr, ref->u.ar.as->rank); The above adds a second nullify to the generated code before the one done the object copy mentioned above. Because I am unsure which patch is best, I propose both. I do favor of course the one without the duplicate nullify as attached. Bootstrapped and regtested ok on x86_64-linux-gnu/F23. Ok for trunk? The patch also applies (with a small delta) to gcc-5 w/o any regressions. Ok for gcc-5-branch? Regards, Andre -- Andre Vehreschild * Email: vehre ad gmx dot de
pr65795_1.clog
Description: Binary data
diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c index 649b80f..825dfb8 100644 --- a/gcc/fortran/trans-array.c +++ b/gcc/fortran/trans-array.c @@ -5550,8 +5550,8 @@ gfc_array_allocate (gfc_se * se, gfc_expr * expr, tree status, tree errmsg, else gfc_add_expr_to_block (&se->pre, set_descriptor); - if ((expr->ts.type == BT_DERIVED) - && expr->ts.u.derived->attr.alloc_comp) + if (expr->ts.type == BT_DERIVED && expr->ts.u.derived->attr.alloc_comp + && !coarray) { tmp = gfc_nullify_alloc_comp (expr->ts.u.derived, se->expr, ref->u.ar.as->rank); diff --git a/gcc/testsuite/gfortran.dg/coarray_allocate_6.f08 b/gcc/testsuite/gfortran.dg/coarray_allocate_6.f08 new file mode 100644 index 0000000..8394c30 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/coarray_allocate_6.f08 @@ -0,0 +1,27 @@ +! { dg-do run } +! { dg-options "-fcoarray=single" } + +! Contributed by Tobias Burnus <bur...@gcc.gnu.org> +! Test fix for pr65795. + +implicit none + +type t2 + integer, allocatable :: x +end type t2 + +type t3 + type(t2), allocatable :: caf[:] +end type t3 + +!type(t3), save, target :: c, d +type(t3), target :: c, d +integer :: stat + +allocate(c%caf[*], stat=stat) +end + +! Besides checking that the executable does not crash anymore, check +! that the cause has been remove. +! { dg-final { scan-tree-dump-not "c.caf.x = 0B" "original" } } +