diff mbox series

PR fortran/78746 - invalid access after error recovery

Message ID trinity-e901471d-de9f-474f-9ea3-1fd57856acb6-1609879289302@3c-app-gmx-bap22
State New
Headers show
Series PR fortran/78746 - invalid access after error recovery | expand

Commit Message

Harald Anlauf Jan. 5, 2021, 8:41 p.m. UTC
Dear all,

the PR contains a lengthy discussion of several testcases, some which were
considered invalid and thus removed from the testsuite (charlen_03.f90,
charlen_10.f90), charlen_15.f90 was resolved elsewhere, so that only
class_61.f90 was left with an invalid access after error recovery with
an instrumented compiler.

I could reproduce the issue triggered by class_61.f90 using valgrind,
and found that the attached trivial, almost obvious patch solves it.
It even regtests cleanly on x86_64-pc-linux-gnu.

OK for master?  Open branches where testcase class_61.f90 exists?

Thanks,
Harald


PR fortran/78746 - invalid access after error recovery

The error recovery after an invalid reference to an undefined CLASS
during a TYPE declaration lead to an invalid access.  Add a check.

gcc/fortran/ChangeLog:

	* resolve.c (resolve_component): Add check for valid CLASS
	reference before trying to access CLASS data.

Comments

Thomas Koenig Jan. 6, 2021, 3:50 p.m. UTC | #1
Hi Harald,

> OK for master?  Open branches where testcase class_61.f90 exists?

OK for both (as you wrote, this one is really obvious).

Best regards

	Thomas
diff mbox series

Patch

diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index fa6f756d285..891db391907 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -14384,7 +14396,7 @@  resolve_component (gfc_component *c, gfc_symbol *sym)
   /* F2008, C448.  */
   if (c->ts.type == BT_CLASS)
     {
-      if (CLASS_DATA (c))
+      if (c->attr.class_ok && CLASS_DATA (c))
 	{
 	  attr = &(CLASS_DATA (c)->attr);