re PR fortran/50071 (gfortran does not distinguish labels in different type scoping...
authorMikael Morin <mikael.morin@sfr.fr>
Thu, 18 Aug 2011 21:39:42 +0000 (23:39 +0200)
committerMikael Morin <mikael@gcc.gnu.org>
Thu, 18 Aug 2011 21:39:42 +0000 (21:39 +0000)
2011-08-18  Mikael Morin  <mikael.morin@sfr.fr>

PR fortran/50071
* symbol.c (gfc_get_st_label): Use the derived type namespace when
we are parsing a derived type definition.

2011-08-18  Mikael Morin  <mikael.morin@sfr.fr>

PR fortran/50071
* gfortran.dg/duplicate_labels_2.f: New test.

From-SVN: r177882

gcc/fortran/ChangeLog
gcc/fortran/symbol.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/duplicate_labels_2.f [new file with mode: 0644]

index fa92219..85538ee 100644 (file)
@@ -1,3 +1,9 @@
+2011-08-18  Mikael Morin  <mikael.morin@sfr.fr>
+
+       PR fortran/50071
+       * symbol.c (gfc_get_st_label): Use the derived type namespace when
+       we are parsing a derived type definition.
+
 2011-08-18  Tobias Burnus  <burnus@net-b.de>
 
        PR fortran/18918
index b761cdd..4463460 100644 (file)
@@ -2127,11 +2127,16 @@ gfc_get_st_label (int labelno)
   gfc_st_label *lp;
   gfc_namespace *ns;
 
-  /* 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;
+  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;
index 4737966..150c1e5 100644 (file)
@@ -1,3 +1,8 @@
+2011-08-18  Mikael Morin  <mikael.morin@sfr.fr>
+
+       PR fortran/50071
+       * gfortran.dg/duplicate_labels_2.f: New test.
+
 2011-08-18  Joseph Myers  <joseph@codesourcery.com>
 
        * gcc.dg/c1x-noreturn-1.c, gcc.dg/c1x-noreturn-2.c,
diff --git a/gcc/testsuite/gfortran.dg/duplicate_labels_2.f b/gcc/testsuite/gfortran.dg/duplicate_labels_2.f
new file mode 100644 (file)
index 0000000..8a3692d
--- /dev/null
@@ -0,0 +1,25 @@
+! { dg-do compile }
+!
+! PR fortran/50071
+! Duplicate statement labels should not be rejected if they appear in
+! different scoping units
+!
+! Contributed by Vittorio Zecca <zeccav@gmail.com>
+
+c gfortran complains about duplicate statement labels
+c this is a legal program because types have their own scoping units 
+c and you may have same labels in different scoping units,
+c as you may have same identifiers inside, like G.
+      type t1
+1      integer G
+      end type
+      type t2
+1      integer G
+      end type
+c this is legal
+      goto 1
+      print *,'bad'
+1     continue
+      print *,'good'
+      end
+