[PATCH, Fortran] Regression Fix PR121743
Jerry D <[email protected]>
| Newsgroups | gmane.comp.gcc.patches,gmane.comp.gcc.fortran |
|---|---|
| Message-ID | <[email protected]> |
The following regression tested on x86_64. The oneliner was provided by the reporter. Jakub gave the reduced test case in the PR. OK to commit to mailine and then will backport to 15 in a few days. Best regards, Jerry commit 49ca17dea6de4e01b068a678b36f1c7caa578cc2 Author: Jerry DeLisle <[email protected]> Date: Thu Mar 12 10:23:47 2026 -0700 Fortran: [PR121743] ICE in build_function_decl. PR fortran/121743 gcc/fortran/ChangeLog: * trans-decl.cc (build_function_decl): Adjust the gcc_assert condition to avoid the ICE. gcc/testsuite/ChangeLog: * gfortran.dg/pr121743.f90: New test. Co-Authored-By: Gilles Gouaillardet <[email protected]> diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc index 8649d0fbc81..0080e83fc36 100644 --- a/gcc/fortran/trans-decl.cc +++ b/gcc/fortran/trans-decl.cc @@ -2550,6 +2550,8 @@ build_function_decl (gfc_symbol * sym, bool global) /* Allow only one nesting level. Allow public declarations. */ gcc_assert (current_function_decl == NULL_TREE || DECL_FILE_SCOPE_P (current_function_decl) + || (TREE_CODE (DECL_CONTEXT (current_function_decl)) + == FUNCTION_DECL) || (TREE_CODE (DECL_CONTEXT (current_function_decl)) == NAMESPACE_DECL)); diff --git a/gcc/testsuite/gfortran.dg/pr121743.f90 b/gcc/testsuite/gfortran.dg/pr121743.f90 new file mode 100644 index 00000000000..29a1cdec2ac --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr121743.f90 @@ -0,0 +1,11 @@ +! PR fortran/121743 +! { dg-do compile } +! { dg-options "-fcoarray=lib" } + +program pr121743 +end program pr121743 +subroutine foo () + integer, allocatable, dimension(:), codimension[:] :: s + integer :: i + i = s(1)[1] +end