[PATCH] fortran/25756 -- fix statement label on empty statements
Steve Kargl
sgk@troutmask.apl.washington.edu
Thu Jan 12 23:14:00 GMT 2006
I've compiled and regression tested the attached patch on
amd64-*-freebsd. There were no regressions. The PR has
3 small test programs, and I intend to commit only label_3.f90.
label_4.f90 and label_5.f90 contain tabs, which make the
programs nonconforming.
The problem is the somewhat convoluted logic of managing the
linked list of structures that contain the statement label info.
Most people would allocate the struct, populate struct, check
validity of struct, and then stick it in the list if its valid
or delete it if its bad. Well, gfortran allocates the struct,
sticks it in the list, populates the struct, checks the validity,
and deletes the struct if its bad. Unfortunately, if this is
the first struct in the list, head was pointed at it, and when
gfortran deletes the struct head is pointing off into invalid
memory.
2006-01-12 Steven G. Kargl <kargls@comcast.net>
PR fortran/25756
(Ported from G95)
* symbol.c (gfc_free_st_label): Give variable meaningful name; Remove
unneeded parenthesis; Fix-up the head of the list.
--
Steve
-------------- next part --------------
Index: symbol.c
===================================================================
--- symbol.c (revision 109606)
+++ symbol.c (working copy)
@@ -1473,21 +1473,25 @@ gfc_get_component_attr (symbol_attribute
occurs. */
void
-gfc_free_st_label (gfc_st_label * l)
+gfc_free_st_label (gfc_st_label * label)
{
- if (l == NULL)
+ if (label == NULL)
return;
- if (l->prev)
- (l->prev->next = l->next);
+ if (label->prev)
+ label->prev->next = label->next;
- if (l->next)
- (l->next->prev = l->prev);
+ if (label->next)
+ label->next->prev = label->prev;
- if (l->format != NULL)
- gfc_free_expr (l->format);
- gfc_free (l);
+ if (gfc_current_ns->st_labels == label)
+ gfc_current_ns->st_labels = label->next;
+
+ if (label->format != NULL)
+ gfc_free_expr (label->format);
+
+ gfc_free (label);
}
/* Free a whole list of gfc_st_label structures. */
More information about the Gcc-patches
mailing list