* [Patch, fortran] PR66679 - [OOP] ICE with class(*) and transfer
@ 2018-07-05 7:52 Paul Richard Thomas
2018-07-23 15:51 ` Paul Richard Thomas
0 siblings, 1 reply; 4+ messages in thread
From: Paul Richard Thomas @ 2018-07-05 7:52 UTC (permalink / raw)
To: fortran, gcc-patches; +Cc: polajnar.miha, Janus Weil
[-- Attachment #1: Type: text/plain, Size: 515 bytes --]
The comment in the patch says it all.
Bootstrapped and regtested on FC28/x86_64 - OK for trunk?
Paul
2018-07-05 Paul Thomas <pault@gcc.gnu.org>
PR fortran/66679
* trans-intrinsic.c (gfc_conv_intrinsic_transfer): Class array
elements are returned as references to the data element. Get
the class expression by stripping back the references. Use this
for the element size.
2018-07-05 Paul Thomas <pault@gcc.gnu.org>
PR fortran/66679
* gfortran.dg/transfer_class_3.f90: New test.
[-- Attachment #2: submit.diff --]
[-- Type: text/x-patch, Size: 3098 bytes --]
Index: gcc/fortran/trans-intrinsic.c
===================================================================
*** gcc/fortran/trans-intrinsic.c (revision 262299)
--- gcc/fortran/trans-intrinsic.c (working copy)
*************** gfc_conv_intrinsic_transfer (gfc_se * se
*** 7346,7358 ****
tree upper;
tree lower;
tree stmt;
gfc_actual_arglist *arg;
gfc_se argse;
gfc_array_info *info;
stmtblock_t block;
int n;
bool scalar_mold;
! gfc_expr *source_expr, *mold_expr;
info = NULL;
if (se->loop)
--- 7346,7359 ----
tree upper;
tree lower;
tree stmt;
+ tree class_ref = NULL_TREE;
gfc_actual_arglist *arg;
gfc_se argse;
gfc_array_info *info;
stmtblock_t block;
int n;
bool scalar_mold;
! gfc_expr *source_expr, *mold_expr, *class_expr;
info = NULL;
if (se->loop)
*************** gfc_conv_intrinsic_transfer (gfc_se * se
*** 7383,7389 ****
{
gfc_conv_expr_reference (&argse, arg->expr);
if (arg->expr->ts.type == BT_CLASS)
! source = gfc_class_data_get (argse.expr);
else
source = argse.expr;
--- 7384,7407 ----
{
gfc_conv_expr_reference (&argse, arg->expr);
if (arg->expr->ts.type == BT_CLASS)
! {
! tmp = build_fold_indirect_ref_loc (input_location, argse.expr);
! if (GFC_CLASS_TYPE_P (TREE_TYPE (tmp)))
! source = gfc_class_data_get (tmp);
! else
! {
! /* Array elements are evaluated as a reference to the data.
! To obtain the vptr for the element size, the argument
! expression must be stripped to the class reference and
! re-evaluated. The pre and post blocks are not needed. */
! gcc_assert (arg->expr->expr_type == EXPR_VARIABLE);
! source = argse.expr;
! class_expr = gfc_find_and_cut_at_last_class_ref (arg->expr);
! gfc_init_se (&argse, NULL);
! gfc_conv_expr (&argse, class_expr);
! class_ref = argse.expr;
! }
! }
else
source = argse.expr;
*************** gfc_conv_intrinsic_transfer (gfc_se * se
*** 7395,7400 ****
--- 7413,7421 ----
argse.string_length);
break;
case BT_CLASS:
+ if (class_ref != NULL_TREE)
+ tmp = gfc_class_vtab_size_get (class_ref);
+ else
tmp = gfc_class_vtab_size_get (argse.expr);
break;
default:
Index: gcc/testsuite/gfortran.dg/transfer_class_3.f90
===================================================================
*** gcc/testsuite/gfortran.dg/transfer_class_3.f90 (nonexistent)
--- gcc/testsuite/gfortran.dg/transfer_class_3.f90 (working copy)
***************
*** 0 ****
--- 1,18 ----
+ ! { dg-do run }
+ !
+ ! Test the fix for PR66679.
+ !
+ ! Contributed by Miha Polajnar <polajnar.miha@gmail.com>
+ !
+ program main
+ implicit none
+ class(*), allocatable :: vec(:)
+ integer :: var, ans(2)
+ allocate(vec(2),source=[1_4, 2_4])
+
+ ! This worked correctly.
+ if (any (transfer(vec,[var],2) .ne. [1_4, 2_4])) stop 1
+
+ ! This caused an ICE.
+ if (any ([transfer(vec(1),[var]), transfer(vec(2),[var])] .ne. [1_4, 2_4])) stop 2
+ end program main
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Patch, fortran] PR66679 - [OOP] ICE with class(*) and transfer
2018-07-05 7:52 [Patch, fortran] PR66679 - [OOP] ICE with class(*) and transfer Paul Richard Thomas
@ 2018-07-23 15:51 ` Paul Richard Thomas
2018-07-23 20:20 ` Janus Weil
0 siblings, 1 reply; 4+ messages in thread
From: Paul Richard Thomas @ 2018-07-23 15:51 UTC (permalink / raw)
To: fortran, gcc-patches; +Cc: Miha Polajnar, Janus Weil
Ping!
On Thu, 5 Jul 2018 at 08:51, Paul Richard Thomas
<paul.richard.thomas@gmail.com> wrote:
>
> The comment in the patch says it all.
>
> Bootstrapped and regtested on FC28/x86_64 - OK for trunk?
>
> Paul
>
> 2018-07-05 Paul Thomas <pault@gcc.gnu.org>
>
> PR fortran/66679
> * trans-intrinsic.c (gfc_conv_intrinsic_transfer): Class array
> elements are returned as references to the data element. Get
> the class expression by stripping back the references. Use this
> for the element size.
>
> 2018-07-05 Paul Thomas <pault@gcc.gnu.org>
>
> PR fortran/66679
> * gfortran.dg/transfer_class_3.f90: New test.
--
"If you can't explain it simply, you don't understand it well enough"
- Albert Einstein
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Patch, fortran] PR66679 - [OOP] ICE with class(*) and transfer
2018-07-23 15:51 ` Paul Richard Thomas
@ 2018-07-23 20:20 ` Janus Weil
2018-07-24 7:47 ` Paul Richard Thomas
0 siblings, 1 reply; 4+ messages in thread
From: Janus Weil @ 2018-07-23 20:20 UTC (permalink / raw)
To: Paul Richard Thomas; +Cc: fortran, gcc-patches, Miha Polajnar
Hi Paul,
2018-07-23 17:51 GMT+02:00 Paul Richard Thomas <paul.richard.thomas@gmail.com>:
> Ping!
> On Thu, 5 Jul 2018 at 08:51, Paul Richard Thomas
> <paul.richard.thomas@gmail.com> wrote:
>>
>> The comment in the patch says it all.
>>
>> Bootstrapped and regtested on FC28/x86_64 - OK for trunk?
I don't see anything wrong with the patch, so as far as I'm concerned
it's ok for trunk.
Just one minor style-wise suggestion: I'd move the declaration of the
'class_expr' into the else branch where it's used (in order to have it
as locally as possible).
Thanks for the patch,
Janus
>> 2018-07-05 Paul Thomas <pault@gcc.gnu.org>
>>
>> PR fortran/66679
>> * trans-intrinsic.c (gfc_conv_intrinsic_transfer): Class array
>> elements are returned as references to the data element. Get
>> the class expression by stripping back the references. Use this
>> for the element size.
>>
>> 2018-07-05 Paul Thomas <pault@gcc.gnu.org>
>>
>> PR fortran/66679
>> * gfortran.dg/transfer_class_3.f90: New test.
>
>
>
> --
> "If you can't explain it simply, you don't understand it well enough"
> - Albert Einstein
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Patch, fortran] PR66679 - [OOP] ICE with class(*) and transfer
2018-07-23 20:20 ` Janus Weil
@ 2018-07-24 7:47 ` Paul Richard Thomas
0 siblings, 0 replies; 4+ messages in thread
From: Paul Richard Thomas @ 2018-07-24 7:47 UTC (permalink / raw)
To: Janus Weil; +Cc: fortran, Miha Polajnar
Hi Janus,
Thanks for that. I will commit this evening.
I put the declaration at function scope because I was anticipating
having to use it elsewhere :-) I will make the change that you
propose.
Cheers
Paul
On Mon, 23 Jul 2018 at 21:20, Janus Weil <janus@gcc.gnu.org> wrote:
>
> Hi Paul,
>
> 2018-07-23 17:51 GMT+02:00 Paul Richard Thomas <paul.richard.thomas@gmail.com>:
> > Ping!
> > On Thu, 5 Jul 2018 at 08:51, Paul Richard Thomas
> > <paul.richard.thomas@gmail.com> wrote:
> >>
> >> The comment in the patch says it all.
> >>
> >> Bootstrapped and regtested on FC28/x86_64 - OK for trunk?
>
> I don't see anything wrong with the patch, so as far as I'm concerned
> it's ok for trunk.
>
> Just one minor style-wise suggestion: I'd move the declaration of the
> 'class_expr' into the else branch where it's used (in order to have it
> as locally as possible).
>
> Thanks for the patch,
> Janus
>
>
>
> >> 2018-07-05 Paul Thomas <pault@gcc.gnu.org>
> >>
> >> PR fortran/66679
> >> * trans-intrinsic.c (gfc_conv_intrinsic_transfer): Class array
> >> elements are returned as references to the data element. Get
> >> the class expression by stripping back the references. Use this
> >> for the element size.
> >>
> >> 2018-07-05 Paul Thomas <pault@gcc.gnu.org>
> >>
> >> PR fortran/66679
> >> * gfortran.dg/transfer_class_3.f90: New test.
> >
> >
> >
> > --
> > "If you can't explain it simply, you don't understand it well enough"
> > - Albert Einstein
--
"If you can't explain it simply, you don't understand it well enough"
- Albert Einstein
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-07-24 7:47 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-05 7:52 [Patch, fortran] PR66679 - [OOP] ICE with class(*) and transfer Paul Richard Thomas
2018-07-23 15:51 ` Paul Richard Thomas
2018-07-23 20:20 ` Janus Weil
2018-07-24 7:47 ` Paul Richard Thomas
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).