[Patch, gfortran] PR22304 - gfortran silently changes values in equivalenced variables

Paul Thomas paulthomas2@wanadoo.fr
Thu Aug 18 05:59:00 GMT 2005


:ADDPATCH <fortran>:

This patch, is a development of Mike Albert's. It considerably 
simplifies the original code and allows it to cope correctly with all 
legal variants of the equivalence statement.

The problem arose when the symbol that owned a common segment did not 
appear first in an equivalence pair.  The first member, which could be 
from the local scope, did not get marked as used and so got hit again, 
when local equivalences were dealt with.  This produced a union, in the 
local scope, that was different to the union for the common/equivalence 
block.

Equivalence groups with three or more members were being being 
re-associated by finish_equivalences, in the correct place, even though 
find_equivalences failed, sometimes to find one of the members; eg. for 
a group (a, b, owner), b would not be found. The patch simplifies the 
business by marking all the members of a group at the same time. (Thanks 
to Thomas Koenig to alerting me to my lack of understanding of this point.)

A blow-by-blow analysis:

(i) Translate_common calls add_equivalences, which calls 
find_equivalences. At present, this only marks, as_used, the equivalence 
partners that appear in the chain linked to the quivalence group; ie. 
the root member is quietly ignored, if it is not the segment owner.
(ii) Later, finish_equivalences does the same again. This time it 
creates local unions for all equivalence variables that are not used; 
ie. those that are declared in the local scope.
(iii) Thus, where this happens, references in this scope point to the 
local union, rather than the common block.
(iv) The fix acts on step (i) by marking all the partners in the local 
scope, as_used. It does this by cycling through each equivalence group 
looking for the segment owner.  Once this is identified,, it cycles 
through this group again, adding the members to the common block and 
marking them as_used.

Bubblestrapped and regtested on FC3/Athlon 1700.

OK for mainline and 4.0?

Paul T


-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: common_equivalences_patch.txt
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20050818/5ae6ae66/attachment.txt>


More information about the Gcc-patches mailing list