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]

PR fortran/41922 -- Patch


The attached patch has been built and tested on x86_64-*-freebsd.
There are no regression in the testing.  OK to commit?

2016-07-30  Steven G. Kargl <kargl@gcc.gnu.org>

	PR fortran/41922
	* target-memory.c (expr_to_char): Pass in locus and use it in error
	messages.
	(gfc_merge_initializers): Ditto.
	* target-memory.h: Update prototype for gfc_merge_initializers ().
	* trans-common.c (get_init_field): Use the correct locus.

2016-07-30  Steven G. Kargl <kargl@gcc.gnu.org>

	PR fortran/41922
	* gfortran.dg/equiv_constraint_5.f90: Adjust the error message.
	* gfortran.dg/equiv_constraint_7.f90: Ditto.
	* gfortran.dg/pr41922.f90: New test.

-- 
Steve
Index: gcc/fortran/target-memory.c
===================================================================
--- gcc/fortran/target-memory.c	(revision 238909)
+++ gcc/fortran/target-memory.c	(working copy)
@@ -639,7 +639,8 @@ gfc_target_interpret_expr (unsigned char
    error.  */
 
 static size_t
-expr_to_char (gfc_expr *e, unsigned char *data, unsigned char *chk, size_t len)
+expr_to_char (gfc_expr *e, locus *loc,
+	      unsigned char *data, unsigned char *chk, size_t len)
 {
   int i;
   int ptr;
@@ -663,7 +664,7 @@ expr_to_char (gfc_expr *e, unsigned char
 	    continue;
 	  ptr = TREE_INT_CST_LOW(DECL_FIELD_OFFSET(cmp->backend_decl))
 	    + TREE_INT_CST_LOW(DECL_FIELD_BIT_OFFSET(cmp->backend_decl))/8;
-	  expr_to_char (c->expr, &data[ptr], &chk[ptr], len);
+	  expr_to_char (c->expr, loc, &data[ptr], &chk[ptr], len);
 	}
       return len;
     }
@@ -674,12 +675,16 @@ expr_to_char (gfc_expr *e, unsigned char
   buffer = (unsigned char*)alloca (len);
   len = gfc_target_encode_expr (e, buffer, len);
 
-    for (i = 0; i < (int)len; i++)
+  for (i = 0; i < (int)len; i++)
     {
       if (chk[i] && (buffer[i] != data[i]))
 	{
-	  gfc_error ("Overlapping unequal initializers in EQUIVALENCE "
-		     "at %L", &e->where);
+	  if (loc)
+	    gfc_error ("Overlapping unequal initializers in EQUIVALENCE "
+			"at %L", loc);
+	  else
+	    gfc_error ("Overlapping unequal initializers in EQUIVALENCE "
+			"at %C");
 	  return 0;
 	}
       chk[i] = 0xFF;
@@ -695,7 +700,8 @@ expr_to_char (gfc_expr *e, unsigned char
    the union declaration.  */
 
 size_t
-gfc_merge_initializers (gfc_typespec ts, gfc_expr *e, unsigned char *data,
+gfc_merge_initializers (gfc_typespec ts, gfc_expr *e, locus *loc,
+			unsigned char *data,
 			unsigned char *chk, size_t length)
 {
   size_t len = 0;
@@ -705,8 +711,7 @@ gfc_merge_initializers (gfc_typespec ts,
     {
     case EXPR_CONSTANT:
     case EXPR_STRUCTURE:
-      len = expr_to_char (e, &data[0], &chk[0], length);
-
+      len = expr_to_char (e, loc, &data[0], &chk[0], length);
       break;
 
     case EXPR_ARRAY:
@@ -718,7 +723,7 @@ gfc_merge_initializers (gfc_typespec ts,
 	  if (mpz_cmp_si (c->offset, 0) != 0)
 	    len = elt_size * (size_t)mpz_get_si (c->offset);
 
-	  len = len + gfc_merge_initializers (ts, c->expr, &data[len],
+	  len = len + gfc_merge_initializers (ts, c->expr, loc, &data[len],
 					      &chk[len], length - len);
 	}
       break;
Index: gcc/fortran/target-memory.h
===================================================================
--- gcc/fortran/target-memory.h	(revision 238909)
+++ gcc/fortran/target-memory.h	(working copy)
@@ -44,7 +44,7 @@ int gfc_interpret_derived (unsigned char
 int gfc_target_interpret_expr (unsigned char *, size_t, gfc_expr *, bool);
 
 /* Merge overlapping equivalence initializers for trans-common.c. */
-size_t gfc_merge_initializers (gfc_typespec, gfc_expr *,
+size_t gfc_merge_initializers (gfc_typespec, gfc_expr *, locus *,
 			       unsigned char *, unsigned char *,
 			       size_t);
 
Index: gcc/fortran/trans-common.c
===================================================================
--- gcc/fortran/trans-common.c	(revision 238909)
+++ gcc/fortran/trans-common.c	(working copy)
@@ -532,10 +532,15 @@ get_init_field (segment_info *head, tree
   memset (chk, '\0', (size_t)length);
   for (s = head; s; s = s->next)
     if (s->sym->value)
-      gfc_merge_initializers (s->sym->ts, s->sym->value,
+      {
+	locus *loc = NULL;
+	if (s->sym->ns->equiv && s->sym->ns->equiv->eq)
+	  loc = &s->sym->ns->equiv->eq->expr->where;
+	gfc_merge_initializers (s->sym->ts, s->sym->value, loc,
 			      &data[s->offset],
 			      &chk[s->offset],
 			     (size_t)s->length);
+      }
   
   for (i = 0; i < length; i++)
     CONSTRUCTOR_APPEND_ELT (v, NULL, build_int_cst (type, data[i]));
Index: gcc/testsuite/gfortran.dg/equiv_constraint_5.f90
===================================================================
--- gcc/testsuite/gfortran.dg/equiv_constraint_5.f90	(revision 238909)
+++ gcc/testsuite/gfortran.dg/equiv_constraint_5.f90	(working copy)
@@ -19,13 +19,13 @@
   END TYPE T2
   TYPE T3
     sequence
-    integer :: i=2 ! { dg-error "Overlapping unequal initializers" }
+    integer :: i=2
   END TYPE T3
   TYPE(T1) :: a1
   TYPE(T2) :: a2
   TYPE(T3) :: a3
   EQUIVALENCE (a1, a2)
-  EQUIVALENCE (a1, a3)
+  EQUIVALENCE (a1, a3) ! { dg-error "Overlapping unequal initializers" }
   write(6, *) a1, a2, a3
 END
 
Index: gcc/testsuite/gfortran.dg/equiv_constraint_7.f90
===================================================================
--- gcc/testsuite/gfortran.dg/equiv_constraint_7.f90	(revision 238909)
+++ gcc/testsuite/gfortran.dg/equiv_constraint_7.f90	(working copy)
@@ -5,7 +5,7 @@
 ! Started out being in BLOCK DATA; however, blockdata variables must be in
 ! COMMON and therefore cannot have F95 style initializers....
  MODULE DATA
-  INTEGER :: I=1,J=2  ! { dg-error "Overlapping unequal initializers" }
-  EQUIVALENCE(I,J)
+  INTEGER :: I=1,J=2
+  EQUIVALENCE(I,J)  ! { dg-error "Overlapping unequal initializers" }
  END MODULE DATA
  END
Index: gcc/testsuite/gfortran.dg/pr41922.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr41922.f90	(nonexistent)
+++ gcc/testsuite/gfortran.dg/pr41922.f90	(working copy)
@@ -0,0 +1,11 @@
+! { dg-do compile}
+! { dg-options -std=gnu }
+      Subroutine RestoreR8Run()
+      Implicit NONE
+      Integer   ISTORE
+      Real      XSTORE
+      character   CSTORE(8)
+      data cstore/8*' '/
+      data istore/0/
+      EQUIVALENCE (CSTORE(1),XSTORE,ISTORE) ! { dg-error "Overlapping unequal" }
+      end

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