------- Comment #2 from paul dot thomas at jet dot uk 2006-04-26 14:09 ------- The testcase reduces to:
module a integer, parameter :: dp = kind (1d0) real(dp) :: reM, M equivalence (M, reM) end module a module b use a, only : dp end module b use a use b print *, M reM = 0.5d1 print *, M end and can be fixed by ensuring that equivalences with unused module variables never get to the namespace. Here is a preliminary patch that accomplishes this. Using gfc_free_equiv causes segfaults further down the line because eq->expr is being freed. I do not know, at the moment, why that should be. To keep memory leaks to the minimum, I have just freed the gfc_equiv, for the time being. Working on this has exposed another, in some ways more serious, bug, which I will add to the database. Index: gcc/fortran/module.c =================================================================== --- gcc/fortran/module.c (r?®vision 113192) +++ gcc/fortran/module.c (copie de travail) @@ -3013,7 +3022,8 @@ static void load_equiv(void) { - gfc_equiv *head, *tail, *end; + gfc_equiv *head, *tail, *end, *eq; + bool unused; mio_lparen(); @@ -3039,12 +3049,33 @@ mio_expr(&tail->expr); } + unused = false; + for (eq = head; eq; eq = eq->eq) + { + if (!(eq && eq->expr && eq->expr->symtree)) + { + unused = true; + break; + } + } + + if (unused) + { + for (eq = head; eq; eq = head) + { + head = eq->eq; + gfc_free (eq); + } + } + if (end == NULL) gfc_current_ns->equiv = head; else end->next = head; - end = head; + if (head != NULL) + end = head; + mio_rparen(); } -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27269