* [patch, fortran] Fix PR 50627
@ 2013-01-27 18:36 Thomas Koenig
2013-01-27 19:44 ` Thomas Koenig
0 siblings, 1 reply; 5+ messages in thread
From: Thomas Koenig @ 2013-01-27 18:36 UTC (permalink / raw)
To: fortran, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 671 bytes --]
Hello world,
the attached patch fixes the regression regarding freeing
namespaces twice.
The test cases where also run unter valgrind without
producing errors.
Regression-tested. OK for trunk?
Thomas
2013-01-27 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/56054
* decl.c (gfc_match_end): Remove half-ready namespace
from parent if the end of a block is missing.
* parse.c (parse_module): Do not put namespace into
gsymbol on error.
2013-01-27 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/56054
* gfortran.dg/block_12.f90: New test.
* gfortran.dg/module_error_1.f90: New test.
[-- Attachment #2: p3.diff --]
[-- Type: text/x-patch, Size: 1965 bytes --]
Index: decl.c
===================================================================
--- decl.c (Revision 195319)
+++ decl.c (Arbeitskopie)
@@ -5979,6 +5979,8 @@ gfc_match_end (gfc_statement *st)
const char *target;
int eos_ok;
match m;
+ gfc_namespace *parent_ns, *ns, *prev_ns;
+ gfc_namespace **nsp;
old_loc = gfc_current_locus;
if (gfc_match ("end") != MATCH_YES)
@@ -6204,6 +6206,35 @@ syntax:
cleanup:
gfc_current_locus = old_loc;
+
+ /* If we are missing an END BLOCK, we created a half-ready namespace.
+ Remove it from the parent namespace's sibling list. */
+
+ if (state == COMP_BLOCK)
+ {
+ parent_ns = gfc_current_ns->parent;
+
+ nsp = &(gfc_state_stack->previous->tail->ext.block.ns);
+
+ prev_ns = NULL;
+ ns = *nsp;
+ while (ns)
+ {
+ if (ns == gfc_current_ns)
+ {
+ if (prev_ns == NULL)
+ *nsp = NULL;
+ else
+ prev_ns->sibling = ns->sibling;
+ }
+ prev_ns = ns;
+ ns = ns->sibling;
+ }
+
+ gfc_free_namespace (gfc_current_ns);
+ gfc_current_ns = parent_ns;
+ }
+
return MATCH_ERROR;
}
Index: parse.c
===================================================================
--- parse.c (Revision 195319)
+++ parse.c (Arbeitskopie)
@@ -4291,6 +4291,7 @@ parse_module (void)
{
gfc_statement st;
gfc_gsymbol *s;
+ bool error;
s = gfc_get_gsymbol (gfc_new_block->name);
if (s->defined || (s->type != GSYM_UNKNOWN && s->type != GSYM_MODULE))
@@ -4304,6 +4305,7 @@ parse_module (void)
st = parse_spec (ST_NONE);
+ error = false;
loop:
switch (st)
{
@@ -4322,12 +4324,15 @@ loop:
gfc_error ("Unexpected %s statement in MODULE at %C",
gfc_ascii_statement (st));
+ error = true;
reject_statement ();
st = next_statement ();
goto loop;
}
- s->ns = gfc_current_ns;
+ /* Make sure not to free the namespace twice on error. */
+ if (!error)
+ s->ns = gfc_current_ns;
}
[-- Attachment #3: module_error_1.f90 --]
[-- Type: text/x-fortran, Size: 119 bytes --]
! { dg-do compile }
module kernels
select type (args) ! { dg-error "Unexpected SELECT TYPE" }
end module kernels
[-- Attachment #4: block_12.f90 --]
[-- Type: text/x-fortran, Size: 182 bytes --]
! { dg-do compile }
! PR 56054 - this used to free a namespace twice.
program main
block
end program main ! { dg-error "END BLOCK" }
! { dg-prune-output "Unexpected end of file" }
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch, fortran] Fix PR 50627
2013-01-27 18:36 [patch, fortran] Fix PR 50627 Thomas Koenig
@ 2013-01-27 19:44 ` Thomas Koenig
2013-02-02 9:32 ` Paul Richard Thomas
0 siblings, 1 reply; 5+ messages in thread
From: Thomas Koenig @ 2013-01-27 19:44 UTC (permalink / raw)
To: fortran, gcc-patches
Of course, that should be PR 50627 in the ChangeLog.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch, fortran] Fix PR 50627
2013-01-27 19:44 ` Thomas Koenig
@ 2013-02-02 9:32 ` Paul Richard Thomas
2013-02-02 10:36 ` Thomas Koenig
0 siblings, 1 reply; 5+ messages in thread
From: Paul Richard Thomas @ 2013-02-02 9:32 UTC (permalink / raw)
To: Thomas Koenig; +Cc: fortran, gcc-patches
Dear Thomas,
I wrote this almost immediately after you posted the patch, got
disturbed and forgot about it - my apologies. Note Dominique's reply
after you corrected the PR number.
OK for trunk. The part in decl.c is exactly what I was thinking to do.
Thanks for the patch
Paul
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch, fortran] Fix PR 50627
2013-02-02 9:32 ` Paul Richard Thomas
@ 2013-02-02 10:36 ` Thomas Koenig
0 siblings, 0 replies; 5+ messages in thread
From: Thomas Koenig @ 2013-02-02 10:36 UTC (permalink / raw)
To: fortran, gcc-patches
Hi Paul,
> OK for trunk. The part in decl.c is exactly what I was thinking to do.
>
> Thanks for the patch
Thanks a lot for your review!
Committed to trunk as rev. 195684, 4.7 and 4.6 to follow.
Thomas
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch, fortran] Fix PR 50627
@ 2013-01-27 20:04 Dominique Dhumieres
0 siblings, 0 replies; 5+ messages in thread
From: Dominique Dhumieres @ 2013-01-27 20:04 UTC (permalink / raw)
To: fortran; +Cc: gcc-patches, tkoenig
> Of course, that should be PR 50627 in the ChangeLog.
I think you need both PR 50627 and 56054.
The patch fixes these PRs, full testing in progress.
Dominique
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-02-02 10:36 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-27 18:36 [patch, fortran] Fix PR 50627 Thomas Koenig
2013-01-27 19:44 ` Thomas Koenig
2013-02-02 9:32 ` Paul Richard Thomas
2013-02-02 10:36 ` Thomas Koenig
2013-01-27 20:04 Dominique Dhumieres
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).