]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: error recovery in frontend optimization [PR103715]
authorHarald Anlauf <anlauf@gmx.de>
Mon, 18 Mar 2024 18:36:59 +0000 (19:36 +0100)
committerHarald Anlauf <anlauf@gmx.de>
Wed, 20 Mar 2024 20:49:26 +0000 (21:49 +0100)
gcc/fortran/ChangeLog:

PR fortran/103715
* frontend-passes.cc (check_externals_expr): Prevent invalid read
in case of mismatch of external subroutine with function.

gcc/testsuite/ChangeLog:

PR fortran/103715
* gfortran.dg/pr103715.f90: New test.

(cherry picked from commit 3be2b8f475f22c531d6cef1b041c0573b3ea5133)

gcc/fortran/frontend-passes.cc
gcc/testsuite/gfortran.dg/pr103715.f90 [new file with mode: 0644]

index 53567307cec272831975876bb54534dd76a426ec..de8cb5a2204c1f52620cc41df43b3898797b7ae6 100644 (file)
@@ -5794,6 +5794,9 @@ check_externals_expr (gfc_expr **ep, int *walk_subtrees ATTRIBUTE_UNUSED,
   if (e->expr_type != EXPR_FUNCTION)
     return 0;
 
+  if (e->symtree && e->symtree->n.sym->attr.subroutine)
+    return 0;
+
   sym = e->value.function.esym;
   if (sym == NULL)
     return 0;
diff --git a/gcc/testsuite/gfortran.dg/pr103715.f90 b/gcc/testsuite/gfortran.dg/pr103715.f90
new file mode 100644 (file)
index 0000000..72c5a31
--- /dev/null
@@ -0,0 +1,12 @@
+! { dg-do compile }
+! PR fortran/103715 - ICE in gfc_find_gsymbol
+!
+! valgrind did report an invalid read in check_externals_procedure
+
+program p
+  select type (y => g()) ! { dg-error "Selector shall be polymorphic" }
+  end select
+  call g()
+end
+
+! { dg-prune-output "already being used as a FUNCTION" }