public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch, fortran] PR93678 - [11/12/13/14 Regression] ICE with TRANSFER and typebound procedures
@ 2024-04-24 16:26 Paul Richard Thomas
  2024-04-24 19:26 ` Harald Anlauf
  0 siblings, 1 reply; 3+ messages in thread
From: Paul Richard Thomas @ 2024-04-24 16:26 UTC (permalink / raw)
  To: fortran, gcc-patches


[-- Attachment #1.1: Type: text/plain, Size: 569 bytes --]

Hi there,

This regression turned out to be low hanging fruit, although it has taken
four years to reach it :-(

The ChangeLog says it all. OK for mainline and backporting after a suitable
delay?

Paul

Fortran: Fix ICE in gfc_trans_create_temp_array from bad type [PR93678]

2024-04-24  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
PR fortran/93678
* trans-expr.cc (gfc_conv_procedure_call): Use the interface,
where possible, to obtain the type of character procedure
pointers of class entities.

gcc/testsuite/
PR fortran/93678
* gfortran.dg/pr93678.f90: New test.

[-- Attachment #2: submit.diff --]
[-- Type: text/x-patch, Size: 2047 bytes --]

diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 605434f4ddb..072adf3fe77 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -7879,8 +7879,14 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym,
 	{
 	  gcc_assert (se->loop && info);
 
-	  /* Set the type of the array.  */
-	  tmp = gfc_typenode_for_spec (&comp->ts);
+	  /* Set the type of the array. vtable charlens are not always reliable.
+	     Use the interface, if possible.  */
+	  if (comp->ts.type == BT_CHARACTER
+	      && expr->symtree->n.sym->ts.type == BT_CLASS
+	      && comp->ts.interface && comp->ts.interface->result)
+	    tmp = gfc_typenode_for_spec (&comp->ts.interface->result->ts);
+	  else
+	    tmp = gfc_typenode_for_spec (&comp->ts);
 	  gcc_assert (se->ss->dimen == se->loop->dimen);
 
 	  /* Evaluate the bounds of the result, if known.  */
diff --git a/gcc/testsuite/gfortran.dg/pr93678.f90 b/gcc/testsuite/gfortran.dg/pr93678.f90
new file mode 100644
index 00000000000..403bedd0c4f
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr93678.f90
@@ -0,0 +1,32 @@
+! { dg-do compile }
+! Test the fix for PR93678 in which the charlen for the 'unpackbytes'
+! vtable field was incomplete and caused the ICE as indicated.
+! Contributed by Luis Kornblueh  <mail.luis@web.de>
+!
+! The testcase was reduced by various gfortran regulars.
+module mo_a
+  implicit none
+  type t_b
+    integer :: i
+  contains
+    procedure :: unpackbytes => b_unpackbytes
+  end type t_b
+contains
+  function b_unpackbytes (me) result (res)
+    class(t_b), intent(inout) :: me
+    character                 :: res(1)
+    res = char (me%i)
+  end function b_unpackbytes
+  subroutine b_unpackint (me, c)
+    class(t_b), intent(inout) :: me
+    character, intent(in) :: c
+!   print *, b_unpackbytes (me) ! ok
+    if (any (me% unpackbytes () .ne. c)) stop 1 ! ICEd here
+  end subroutine b_unpackint
+end module mo_a
+
+  use mo_a
+  class(t_b), allocatable :: z
+  allocate (z, source = t_b(97))
+  call b_unpackint (z, "a")
+end

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Patch, fortran] PR93678 - [11/12/13/14 Regression] ICE with TRANSFER and typebound procedures
  2024-04-24 16:26 [Patch, fortran] PR93678 - [11/12/13/14 Regression] ICE with TRANSFER and typebound procedures Paul Richard Thomas
@ 2024-04-24 19:26 ` Harald Anlauf
  2024-04-24 19:26   ` Harald Anlauf
  0 siblings, 1 reply; 3+ messages in thread
From: Harald Anlauf @ 2024-04-24 19:26 UTC (permalink / raw)
  To: Paul Richard Thomas, fortran, gcc-patches

Hi Paul,

On 4/24/24 18:26, Paul Richard Thomas wrote:
> Hi there,
>
> This regression turned out to be low hanging fruit, although it has taken
> four years to reach it :-(
>
> The ChangeLog says it all. OK for mainline and backporting after a suitable
> delay?

yes to both.

Thanks for "picking" this fruit!

Harald

> Paul
>
> Fortran: Fix ICE in gfc_trans_create_temp_array from bad type [PR93678]
>
> 2024-04-24  Paul Thomas  <pault@gcc.gnu.org>
>
> gcc/fortran
> PR fortran/93678
> * trans-expr.cc (gfc_conv_procedure_call): Use the interface,
> where possible, to obtain the type of character procedure
> pointers of class entities.
>
> gcc/testsuite/
> PR fortran/93678
> * gfortran.dg/pr93678.f90: New test.
>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Patch, fortran] PR93678 - [11/12/13/14 Regression] ICE with TRANSFER and typebound procedures
  2024-04-24 19:26 ` Harald Anlauf
@ 2024-04-24 19:26   ` Harald Anlauf
  0 siblings, 0 replies; 3+ messages in thread
From: Harald Anlauf @ 2024-04-24 19:26 UTC (permalink / raw)
  To: gcc-patches; +Cc: fortran

Hi Paul,

On 4/24/24 18:26, Paul Richard Thomas wrote:
> Hi there,
> 
> This regression turned out to be low hanging fruit, although it has taken
> four years to reach it :-(
> 
> The ChangeLog says it all. OK for mainline and backporting after a suitable
> delay?

yes to both.

Thanks for "picking" this fruit!

Harald

> Paul
> 
> Fortran: Fix ICE in gfc_trans_create_temp_array from bad type [PR93678]
> 
> 2024-04-24  Paul Thomas  <pault@gcc.gnu.org>
> 
> gcc/fortran
> PR fortran/93678
> * trans-expr.cc (gfc_conv_procedure_call): Use the interface,
> where possible, to obtain the type of character procedure
> pointers of class entities.
> 
> gcc/testsuite/
> PR fortran/93678
> * gfortran.dg/pr93678.f90: New test.
> 



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-04-24 19:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-24 16:26 [Patch, fortran] PR93678 - [11/12/13/14 Regression] ICE with TRANSFER and typebound procedures Paul Richard Thomas
2024-04-24 19:26 ` Harald Anlauf
2024-04-24 19:26   ` Harald Anlauf

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).