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] PR22304 - gfortran silently changes values in equivalencedvariables


This patch, that Mike Albert found, is devastatingly simple; just one added line. It is discussed in the list for the PR but not adopted because it was not clear how it worked.

In fact, it is also relatively easy to understand:

(i) Translate_common calls add_equivalences, which calls find_equivalences. At present, this only marks, as used, the equivalence partners that appear in the common block.
(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 the partners in the local scope, as used, as well.


There is a strange side-effect of this fix, noted by Thomas Koenig, in the PR correspondence: Where this fix operates, -fdump-tree-original produces a scope block that is not terminated by a right brace. The gimple output is fine and the programs run fine. Using one more variable in this scope clears the problem and restores the right brace.

Is this a gfortran or a tree-dump problem?

2005-08-05 Mike Albert <albertm@uphs.upenn.edu>

   PR fortran/22304
   * trans-common.c (find_equivalences): Ensure that both partners
   in common block equivalences are marked as used. This prevents
   the second call to this function from making local unions.

2005-08-05 Paul Thomas <pault@gcc.gnu.org>

   PR fortran/22304
   * gfortran.dg/common_equivalence_1.f: New.

Patch and test case are attached.

OK for mainline and 4.0?

Paul T

Index: gcc/gcc/fortran/trans-common.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/trans-common.c,v
retrieving revision 1.29
diff -c -3 -p -r1.29 trans-common.c
*** gcc/gcc/fortran/trans-common.c	20 Jul 2005 01:19:32 -0000	1.29
--- gcc/gcc/fortran/trans-common.c	5 Aug 2005 14:51:32 -0000
*************** find_equivalence (segment_info *n)
*** 700,705 ****
--- 700,706 ----
  	    {
  	      add_condition (n, eq, other);
  	      eq->used = 1;
+ 	      other->used = 1;
  	      found = TRUE;
  	      /* If this symbol is the first in the chain we may find other
  		 matches. Otherwise we can skip to the next equivalence.  */
c { dg-do run }
c This program tests the fix for PR22304.
c
c provided by Paul Thomas - pault@gcc.gnu.org
c
      integer a(2), b, c
      COMMON /foo/ a
      EQUIVALENCE (a(1),b), (c,a(2))
      a(1)=101
      a(2)=102
      if (b.ne.101) call abort ()
      if (c.ne.102) call abort ()
      END 

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