===================================================================
@@ -4479,8 +4479,8 @@ load_commons (void)
static void
load_equiv (void)
{
- gfc_equiv *head, *tail, *end, *eq;
- bool unused;
+ gfc_equiv *head, *tail, *end, *equiv;
+ bool unused, duplicate;
mio_lparen ();
in_load_equiv = true;
@@ -4507,23 +4507,19 @@ load_equiv (void)
mio_expr (&tail->expr);
}
- /* Unused equivalence members have a unique name. In addition, it
- must be checked that the symbols are from the same module. */
- unused = true;
- for (eq = head; eq; eq = eq->eq)
+ /* Check for duplicate equivalences being loaded from different modules */
+ duplicate = false;
+ for (equiv = gfc_current_ns->equiv; equiv; equiv = equiv->next)
{
- if (eq->expr->symtree->n.sym->module
- && head->expr->symtree->n.sym->module
- && strcmp (head->expr->symtree->n.sym->module,
- eq->expr->symtree->n.sym->module) == 0
- && !check_unique_name (eq->expr->symtree->name))
+ if (equiv->module && head->module
+ && strcmp (equiv->module, head->module) == 0)
{
- unused = false;
+ duplicate = true;
break;
}
}
- if (unused)
+ if (duplicate)
{
for (eq = head; eq; eq = head)
{
===================================================================
@@ -0,0 +1,22 @@
+! { dg-do run }
+! PR fortran/66377
+!
+module constant
+ integer x1, x2, x3
+ integer x(3)
+ equivalence (x(1),x1), (x2,x(2)), (x3,x(3))
+end module
+
+program test
+ use constant
+ implicit none
+ x = (/1, 2, 3/)
+ call another()
+end program
+
+subroutine another()
+ use constant, only : x2
+ implicit none
+ if (x2 /= 2) call abort
+end subroutine
+! { dg-final { cleanup-modules "constant" } }