public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] fortran: Restore current interface info on error [PR111291]
@ 2024-01-19 17:47 Mikael Morin
  2024-01-19 18:58 ` Steve Kargl
  0 siblings, 1 reply; 2+ messages in thread
From: Mikael Morin @ 2024-01-19 17:47 UTC (permalink / raw)
  To: fortran, gcc-patches

Hello,

I tested this on x86_64-pc-linux-gnu without regression.
There is no new test, as the problem is visible on an 
existing test with valgrind or an asan-instrumented compiler.
OK for master?

-- >8 --

This change is a followup to the fix for PR48776 (namely
r14-3572-gd58150452976c4ca65ddc811fac78ef956fa96b0 AKA
fortran: Restore interface to its previous state on error [PR48776]),
which cleaned up new changes from interfaces upon error.

Unfortunately, there is one case in that fix that is mishandled, visible
on unexpected_interface.f90 with valgrind or an asan-instrumented gfortran.
when an interface statement is found while parsing an interface body (which
is invalid), the current interface is replaced by the one from the new
statement, and as parsing continues, new procedures are added
to the new interface, which has been rejected and freed, instead of the
original one.

This change restores the current interface pointer to its previous value
on each rejected statement.

	PR fortran/48776
	PR fortran/111291

gcc/fortran/ChangeLog:

	* parse.cc: Restore current interface to its previous value on error.
---
 gcc/fortran/parse.cc | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/fortran/parse.cc b/gcc/fortran/parse.cc
index abd3a424f38..51e89e10e2d 100644
--- a/gcc/fortran/parse.cc
+++ b/gcc/fortran/parse.cc
@@ -4033,6 +4033,7 @@ loop:
     default:
       gfc_error ("Unexpected %s statement in INTERFACE block at %C",
 		 gfc_ascii_statement (st));
+      current_interface = save;
       reject_statement ();
       gfc_free_namespace (gfc_current_ns);
       goto loop;
-- 
2.43.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] fortran: Restore current interface info on error [PR111291]
  2024-01-19 17:47 [PATCH] fortran: Restore current interface info on error [PR111291] Mikael Morin
@ 2024-01-19 18:58 ` Steve Kargl
  0 siblings, 0 replies; 2+ messages in thread
From: Steve Kargl @ 2024-01-19 18:58 UTC (permalink / raw)
  To: Mikael Morin; +Cc: fortran, gcc-patches

On Fri, Jan 19, 2024 at 06:47:36PM +0100, Mikael Morin wrote:
> 
> I tested this on x86_64-pc-linux-gnu without regression.
> There is no new test, as the problem is visible on an 
> existing test with valgrind or an asan-instrumented compiler.
> OK for master?
> 

Yes.  After your explanation, the patch looks trivially obvious! :-)
Thanks for the patch.

-- 
Steve

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-01-19 18:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-19 17:47 [PATCH] fortran: Restore current interface info on error [PR111291] Mikael Morin
2024-01-19 18:58 ` Steve Kargl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).