* [Patch, fortran] PR106999 [11/12/13/14 Regression] ICE tree check: expected record_type or union_type or qual_union_type, have function_type in gfc_class_data_get, at fortran/trans-expr.cc:233
@ 2024-03-31 13:01 Paul Richard Thomas
2024-04-01 20:29 ` Harald Anlauf
0 siblings, 1 reply; 3+ messages in thread
From: Paul Richard Thomas @ 2024-03-31 13:01 UTC (permalink / raw)
To: fortran, gcc-patches
[-- Attachment #1.1: Type: text/plain, Size: 925 bytes --]
This regression has a relatively simple fix. The passing of a subroutine
procedure pointer component to a dummy variable was being missed
completely. The error has been added. Conversely, an error was generated
for a procedure pointer variable but no use was being made of the
interface, if one was available. This has been corrected.
OK for mainline and backporting in a couple of weeks?
Paul
Fortran: Add error for subroutine passed to a variable dummy [PR106999]
2024-03-31 Paul Thomas <pault@gcc.gnu.org>
gcc/fortran
PR fortran/106999
*interface.cc (gfc_compare_interfaces): Add error for a
subroutine proc pointer passed to a variable formal.
(compare_parameter): If a procedure pointer is being passed to
a non-procedure formal arg, and there is an an interface, use
gfc_compare_interfaces to check and provide a more useful error
message.
gcc/testsuite/
PR fortran/106999
* gfortran.dg/pr106999.f90: New test.
[-- Attachment #2: submit.diff --]
[-- Type: text/x-patch, Size: 2485 bytes --]
diff --git a/gcc/fortran/interface.cc b/gcc/fortran/interface.cc
index 7b86a338bc1..bf151dae743 100644
--- a/gcc/fortran/interface.cc
+++ b/gcc/fortran/interface.cc
@@ -1789,6 +1789,14 @@ gfc_compare_interfaces (gfc_symbol *s1, gfc_symbol *s2, const char *name2,
return false;
}
+ if (s2->attr.subroutine && s1->attr.flavor == FL_VARIABLE)
+ {
+ if (errmsg != NULL)
+ snprintf (errmsg, err_len, "subroutine proc pointer '%s' passed "
+ "to dummy variable '%s'", name2, s1->name);
+ return false;
+ }
+
/* Do strict checks on all characteristics
(for dummy procedures and procedure pointer assignments). */
if (!generic_flag && strict_flag)
@@ -2425,12 +2433,22 @@ compare_parameter (gfc_symbol *formal, gfc_expr *actual,
{
gfc_symbol *act_sym = actual->symtree->n.sym;
- if (formal->attr.flavor != FL_PROCEDURE)
+ if (formal->attr.flavor != FL_PROCEDURE && !act_sym->ts.interface)
{
if (where)
gfc_error ("Invalid procedure argument at %L", &actual->where);
return false;
}
+ else if (act_sym->ts.interface
+ && !gfc_compare_interfaces (formal, act_sym->ts.interface,
+ act_sym->name, 0, 1, err,
+ sizeof(err),NULL, NULL))
+ {
+ if (where)
+ gfc_error_opt (0, "Interface mismatch in dummy procedure %qs at %L:"
+ " %s", formal->name, &actual->where, err);
+ return false;
+ }
if (!gfc_compare_interfaces (formal, act_sym, act_sym->name, 0, 1, err,
sizeof(err), NULL, NULL))
diff --git a/gcc/testsuite/gfortran.dg/pr106999.f90 b/gcc/testsuite/gfortran.dg/pr106999.f90
new file mode 100644
index 00000000000..b3f1d7741f3
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr106999.f90
@@ -0,0 +1,33 @@
+! { dg-do compile }
+! Test the fix for PR106999
+! Contributed by Gerhard Steinmetz <gscfq@t-online.de>
+program p
+ type t
+ integer :: i
+ procedure(g), pointer :: f
+ end type
+ class(t), allocatable :: y, z
+ procedure(g), pointer :: ff
+ allocate (z)
+ z%i = 42
+ z%f => g
+ ff => g
+ call r(z%f)
+ call s(z%f) ! { dg-error "Interface mismatch in dummy procedure" }
+ call s(ff) ! { dg-error "Interface mismatch in dummy procedure" }
+contains
+ subroutine g(x)
+ class(t) :: x
+ x%i = 84
+ end
+ subroutine r(x)
+ procedure(g) :: x
+ print *, "in r"
+ allocate (y)
+ call x(y)
+ print *, y%i
+ end
+ subroutine s(x)
+ class(*) :: x
+ end subroutine
+end
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Patch, fortran] PR106999 [11/12/13/14 Regression] ICE tree check: expected record_type or union_type or qual_union_type, have function_type in gfc_class_data_get, at fortran/trans-expr.cc:233
2024-03-31 13:01 [Patch, fortran] PR106999 [11/12/13/14 Regression] ICE tree check: expected record_type or union_type or qual_union_type, have function_type in gfc_class_data_get, at fortran/trans-expr.cc:233 Paul Richard Thomas
@ 2024-04-01 20:29 ` Harald Anlauf
2024-04-01 20:29 ` Harald Anlauf
0 siblings, 1 reply; 3+ messages in thread
From: Harald Anlauf @ 2024-04-01 20:29 UTC (permalink / raw)
To: Paul Richard Thomas, fortran, gcc-patches
Hi Paul,
On 3/31/24 15:01, Paul Richard Thomas wrote:
> This regression has a relatively simple fix. The passing of a subroutine
> procedure pointer component to a dummy variable was being missed
> completely. The error has been added. Conversely, an error was generated
> for a procedure pointer variable but no use was being made of the
> interface, if one was available. This has been corrected.
>
> OK for mainline and backporting in a couple of weeks?
this is all OK.
Thanks for the patch!
Harald
> Paul
>
> Fortran: Add error for subroutine passed to a variable dummy [PR106999]
>
> 2024-03-31 Paul Thomas <pault@gcc.gnu.org>
>
> gcc/fortran
> PR fortran/106999
> *interface.cc (gfc_compare_interfaces): Add error for a
> subroutine proc pointer passed to a variable formal.
> (compare_parameter): If a procedure pointer is being passed to
> a non-procedure formal arg, and there is an an interface, use
> gfc_compare_interfaces to check and provide a more useful error
> message.
>
> gcc/testsuite/
> PR fortran/106999
> * gfortran.dg/pr106999.f90: New test.
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Patch, fortran] PR106999 [11/12/13/14 Regression] ICE tree check: expected record_type or union_type or qual_union_type, have function_type in gfc_class_data_get, at fortran/trans-expr.cc:233
2024-04-01 20:29 ` Harald Anlauf
@ 2024-04-01 20:29 ` Harald Anlauf
0 siblings, 0 replies; 3+ messages in thread
From: Harald Anlauf @ 2024-04-01 20:29 UTC (permalink / raw)
To: gcc-patches; +Cc: fortran
Hi Paul,
On 3/31/24 15:01, Paul Richard Thomas wrote:
> This regression has a relatively simple fix. The passing of a subroutine
> procedure pointer component to a dummy variable was being missed
> completely. The error has been added. Conversely, an error was generated
> for a procedure pointer variable but no use was being made of the
> interface, if one was available. This has been corrected.
>
> OK for mainline and backporting in a couple of weeks?
this is all OK.
Thanks for the patch!
Harald
> Paul
>
> Fortran: Add error for subroutine passed to a variable dummy [PR106999]
>
> 2024-03-31 Paul Thomas <pault@gcc.gnu.org>
>
> gcc/fortran
> PR fortran/106999
> *interface.cc (gfc_compare_interfaces): Add error for a
> subroutine proc pointer passed to a variable formal.
> (compare_parameter): If a procedure pointer is being passed to
> a non-procedure formal arg, and there is an an interface, use
> gfc_compare_interfaces to check and provide a more useful error
> message.
>
> gcc/testsuite/
> PR fortran/106999
> * gfortran.dg/pr106999.f90: New test.
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-04-01 20:29 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-31 13:01 [Patch, fortran] PR106999 [11/12/13/14 Regression] ICE tree check: expected record_type or union_type or qual_union_type, have function_type in gfc_class_data_get, at fortran/trans-expr.cc:233 Paul Richard Thomas
2024-04-01 20:29 ` Harald Anlauf
2024-04-01 20:29 ` 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).