This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch, fortran] PR63744 accept duplicate use-rename


Hello,

we currently reject programs of the form
> 
> module m
>     integer :: s
> end module m
> subroutine s
>     use m, only: x => s, x => s
> end subroutine s

with an error stating that S is the name of the current program unit.
Interestingly, the duplicate rename is necessary to trigger it.

There doesn't seem to be a consensus as to whether it should be
accepted, but I think it should be.
Quoting Dominique's comment in the PR:
>  if
> 
>   use m, only: A => X
>   use m, only: B => X
> 
> is valid, I don't see why
> 
>   use m, only: A => X
>   use m, only: A => X
> 
> should not.
The problem is we check the original (symbol) name instead of the local
(symtree) name.
The fix is close to obvious, and should be safe for the branches (this
is a regression)
Regression tested on x86_64-linux. OK for trunk/4.9/4.8 ?

Mikael



Attachment: pr63744.CL
Description: Text document

Index: module.c
===================================================================
--- module.c	(révision 220107)
+++ module.c	(copie de travail)
@@ -4795,19 +4795,21 @@ read_cleanup (pointer_info *p)
 /* It is not quite enough to check for ambiguity in the symbols by
    the loaded symbol and the new symbol not being identical.  */
 static bool
-check_for_ambiguous (gfc_symbol *st_sym, pointer_info *info)
+check_for_ambiguous (gfc_symtree *st, pointer_info *info)
 {
   gfc_symbol *rsym;
   module_locus locus;
   symbol_attribute attr;
+  gfc_symbol *st_sym;
 
-  if (gfc_current_ns->proc_name && st_sym->name == gfc_current_ns->proc_name->name)
+  if (gfc_current_ns->proc_name && st->name == gfc_current_ns->proc_name->name)
     {
       gfc_error ("%qs of module %qs, imported at %C, is also the name of the "
-		 "current program unit", st_sym->name, module_name);
+		 "current program unit", st->name, module_name);
       return true;
     }
 
+  st_sym = st->n.sym;
   rsym = info->u.rsym.sym;
   if (st_sym == rsym)
     return false;
@@ -5037,7 +5039,7 @@ read_module (void)
 	  if (st != NULL)
 	    {
 	      /* Check for ambiguous symbols.  */
-	      if (check_for_ambiguous (st->n.sym, info))
+	      if (check_for_ambiguous (st, info))
 		st->ambiguous = 1;
 	      else
 		info->u.rsym.symtree = st;



! { dg-do compile }
!
! PR fortran/63744
! duplicate use rename used to be rejected when the target name
! was that of the current program unit 
!
! Original testcase from Roger Ferrer Ibanez <roger.ferrer@bsc.es>

MODULE MOO
    INTEGER :: A, B, C, D, E, F, G, H, I
END MODULE MOO

SUBROUTINE S
    USE MOO, ONLY: X => A, X => A
END SUBROUTINE S

SUBROUTINE T
    USE MOO, ONLY: X => B
    USE MOO, ONLY: X => B
END SUBROUTINE T

SUBROUTINE C
    USE MOO, ONLY: C  ! { dg-error "is also the name of the current program unit" }
END SUBROUTINE C

SUBROUTINE D
    USE MOO, ONLY: X => D
END SUBROUTINE D

SUBROUTINE E
    USE MOO, ONLY: X => E, X => E
END SUBROUTINE E

SUBROUTINE F
    USE MOO, ONLY: X => F
    USE MOO, ONLY: X => F
END SUBROUTINE F

SUBROUTINE X
    USE MOO, ONLY: X => G ! { dg-error "is also the name of the current program unit" }
END SUBROUTINE X

SUBROUTINE Y
    USE MOO, ONLY: Y => H ! { dg-error "is also the name of the current program unit" }
END SUBROUTINE Y

SUBROUTINE Z
    USE MOO, ONLY: Z => I, Z => I ! { dg-error "is also the name of the current program unit" }
END SUBROUTINE Z





Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]