From ade8fdbbfd98aafdc12585885dea60460fea0a26 Mon Sep 17 00:00:00 2001 From: "Steven G. Kargl" Date: Wed, 14 Aug 2019 04:22:31 +0000 Subject: [PATCH] re PR fortran/87991 (ICE in gfc_constructor_append_expr, at fortran/constructor.c:135) 2019-08-13 Steven G. Kargl PR fortran/87991 * resolve.c (check_data_variable): data-stmt-object with pointer attribute requires a data-stmt-value with the target attribute. 2019-08-13 Steven G. Kargl PR fortran/87991 * gfortran.dg/pr87991.f90: New test. From-SVN: r274412 --- gcc/fortran/ChangeLog | 6 ++++++ gcc/fortran/resolve.c | 29 ++++++++++++++++++--------- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/pr87991.f90 | 11 ++++++++++ 4 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr87991.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 787c704cafc..42cf2f57947 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2019-08-13 Steven G. Kargl + + PR fortran/87991 + * resolve.c (check_data_variable): data-stmt-object with pointer + attribute requires a data-stmt-value with the target attribute. + 2019-08-13 Steven G. Kargl PR fortran/88072 diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index bd379b696a0..ac9192ae02c 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -15726,8 +15726,6 @@ check_data_variable (gfc_data_variable *var, locus *where) return false; } - has_pointer = sym->attr.pointer; - if (gfc_is_coindexed (e)) { gfc_error ("DATA element %qs at %L cannot have a coindex", sym->name, @@ -15735,19 +15733,30 @@ check_data_variable (gfc_data_variable *var, locus *where) return false; } + has_pointer = sym->attr.pointer; + for (ref = e->ref; ref; ref = ref->next) { if (ref->type == REF_COMPONENT && ref->u.c.component->attr.pointer) has_pointer = 1; - if (has_pointer - && ref->type == REF_ARRAY - && ref->u.ar.type != AR_FULL) - { - gfc_error ("DATA element %qs at %L is a pointer and so must " - "be a full array", sym->name, where); - return false; - } + if (has_pointer) + { + if (ref->type == REF_ARRAY && ref->u.ar.type != AR_FULL) + { + gfc_error ("DATA element %qs at %L is a pointer and so must " + "be a full array", sym->name, where); + return false; + } + + if (values.vnode->expr->expr_type == EXPR_CONSTANT) + { + gfc_error ("DATA object near %L has the pointer attribute " + "and the corresponding DATA value is not a valid " + "initial-data-target", where); + return false; + } + } } if (e->rank == 0 || has_pointer) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 1147dc86a0e..9f7f4e71c31 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-08-13 Steven G. Kargl + + PR fortran/87991 + * gfortran.dg/pr87991.f90: New test. + 2019-08-13 Richard Sandiford * gcc.target/aarch64/sve/spill_2.c: Increase iteration counts diff --git a/gcc/testsuite/gfortran.dg/pr87991.f90 b/gcc/testsuite/gfortran.dg/pr87991.f90 new file mode 100644 index 00000000000..435871ec779 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr87991.f90 @@ -0,0 +1,11 @@ +! { dg-do compile } +! { dg-options "-w" } +! PR fortran/87991 +program p + type t + character(:), pointer :: c + end type + type(t) :: x + allocate (character(3) :: x%c) + data x%c /'abc'/ ! { dg-error "has the pointer attribute" } +end -- 2.30.2