]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR fortran/87991 (ICE in gfc_constructor_append_expr, at fortran/constructor.c...
authorSteven G. Kargl <kargl@gcc.gnu.org>
Wed, 14 Aug 2019 04:38:29 +0000 (04:38 +0000)
committerSteven G. Kargl <kargl@gcc.gnu.org>
Wed, 14 Aug 2019 04:38:29 +0000 (04:38 +0000)
2019-08-13  Steven G. Kargl  <kargl@gcc.gnu.org>

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  <kargl@gcc.gnu.org>

PR fortran/87991
* gfortran.dg/pr87991.f90: New test.

From-SVN: r274413

gcc/fortran/ChangeLog
gcc/fortran/resolve.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/pr87991.f90 [new file with mode: 0644]

index 9484b9992e533a70753fef0aa552e671dab40d13..ee23b3f3bba1b051a293241ba0de60fded217591 100644 (file)
@@ -1,10 +1,16 @@
+2019-08-13  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       PR fortran/87991
+       * resolve.c (check_data_variable): data-stmt-object with pointer
+       attribute requires a data-stmt-value with the target attribute.
+
 2013-08-13  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        Backport from trunk
        PR fortran/90563
        * frontend-passes.c (insert_index): Suppress errors while
        simplifying the resulting expression.
-
 2019-08-13  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        PR fortran/88072
index c6569d5da3942128cd18c3f43c4ce65a1462412d..9647ef2c46a463a71496fe681f7f40a0c0ed629c 100644 (file)
@@ -15682,8 +15682,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,
@@ -15691,19 +15689,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)
index e8b462ac39734eb2ad2c458732ba3a008a111300..111c5ace0651ca5ae785f421e3f07b8262bf9762 100644 (file)
@@ -1,3 +1,8 @@
+2019-08-13  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       PR fortran/87991
+       * gfortran.dg/pr87991.f90: New test.
 2013-08-13  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        Backport from trunk
diff --git a/gcc/testsuite/gfortran.dg/pr87991.f90 b/gcc/testsuite/gfortran.dg/pr87991.f90
new file mode 100644 (file)
index 0000000..435871e
--- /dev/null
@@ -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