public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-8467] Fortran: error recovery in frontend optimization [PR103715]
@ 2024-03-19 19:21 Harald Anlauf
  0 siblings, 0 replies; only message in thread
From: Harald Anlauf @ 2024-03-19 19:21 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:9623e5dd70b0d8334ebe093459721d0d447ce4f2

commit r13-8467-g9623e5dd70b0d8334ebe093459721d0d447ce4f2
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Mon Mar 18 19:36:59 2024 +0100

    Fortran: error recovery in frontend optimization [PR103715]
    
    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)

Diff:
---
 gcc/fortran/frontend-passes.cc         |  3 +++
 gcc/testsuite/gfortran.dg/pr103715.f90 | 12 ++++++++++++
 2 files changed, 15 insertions(+)

diff --git a/gcc/fortran/frontend-passes.cc b/gcc/fortran/frontend-passes.cc
index 85ebca56a69..349d26ec29a 100644
--- a/gcc/fortran/frontend-passes.cc
+++ b/gcc/fortran/frontend-passes.cc
@@ -5807,6 +5807,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
index 00000000000..72c5a31fb21
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr103715.f90
@@ -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" }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-03-19 19:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-19 19:21 [gcc r13-8467] Fortran: error recovery in frontend optimization [PR103715] 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).