diff mbox series

[committed] PR fortran/102311 - fix ICE during error recovery checking entry characteristics

Message ID trinity-1ba6b01d-fcc2-4f4b-9044-62474b7f170c-1631644486735@3c-app-gmx-bap28
State Committed
Headers show
Series [committed] PR fortran/102311 - fix ICE during error recovery checking entry characteristics | expand

Commit Message

Harald Anlauf Sept. 14, 2021, 6:34 p.m. UTC
Committed as obvious as r12-3533.

The fix to PR87737 did work for the given testcase, but could lead
to a bad internal compiler state for a variation of the testcase.
(Found by Gerhard...)

The solution was to not return too early after emitting the error
message but going through a 'cleanup' instead.

Regtested on x86_64-pc-linux-gnu, and checked the testcase also
with valgrind (to be on the safer side).

Thanks,
Harald


Fortran - fix ICE during error recovery checking entry characteristics

gcc/fortran/ChangeLog:

	PR fortran/102311
	* resolve.c (resolve_entries): Attempt to recover cleanly after
	rejecting mismatched function entries.

gcc/testsuite/ChangeLog:

	PR fortran/102311
	* gfortran.dg/entry_25.f90: New test.
diff mbox series

Patch

diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index 8e5ed1c032c..30b96b2f597 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -811,7 +811,7 @@  resolve_entries (gfc_namespace *ns)
 	      gfc_error ("Function %s at %L has entry %s with mismatched "
 			 "characteristics", ns->entries->sym->name,
 			 &ns->entries->sym->declared_at, el->sym->name);
-	      return;
+	      goto cleanup;
 	    }
 	  else if (ts->type == BT_CHARACTER && ts->u.cl && fts->u.cl
 		   && (((ts->u.cl->length && !fts->u.cl->length)
@@ -917,6 +917,8 @@  resolve_entries (gfc_namespace *ns)
 	    }
 	}
     }
+
+cleanup:
   proc->attr.access = ACCESS_PRIVATE;
   proc->attr.entry_master = 1;

diff --git a/gcc/testsuite/gfortran.dg/entry_25.f90 b/gcc/testsuite/gfortran.dg/entry_25.f90
new file mode 100644
index 00000000000..518560aa198
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/entry_25.f90
@@ -0,0 +1,13 @@ 
+! { dg-do compile }
+! PR fortran/102311 - ICE during error recovery checking entry characteristics
+
+module m
+contains
+  function f() ! { dg-error "mismatched characteristics" }
+    character(:), allocatable :: f
+    character(1)              :: g
+    f = 'f'
+  entry g()
+    g = 'g'
+  end
+end