public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Proxy ping [PATCH] PR fortran/100136 - ICE, regression, using flag -fcheck=pointer
@ 2022-09-04 20:04 Harald Anlauf
  2022-09-04 20:53 ` Mikael Morin
  0 siblings, 1 reply; 2+ messages in thread
From: Harald Anlauf @ 2022-09-04 20:04 UTC (permalink / raw)
  To: fortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 554 bytes --]

Dear all,

said PR was addressed by Jose in

  https://gcc.gnu.org/pipermail/fortran/2021-April/055949.html

but unfortunately his patch was never reviewed.

IMHO the patch is mostly fine, with one small exception that
it should use POINTER_TYPE_P (TREE_TYPE (tmp)), see PR and
attached adjusted patch.

Regtested on x86_64-pc-linux-gnu.

Since this fixes a 11/12/13 regression on valid code, I'd like
to commit this one on these branches, but would be glad to see
an OK or LGTM from somebody else.  (Jose says he's too busy
currently.)

Thanks,
Harald


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: PR100136.diff --]
[-- Type: text/x-patch, Size: 2617 bytes --]

From 3ce0b852ddd91151a23baf8301b7aea5cc7d7ea0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jos=C3=A9=20Rui=20Faustino=20de=20Sousa?=
 <jrfsousa@gmail.com>
Date: Sun, 4 Sep 2022 21:53:09 +0200
Subject: [PATCH] Fortran: Fix ICE with -fcheck=pointer [PR100136]

gcc/fortran/ChangeLog:

	PR fortran/100136
	* trans-expr.cc (gfc_conv_procedure_call): Add handling of pointer
	expressions.

gcc/testsuite/ChangeLog:

	PR fortran/100136
	* gfortran.dg/PR100136.f90: New test.
---
 gcc/fortran/trans-expr.cc              |  7 ++---
 gcc/testsuite/gfortran.dg/PR100136.f90 | 39 ++++++++++++++++++++++++++
 2 files changed, 42 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/PR100136.f90

diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 13c3e7df45f..7895d034610 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -7220,16 +7220,15 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym,
 	      else
 		goto end_pointer_check;

+	      tmp = parmse.expr;
 	      if (fsym && fsym->ts.type == BT_CLASS)
 		{
-		  tmp = build_fold_indirect_ref_loc (input_location,
-						      parmse.expr);
+		  if (POINTER_TYPE_P (TREE_TYPE (tmp)))
+		    tmp = build_fold_indirect_ref_loc (input_location, tmp);
 		  tmp = gfc_class_data_get (tmp);
 		  if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (tmp)))
 		    tmp = gfc_conv_descriptor_data_get (tmp);
 		}
-	      else
-		tmp = parmse.expr;

 	      /* If the argument is passed by value, we need to strip the
 		 INDIRECT_REF.  */
diff --git a/gcc/testsuite/gfortran.dg/PR100136.f90 b/gcc/testsuite/gfortran.dg/PR100136.f90
new file mode 100644
index 00000000000..922af4aecc3
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/PR100136.f90
@@ -0,0 +1,39 @@
+! { dg-do run }
+! { dg-options "-fcheck=pointer" }
+! { dg-shouldfail "Argument not allocated" }
+! { dg-output "Fortran runtime error: Allocatable actual argument 'c_init2' is not allocated" }
+!
+! Tests fix for PR100136
+!
+! Test cut down from PR58586
+!
+
+module test_pr58586_mod
+  implicit none
+
+  type :: a
+  end type
+
+  type :: c
+     type(a), allocatable :: a
+  end type
+
+contains
+
+  subroutine add_class_c (d)
+    class(c), value :: d
+  end subroutine
+
+  class(c) function c_init2()
+    allocatable :: c_init2
+  end function
+
+end module test_pr58586_mod
+
+program test_pr58586
+  use test_pr58586_mod
+
+  ! This needs to execute, to see whether the segfault at runtime is resolved
+  call add_class_c(c_init2())
+
+end program
--
2.35.3


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

* Re: Proxy ping [PATCH] PR fortran/100136 - ICE, regression, using flag -fcheck=pointer
  2022-09-04 20:04 Proxy ping [PATCH] PR fortran/100136 - ICE, regression, using flag -fcheck=pointer Harald Anlauf
@ 2022-09-04 20:53 ` Mikael Morin
  0 siblings, 0 replies; 2+ messages in thread
From: Mikael Morin @ 2022-09-04 20:53 UTC (permalink / raw)
  To: Harald Anlauf, fortran, gcc-patches

Le 04/09/2022 à 22:04, Harald Anlauf via Fortran a écrit :
> Dear all,
> 
> said PR was addressed by Jose in
> 
>    https://gcc.gnu.org/pipermail/fortran/2021-April/055949.html
> 
> but unfortunately his patch was never reviewed.
> 
> IMHO the patch is mostly fine, with one small exception that
> it should use POINTER_TYPE_P (TREE_TYPE (tmp)), see PR and
> attached adjusted patch.
> 
> Regtested on x86_64-pc-linux-gnu.
> 
> Since this fixes a 11/12/13 regression on valid code, I'd like
> to commit this one on these branches, but would be glad to see
> an OK or LGTM from somebody else.  (Jose says he's too busy
> currently.)
> 
LGTM.

Thanks for taking care of José’s patches.

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

end of thread, other threads:[~2022-09-04 20:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-04 20:04 Proxy ping [PATCH] PR fortran/100136 - ICE, regression, using flag -fcheck=pointer Harald Anlauf
2022-09-04 20:53 ` Mikael Morin

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