PR fortran/95089 - ICE in gfc_get_derived_type, at fortran/trans-types.c:2843
authorHarald Anlauf <anlauf@gmx.de>
Tue, 26 May 2020 19:19:19 +0000 (21:19 +0200)
committerHarald Anlauf <anlauf@gmx.de>
Tue, 26 May 2020 19:19:19 +0000 (21:19 +0200)
For long module name, derive type and component name, the
generated name-mangled symbol did not fit into a buffer when
coarrays were enabled.  Provide sufficiently large temporary.

2020-05-26  Harald Anlauf  <anlauf@gmx.de>

gcc/fortran/
PR fortran/95089
* trans-types.c (gfc_get_derived_type): Enlarge temporary to hold
mangled name "_caf_symbol".

gcc/testsuite/
PR fortran/95089
* gfortran.dg/pr95089.f90: New test.

gcc/fortran/trans-types.c
gcc/testsuite/gfortran.dg/pr95089.f90 [new file with mode: 0644]

index b7712dc74d167d1e35506c44fb0fdfb67ef1286e..998448125056f8ead373f603150086341c70dcbf 100644 (file)
@@ -2836,9 +2836,10 @@ copy_derived_types:
          && (c->attr.allocatable || c->attr.pointer)
          && !derived->attr.is_class)
        {
-         char caf_name[GFC_MAX_SYMBOL_LEN];
+         /* Provide sufficient space to hold "_caf_symbol".  */
+         char caf_name[GFC_MAX_SYMBOL_LEN + 6];
          gfc_component *token;
-         snprintf (caf_name, GFC_MAX_SYMBOL_LEN, "_caf_%s", c->name);
+         snprintf (caf_name, sizeof (caf_name), "_caf_%s", c->name);
          token = gfc_find_component (derived, caf_name, true, true, NULL);
          gcc_assert (token);
          c->caf_token = token->backend_decl;
diff --git a/gcc/testsuite/gfortran.dg/pr95089.f90 b/gcc/testsuite/gfortran.dg/pr95089.f90
new file mode 100644 (file)
index 0000000..1cd20f0
--- /dev/null
@@ -0,0 +1,11 @@
+! { dg-do compile }
+! { dg-options "-fcoarray=lib" }
+!
+! PR fortran/95089 - ICE in gfc_get_derived_type, at fortran/trans-types.c:2843
+
+module m23456789012345678901234567890123456789012345678901234567890123
+  type t23456789012345678901234567890123456789012345678901234567890123
+     type (t23456789012345678901234567890123456789012345678901234567890123), &
+          pointer :: z23456789012345678901234567890123456789012345678901234567890123
+  end type t23456789012345678901234567890123456789012345678901234567890123
+end