From: Andre Vehreschild <vehre@gmx.de>
To: GCC-Patches-ML <gcc-patches@gcc.gnu.org>,
GCC-Fortran-ML <fortran@gcc.gnu.org>
Subject: Re: [Patch, Fortran-5, 66035, v2] [5/6 Regression] gfortran ICE segfault
Date: Tue, 21 Jul 2015 09:15:00 -0000 [thread overview]
Message-ID: <20150721100531.27be9b8d@vepi2> (raw)
In-Reply-To: <20150717121707.7f1a9e2f@vepi2>
[-- Attachment #1: Type: text/plain, Size: 2958 bytes --]
Hi all,
as this is a 5/6 regression and the patch now lived for some time in the 6
branch without any complaints, I like to propose the same patch for the
5-branch.
Bootstraps and regtests fine on x86_64-linux-gnu/f21.
Ok for trunk-5 (aka gcc-5-branch)?
Regards,
Andre
On Fri, 17 Jul 2015 12:17:07 +0200
Andre Vehreschild <vehre@gmx.de> wrote:
> Hi Paul,
>
> thanks for the review, commited as r225928.
>
> Regards,
> Andre
>
> On Wed, 15 Jul 2015 13:40:29 +0200
> Paul Richard Thomas <paul.richard.thomas@gmail.com> wrote:
>
> > Dear Andre,
> >
> > I am still in the bizarre situation that the testcase compiles and
> > runs correctly on a clean trunk!
> >
> > That said, the patch applies cleanly and, at very least from my point
> > of view, does not do any harm :-)
> >
> > OK for trunk
> >
> > Thanks for the patch
> >
> > Paul
> >
> > On 11 July 2015 at 14:08, Andre Vehreschild <vehre@gmx.de> wrote:
> > > Hi Mikael,
> > >
> > >> > @@ -7030,7 +7053,8 @@ gfc_trans_subcomponent_assign (tree dest,
> > >> > gfc_component * cm, gfc_expr * expr, gfc_add_expr_to_block (&block,
> > >> > tmp); }
> > >> > else if (init && (cm->attr.allocatable
> > >> > - || (cm->ts.type == BT_CLASS && CLASS_DATA
> > >> > (cm)->attr.allocatable)))
> > >> > + || (cm->ts.type == BT_CLASS && CLASS_DATA (cm)->attr.allocatable
> > >> > + && expr->ts.type != BT_CLASS)))
> > >> > {
> > >> > /* Take care about non-array allocatable components here. The
> > >> > alloc_* routine below is motivated by the alloc_scalar_allocatable_for_
> > >> > @@ -7074,6 +7098,14 @@ gfc_trans_subcomponent_assign (tree dest,
> > >> > gfc_component * cm, gfc_expr * expr, tmp = gfc_build_memcpy_call (tmp,
> > >> > se.expr, size); gfc_add_expr_to_block (&block, tmp);
> > >> > }
> > >> > + else if (cm->ts.type == BT_CLASS && expr->ts.type == BT_CLASS)
> > >> > + {
> > >> > + tmp = gfc_copy_class_to_class (se.expr, dest, integer_one_node,
> > >> > + CLASS_DATA
> > >> > (cm)->attr.unlimited_polymorphic);
> > >> > + gfc_add_expr_to_block (&block, tmp);
> > >> > + gfc_add_modify (&block, gfc_class_vptr_get (dest),
> > >> > + gfc_class_vptr_get (se.expr));
> > >> > + }
> > >> > else
> > >> > gfc_add_modify (&block, tmp,
> > >> > fold_convert (TREE_TYPE (tmp), se.expr));
> > >> But this hunk is canceled by the one before, isn't it?
> > >> I mean, If the condition here is true, the condition before was false?
> > >
> > > You are absolutely right. The second hunk is dead code and removed in the
> > > attached patch. That must have been the first attempt to address the issue
> > > and later on I did not perceive that it was useless. Sorry for that.
> > >
> > > Regards,
> > > Andre
> > > --
> > > Andre Vehreschild * Email: vehre ad gmx dot de
> >
> >
> >
>
>
--
Andre Vehreschild * Email: vehre ad gmx dot de
[-- Attachment #2: pr66035_5_1.clog --]
[-- Type: application/octet-stream, Size: 721 bytes --]
gcc/fortran/ChangeLog:
2015-07-21 Andre Vehreschild <vehre@gcc.gnu.org>
PR fortran/66035
* trans-expr.c (alloc_scalar_allocatable_for_subcomponent_assignment):
Compute the size to allocate for class and derived type objects
correclty.
(gfc_trans_subcomponent_assign): Only allocate memory for a
component when the object to assign is not an allocatable class
object (the memory is already present for allocatable class objects).
Furthermore use copy_class_to_class for assigning the rhs to the
component (may happen for dummy class objects on the rhs).
gcc/testsuite/ChangeLog:
2015-07-21 Andre Vehreschild <vehre@gcc.gnu.org>
PR fortran/66035
* gfortran.dg/structure_constructor_13.f03: New test.
[-- Attachment #3: pr66035_5_1.patch --]
[-- Type: text/x-patch, Size: 2428 bytes --]
diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c
index 88f1af8..e7f9caa 100644
--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -6732,6 +6732,29 @@ alloc_scalar_allocatable_for_subcomponent_assignment (stmtblock_t *block,
TREE_TYPE (tmp), tmp,
fold_convert (TREE_TYPE (tmp), size));
}
+ else if (cm->ts.type == BT_CLASS)
+ {
+ gcc_assert (expr2->ts.type == BT_CLASS || expr2->ts.type == BT_DERIVED);
+ if (expr2->ts.type == BT_DERIVED)
+ {
+ tmp = gfc_get_symbol_decl (expr2->ts.u.derived);
+ size = TYPE_SIZE_UNIT (tmp);
+ }
+ else
+ {
+ gfc_expr *e2vtab;
+ gfc_se se;
+ e2vtab = gfc_find_and_cut_at_last_class_ref (expr2);
+ gfc_add_vptr_component (e2vtab);
+ gfc_add_size_component (e2vtab);
+ gfc_init_se (&se, NULL);
+ gfc_conv_expr (&se, e2vtab);
+ gfc_add_block_to_block (block, &se.pre);
+ size = fold_convert (size_type_node, se.expr);
+ gfc_free_expr (e2vtab);
+ }
+ size_in_bytes = size;
+ }
else
{
/* Otherwise use the length in bytes of the rhs. */
@@ -6859,7 +6882,8 @@ gfc_trans_subcomponent_assign (tree dest, gfc_component * cm, gfc_expr * expr,
gfc_add_expr_to_block (&block, tmp);
}
else if (init && (cm->attr.allocatable
- || (cm->ts.type == BT_CLASS && CLASS_DATA (cm)->attr.allocatable)))
+ || (cm->ts.type == BT_CLASS && CLASS_DATA (cm)->attr.allocatable
+ && expr->ts.type != BT_CLASS)))
{
/* Take care about non-array allocatable components here. The alloc_*
routine below is motivated by the alloc_scalar_allocatable_for_
diff --git a/gcc/testsuite/gfortran.dg/structure_constructor_13.f03 b/gcc/testsuite/gfortran.dg/structure_constructor_13.f03
new file mode 100644
index 0000000..c74e325
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/structure_constructor_13.f03
@@ -0,0 +1,28 @@
+! { dg-do run }
+!
+! Contributed by Melven Roehrig-Zoellner <Melven.Roehrig-Zoellner@DLR.de>
+! PR fortran/66035
+
+program test_pr66035
+ type t
+ end type t
+ type w
+ class(t), allocatable :: c
+ end type w
+
+ type(t) :: o
+
+ call test(o)
+contains
+ subroutine test(o)
+ class(t), intent(inout) :: o
+ type(w), dimension(:), allocatable :: list
+
+ select type (o)
+ class is (t)
+ list = [w(o)] ! This caused an ICE
+ class default
+ call abort()
+ end select
+ end subroutine
+end program
next prev parent reply other threads:[~2015-07-21 8:05 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-08 13:29 [Patch, Fortran, 66035, v1] " Andre Vehreschild
2015-05-10 13:04 ` Mikael Morin
2015-05-11 10:40 ` Andre Vehreschild
2015-07-06 11:55 ` [Patch, Fortran, 66035, v2] " Andre Vehreschild
2015-07-10 16:47 ` Mikael Morin
2015-07-11 12:09 ` Andre Vehreschild
2015-07-15 11:46 ` Paul Richard Thomas
2015-07-17 11:01 ` Andre Vehreschild
2015-07-21 9:15 ` Andre Vehreschild [this message]
2015-07-21 9:16 ` [Patch, Fortran-5, " Paul Richard Thomas
2015-07-21 10:42 ` Andre Vehreschild
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150721100531.27be9b8d@vepi2 \
--to=vehre@gmx.de \
--cc=fortran@gcc.gnu.org \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).