[Patch, fortran] PR fortran/50071 Duplicate statement labels from different scoping units rejected.
Mikael Morin
mikael.morin@sfr.fr
Sat Aug 13 20:11:00 GMT 2011
Hello,
this patch fixes PR 50071 where statement labels in a type definition where
hooked to the parent scoping unit instead of the type scoping unit.
From the standard:
- statement label (3.2.5):
The same statement label shall not be given to more than one statement in its
scope.
- scoping unit (1.3.124)
BLOCK construct, _derived-type_ definition, interface body, program unit,
or subprogram, excluding all nested scoping units in it.
Currently we ignore the derived type definition scoping unit, and thus reject
the statement label if it is the same as another one outside the derived type
definition. As it can't be used anyway, it makes sense to ignore it
completely.
This patch puts the statement label in the derived_type->f2k_derived namespace
if we are parsing a derived type definition.
Regression tested on x86_64-unknown-freebsd8.2. OK for trunk?
Even if it is a rejects-valid bug, I consider it as minor, and don't feel the
need for backporting (but it can be discussed).
Mikael
*** a/symbol.c
--- b/symbol.c
*************** gfc_get_st_label (int labelno)
*** 2127,2137 ****
--- 2127,2144 ----
gfc_st_label *lp;
gfc_namespace *ns;
+ /* A derived type definition is a separate scoping unit, so that it has
its
+ own set of statement labels. */
+ if (gfc_current_state () == COMP_DERIVED)
+ ns = gfc_current_block ()->f2k_derived;
+ else
+ {
/* Find the namespace of the scoping unit:
If we're in a BLOCK construct, jump to the parent namespace. */
ns = gfc_current_ns;
while (ns->proc_name && ns->proc_name->attr.flavor == FL_LABEL)
ns = ns->parent;
+ }
/* First see if the label is already in this namespace. */
lp = ns->st_labels;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr50071_1.diff
Type: text/x-patch
Size: 1153 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20110813/7420cd79/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: duplicate_labels_2.f
Type: text/x-fortran
Size: 613 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20110813/7420cd79/attachment-0001.bin>
More information about the Gcc-patches
mailing list