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, gfortran] PR16511 - Test 19990905-0.f fails with gfortran


:ADDPATCH <fortran>:

This patch, fixes PR16511.

The problem occurred with constructs of the kind:

     common /info/ iarray(1000)
     equivalence (m,iarray(100)), (n,iarray(200))
     real a(m,n)

which are legal because m an n are in the common block, via an equivalence.

The patch works by intercepting all symbols that are equivalence associated with a common block and by marking them as in_common.

This is done in both gfc_match_common and in gfc_match_equivalence, so that the statements can be in any order. This is consistent with the lay-up of the variables in the common segment and their tree declarations.

Bubblestrapped and regtested on FC3/Athlon 1700.

OK for mainline and 4.0?

Paul T

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

	PR fortran/16511
	* match.c (gfc_match_common, gfc_match_equivalence): Ensure that
	symbols that are equivalence associated with a common block are
	marked as being in_common.


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

	PR fortran/16511
	* gfortran.dg/g77/19990905-0.f: Remove XFAIL and add comment to
	connect the test with the PR.

============================================================

*** gcc/gcc/fortran/match.c	2005-08-17 14:47:08.000000000 +0200
--- /gcc-4.1/gcc/gcc/fortran/match.c	2005-08-16 08:53:19.000000000 +0200
*************** gfc_match_common (void)
*** 2230,2235 ****
--- 2230,2237 ----
    char name[GFC_MAX_SYMBOL_LEN+1];
    gfc_common_head *t;
    gfc_array_spec *as;
+   gfc_equiv * e1, * e2;
+   bool equiv_flag;
    match m;
  
    old_blank_common = gfc_current_ns->blank_common.head;
*************** gfc_match_common (void)
*** 2354,2359 ****
--- 2356,2379 ----
  
  	      sym->as = as;
  	      as = NULL;
+ 
+ 	      /* Check to see if the symbol is already in an equivalence group.
+ 	         If it is, set the other members as being in common.  */
+ 	      for (e1 = gfc_current_ns->equiv; e1; e1 = e1->next)
+ 		{
+ 		  equiv_flag = false;
+ 		  for (e2 = e1; e2; e2 = e2->eq)
+ 		    if (e2->expr->symtree->n.sym == sym)
+ 		      {
+ 			equiv_flag = true;
+ 			continue;
+ 		      }
+ 		  if (equiv_flag == false)
+ 		    continue;
+ 		  for (e2 = e1; e2; e2 = e2->eq)
+ 		    e2->expr->symtree->n.sym->attr.in_common = 1;
+ 		}
+ 
  	    }
  
  	  gfc_gobble_whitespace ();
*************** gfc_match_equivalence (void)
*** 2560,2565 ****
--- 2580,2586 ----
    gfc_equiv *eq, *set, *tail;
    gfc_ref *ref;
    match m;
+   bool common_flag;
  
    tail = NULL;
  
*************** gfc_match_equivalence (void)
*** 2576,2581 ****
--- 2597,2603 ----
  	goto syntax;
  
        set = eq;
+       common_flag = FALSE;
  
        for (;;)
  	{
*************** gfc_match_equivalence (void)
*** 2594,2599 ****
--- 2616,2624 ----
  		goto cleanup;
  	      }
  
+ 	  if (set->expr->symtree->n.sym->attr.in_common)
+ 	    common_flag = TRUE;
+ 
  	  if (gfc_match_char (')') == MATCH_YES)
  	    break;
  	  if (gfc_match_char (',') != MATCH_YES)
*************** gfc_match_equivalence (void)
*** 2603,2608 ****
--- 2628,2639 ----
  	  set = set->eq;
  	}
  
+       /* If one of the members of an equivalence is in common, then
+        mark them all as being in common.  */
+       if (common_flag)
+         for (set = eq; set; set = set->eq)
+           set->expr->symtree->n.sym->attr.in_common = 1;
+ 
        if (gfc_match_eos () == MATCH_YES)
  	break;
        if (gfc_match_char (',') != MATCH_YES)

========================================================

*** /gcc-4.0/gcc/gcc/testsuite/gfortran.dg/g77/19990905-0.f	2004-07-13 09:08:22.000000000 +0200
--- /mainline/gcc/gcc/testsuite/gfortran.dg/g77/19990905-0.f	2005-08-17 16:53:25.486882968 +0200
***************
*** 1,8 ****
  c { dg-do compile }
  * =foo0.f in Burley's g77 test suite.
        subroutine sub(a)
        common /info/ iarray(1000)
!       equivalence (m,iarray(100)), (n,iarray(200))
!       real a(m,n) ! { dg-bogus "Variable 'm' cannot appear" "Variable 'm' cannot appear" { xfail *-*-* } } PR 16511 
        a(1,1) = a(2,2)
        end
--- 1,12 ----
  c { dg-do compile }
  * =foo0.f in Burley's g77 test suite.
+ ! Used to give "Variable 'm' cannot appear" "Variable 'm' cannot appear"
+ ! after REAL a(m,n), as described in PR 16511.
+ !
        subroutine sub(a)
+       equivalence (m,iarray(100))
        common /info/ iarray(1000)
!       equivalence (n,iarray(200))
!       real a(m,n)
        a(1,1) = a(2,2)
        end

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