[gcc r17-2629] fortran: [PR78718] ICE in gfc_get_symbol_decl, at fortran/trans-decl.c

Jerry DeLisle via Gcc-cvs <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:b2c44478da133c8ac81bf3fdb67c1fdd8e38d61a

commit r17-2629-gb2c44478da133c8ac81bf3fdb67c1fdd8e38d61a
Author: Jerry DeLisle <[email protected]>
Date:   Fri Jul 10 21:47:59 2026 -0700

    fortran: [PR78718] ICE in gfc_get_symbol_decl, at fortran/trans-decl.c
    
            PR fortran/78718
    
    gcc/fortran/ChangeLog:
    
            * resolve.cc (was_declared): Recognize the RESULT attribute so a
            function's result variable is not mistaken for a host-associated
            symbol of the same name.
    
    gcc/testsuite/ChangeLog:
    
            * gfortran.dg/func_result_8.f90: New test.

Diff:
---
 gcc/fortran/resolve.cc                      |  2 +-
 gcc/testsuite/gfortran.dg/func_result_8.f90 | 17 +++++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index 5f3edb37aa4b..036da9a939ee 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -1655,7 +1655,7 @@ was_declared (gfc_symbol *sym)
   if (a.allocatable || a.dimension || a.dummy || a.external || a.intrinsic
       || a.optional || a.pointer || a.save || a.target || a.volatile_
       || a.value || a.access != ACCESS_UNKNOWN || a.intent != INTENT_UNKNOWN
-      || a.asynchronous || a.codimension || a.subroutine)
+      || a.asynchronous || a.codimension || a.subroutine || a.result)
     return 1;
 
   return 0;
diff --git a/gcc/testsuite/gfortran.dg/func_result_8.f90 b/gcc/testsuite/gfortran.dg/func_result_8.f90
new file mode 100644
index 000000000000..bbe0b25395cd
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/func_result_8.f90
@@ -0,0 +1,17 @@
+! { dg-do run }
+!
+! PR fortran/78718
+program p
+   integer :: n, m
+   n = 1
+   if (f() /= 1) stop 1
+contains
+   function f() result(m)
+      call s(n, m)
+   end function
+end program
+
+subroutine s(a, b)
+   integer :: a, b
+   b = a
+end subroutine
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.