[fortran] ICE assign character pointer to non target PR93714
authorMark Eggleston <markeggleston@gcc.gnu.org>
Tue, 18 Feb 2020 15:54:13 +0000 (15:54 +0000)
committerMark Eggleston <markeggleston@gcc.gnu.org>
Tue, 18 Feb 2020 15:54:13 +0000 (15:54 +0000)
An ICE occurred if an attempt was made to assign a pointer to a
character variable that has an length incorrectly specified using
a real constant and does not have the target attribute.

gcc/fortran/ChangeLog

PR fortran/93714
* expr.c (gfc_check_pointer_assign): Move check for
matching character length to after checking the lvalue
attributes for target or pointer.

gcc/testsuite/ChangeLog

PR fortran/93714
* gfortran.dg/char_pointer_assign_6.f90: Look for no target
message instead of length mismatch.
* gfortran.dg/pr93714_1.f90
* gfortran.dg/pr93714_2.f90

gcc/fortran/ChangeLog
gcc/fortran/expr.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/char_pointer_assign_6.f90
gcc/testsuite/gfortran.dg/pr93714_1.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/pr93714_2.f90 [new file with mode: 0644]

index 5daaefd..7547dcc 100644 (file)
@@ -1,3 +1,10 @@
+2020-02-18  Mark Eggleston  <markeggleston@gcc.gnu.org>
+
+       PR fortran/93714
+       * expr.c (gfc_check_pointer_assign): Move check for
+       matching character length to after checking the lvalue
+       attributes for target or pointer.
+
 2020-02-18  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        PR fortran/93601
index a9698c3..79e00b4 100644 (file)
@@ -4222,13 +4222,6 @@ gfc_check_pointer_assign (gfc_expr *lvalue, gfc_expr *rvalue,
   if (rvalue->expr_type == EXPR_NULL)
     return true;
 
-  if (lvalue->ts.type == BT_CHARACTER)
-    {
-      bool t = gfc_check_same_strlen (lvalue, rvalue, "pointer assignment");
-      if (!t)
-       return false;
-    }
-
   if (rvalue->expr_type == EXPR_VARIABLE && is_subref_array (rvalue))
     lvalue->symtree->n.sym->attr.subref_array_pointer = 1;
 
@@ -4284,6 +4277,13 @@ gfc_check_pointer_assign (gfc_expr *lvalue, gfc_expr *rvalue,
        }
     }
 
+  if (lvalue->ts.type == BT_CHARACTER)
+    {
+      bool t = gfc_check_same_strlen (lvalue, rvalue, "pointer assignment");
+      if (!t)
+       return false;
+    }
+
   if (is_pure && gfc_impure_variable (rvalue->symtree->n.sym))
     {
       gfc_error ("Bad target in pointer assignment in PURE "
index 6b008fd..270644a 100644 (file)
@@ -1,3 +1,11 @@
+2020-02-18  Mark Eggleston <markeggleston@gcc.gnu.org>
+
+       PR fortran/93714
+       * gfortran.dg/char_pointer_assign_6.f90: Look for no target
+       message instead of length mismatch.
+       * gfortran.dg/pr93714_1.f90
+       * gfortran.dg/pr93714_2.f90
+
 2020-02-18  Mark Eggleston  <mark.eggleston@codethink.com>
 
        PR fortran/93601
index cd90bfc..e0e1160 100644 (file)
@@ -6,6 +6,6 @@ program main
   character (len=4) :: c
   s1 = 'abcd'
   p1 => s1(2:3) ! { dg-error "Unequal character lengths \\(20/2\\)" }
-  p1 => c(1:) ! { dg-error "Unequal character lengths \\(20/4\\)" }
-  p1 => c(:4) ! { dg-error "Unequal character lengths \\(20/4\\)" }
+  p1 => c(1:) ! { dg-error "Pointer assignment target" }
+  p1 => c(:4) ! { dg-error "Pointer assignment target" }
 end
diff --git a/gcc/testsuite/gfortran.dg/pr93714_1.f90 b/gcc/testsuite/gfortran.dg/pr93714_1.f90
new file mode 100644 (file)
index 0000000..40f4a4b
--- /dev/null
@@ -0,0 +1,11 @@
+! { dg-do compile }
+! PR 93714
+! Original test case from G. Steinmetz
+
+program test
+   character((1.)) :: a
+   character, pointer :: b => a
+end program
+
+! { dg-error "must be of INTEGER type" " " { target *-*-* } 6 }
+! { dg-error "does not have the TARGET attribute" " " { target *-*-* } 7 }
diff --git a/gcc/testsuite/gfortran.dg/pr93714_2.f90 b/gcc/testsuite/gfortran.dg/pr93714_2.f90
new file mode 100644 (file)
index 0000000..86658f2
--- /dev/null
@@ -0,0 +1,11 @@
+! { dg-do compile }
+! PR 93714
+! Original test case from G. Steinmetz
+
+program test
+   character((9.)) :: a
+   character(:), pointer :: b => a
+end program
+
+! { dg-error "must be of INTEGER type" " " { target *-*-* } 6 }
+! { dg-error "does not have the TARGET attribute" " " { target *-*-* } 7 }