From 93cb9a5aa147c94d18c708fa67e6fcb546dd7391 Mon Sep 17 00:00:00 2001 From: "Steven G. Kargl" Date: Sun, 31 Jul 2016 01:51:37 +0000 Subject: [PATCH] re PR fortran/41922 (Diagnostic: No location shown for overlappingly initialized EQUIVALENCEd character vars) 2016-07-30 Steven G. Kargl 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 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. From-SVN: r238915 --- gcc/fortran/ChangeLog | 9 ++++++++ gcc/fortran/target-memory.c | 23 +++++++++++-------- gcc/fortran/target-memory.h | 2 +- gcc/fortran/trans-common.c | 7 +++++- gcc/testsuite/ChangeLog | 7 ++++++ .../gfortran.dg/equiv_constraint_5.f90 | 4 ++-- .../gfortran.dg/equiv_constraint_7.f90 | 4 ++-- gcc/testsuite/gfortran.dg/pr41922.f90 | 11 +++++++++ 8 files changed, 52 insertions(+), 15 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr41922.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 32a1e86ab25..d39bd9a1cfc 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,12 @@ +2016-07-30 Steven G. Kargl + + 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 PR fortran/68566 diff --git a/gcc/fortran/target-memory.c b/gcc/fortran/target-memory.c index 0c71c3c805a..ac9cce262e3 100644 --- a/gcc/fortran/target-memory.c +++ b/gcc/fortran/target-memory.c @@ -639,7 +639,8 @@ gfc_target_interpret_expr (unsigned char *buffer, size_t buffer_size, 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 *data, unsigned char *chk, size_t len) 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 *data, unsigned char *chk, size_t len) 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 *data, unsigned char *chk, size_t len) 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, gfc_expr *e, unsigned char *data, { 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, gfc_expr *e, unsigned char *data, 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; diff --git a/gcc/fortran/target-memory.h b/gcc/fortran/target-memory.h index f83cc2163b6..0d79c104b2f 100644 --- a/gcc/fortran/target-memory.h +++ b/gcc/fortran/target-memory.h @@ -44,7 +44,7 @@ int gfc_interpret_derived (unsigned char *, size_t, gfc_expr *); 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); diff --git a/gcc/fortran/trans-common.c b/gcc/fortran/trans-common.c index 4fdccc90747..20ec69eb570 100644 --- a/gcc/fortran/trans-common.c +++ b/gcc/fortran/trans-common.c @@ -532,10 +532,15 @@ get_init_field (segment_info *head, tree union_type, tree *field_init, 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])); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e4ce4c7eceb..829d8975037 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2016-07-30 Steven G. Kargl + + 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. + 2016-07-30 Steven G. Kargl PR fortran/68566 diff --git a/gcc/testsuite/gfortran.dg/equiv_constraint_5.f90 b/gcc/testsuite/gfortran.dg/equiv_constraint_5.f90 index 1f7dddc846b..199b9548900 100644 --- a/gcc/testsuite/gfortran.dg/equiv_constraint_5.f90 +++ b/gcc/testsuite/gfortran.dg/equiv_constraint_5.f90 @@ -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 diff --git a/gcc/testsuite/gfortran.dg/equiv_constraint_7.f90 b/gcc/testsuite/gfortran.dg/equiv_constraint_7.f90 index 872e05b90fc..f999d00665b 100644 --- a/gcc/testsuite/gfortran.dg/equiv_constraint_7.f90 +++ b/gcc/testsuite/gfortran.dg/equiv_constraint_7.f90 @@ -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 diff --git a/gcc/testsuite/gfortran.dg/pr41922.f90 b/gcc/testsuite/gfortran.dg/pr41922.f90 new file mode 100644 index 00000000000..cbbfa6f15f5 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr41922.f90 @@ -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 -- 2.30.2