Here's an almost obvious one on a testcase by Gerhard, which triggered an internal error since the buffer size was checked. By looking at the format string and arguments used in name mangling, I decided to stick with the simple approach of using a fixed size buffer, but larger.
Regtested on x86_64-pc-linux-gnu, along with the fixes for similar bugs (PRs 95687, 95689). OK for trunk? Backport if suitable? Thanks, Harald PR fortran/95688 - ICE in gfc_get_string, at fortran/iresolve.c:70 With submodules, name mangling of character pointer declarations produces long internal symbols that overflowed a static internal buffer. Adjust the buffer size. gcc/fortran/ PR fortran/95688 * iresolve.c (gfc_get_string): Enlarge static buffer size.
diff --git a/gcc/fortran/iresolve.c b/gcc/fortran/iresolve.c index df4f2265c58..aa9bb328a0f 100644 --- a/gcc/fortran/iresolve.c +++ b/gcc/fortran/iresolve.c @@ -47,8 +47,8 @@ along with GCC; see the file COPYING3. If not see const char * gfc_get_string (const char *format, ...) { - /* Provide sufficient space to hold "_F.caf_token__symbol_MOD_symbol". */ - char temp_name[14 + GFC_MAX_SYMBOL_LEN + 5 + GFC_MAX_SYMBOL_LEN + 1]; + /* Provide sufficient space to hold "_F.symbol.symbol_MOD_symbol". */ + char temp_name[4 + 2*GFC_MAX_SYMBOL_LEN + 5 + GFC_MAX_SYMBOL_LEN + 1]; const char *str; va_list ap; tree ident; diff --git a/gcc/testsuite/gfortran.dg/pr95688.f90 b/gcc/testsuite/gfortran.dg/pr95688.f90 new file mode 100644 index 00000000000..ce8fd3e9890 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr95688.f90 @@ -0,0 +1,15 @@ +! { dg-do compile } +! { dg-options "-fsecond-underscore" } +! PR fortran/95688 - ICE in gfc_get_string, at fortran/iresolve.c:70 + +module m2345678901234567890123456789012345678901234567890123456789_123 + interface + module subroutine s2345678901234567890123456789012345678901234567890123456789_123 + end + end interface +end +submodule(m2345678901234567890123456789012345678901234567890123456789_123) & + n2345678901234567890123456789012345678901234567890123456789_123 + character(:), pointer :: & + x2345678901234567890123456789012345678901234567890123456789_123 => null() +end