[8/9/10,Regression,PR93714] ICE in gfc_check_same_strlen, at fortran/check.c:1253
diff mbox series

Message ID 4a83fa75-fc10-7364-6d9b-30a9ef890dac@codethink.co.uk
State New
Headers show
Series
  • Untitled series #158569
Related show

Commit Message

Mark Eggleston Feb. 14, 2020, 1:14 p.m. UTC
Please find attached a patch fixing the ICE in PR93714.

Tested on:

master at https://gcc.gnu.org/g:e235031d490e8ed2aa0bc229694975493fd58977
gcc 9 branch at 
https://gcc.gnu.org/g:d7ab361df604fb66e1ba1e3fb45b4453cba803c4
gcc 8 branch at 
https://gcc.gnu.org/g:1b169f1ea0c9fab7712ede65edb0ffb6e021ad7c

All test OK, however, gcc 9 and gcc 8 report:

XPASS: gfortran.dg/typebound_call_22.f03   -O scan-tree-dump-times 
optimized "base \\(\\);" 1

with and without the patch.

Note: there is a change in error message handled by 
char_pointer_assign_6.f90

     9 |   p1 => c(1:) ! { dg-error "Pointer assignment target" }
       |  1
Error: Unequal character lengths (20/4) in pointer assignment at (1)
char_pointer_assign_6.f90:10:2:

    10 |   p1 => c(:4) ! { dg-error "Pointer assignment target" }
       |  1
Error: Unequal character lengths (20/4) in pointer assignment at (1)

the following is reported:

     9 |   p1 => c(1:) ! { dg-error "Pointer assignment target" }
       |        1
Error: Pointer assignment target is neither TARGET nor POINTER at (1)
char_pointer_assign_6.f90:10:8:

    10 |   p1 => c(:4) ! { dg-error "Pointer assignment target" }
       |        1
Error: Pointer assignment target is neither TARGET nor POINTER at (1)

this is because c does not have TARGET or POINTER attributes specified.

Change logs:

gcc/fortran/ChangeLog

     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.

gcc/testsuite/ChangeLog

     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

OK to commit?

Comments

Thomas Koenig Feb. 17, 2020, 10:08 p.m. UTC | #1
Hi Mark,

> OK to commit?

Yes, OK.

Thanks a lot for the patch!

Regards

	Thomas

Patch
diff mbox series

From 9c83f31b3ed530c605356cd7459e150e2284c5e0 Mon Sep 17 00:00:00 2001
From: Mark Eggleston <markeggleston@gcc.gnu.org>
Date: Thu, 13 Feb 2020 15:58:20 +0000
Subject: [PATCH] fortran: ICE assign character pointer to non target PR93714

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/expr.c                                  | 14 +++++++-------
 gcc/testsuite/gfortran.dg/char_pointer_assign_6.f90 |  4 ++--
 gcc/testsuite/gfortran.dg/pr93714_1.f90             | 11 +++++++++++
 gcc/testsuite/gfortran.dg/pr93714_2.f90             | 11 +++++++++++
 4 files changed, 31 insertions(+), 9 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/pr93714_1.f90
 create mode 100644 gcc/testsuite/gfortran.dg/pr93714_2.f90

diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c
index a9698c3e3d2..79e00b4112a 100644
--- a/gcc/fortran/expr.c
+++ b/gcc/fortran/expr.c
@@ -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 "
diff --git a/gcc/testsuite/gfortran.dg/char_pointer_assign_6.f90 b/gcc/testsuite/gfortran.dg/char_pointer_assign_6.f90
index cd90bfc06e3..e0e116074ae 100644
--- a/gcc/testsuite/gfortran.dg/char_pointer_assign_6.f90
+++ b/gcc/testsuite/gfortran.dg/char_pointer_assign_6.f90
@@ -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
index 00000000000..40f4a4bf89f
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr93714_1.f90
@@ -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
index 00000000000..86658f28859
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr93714_2.f90
@@ -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 }
-- 
2.11.0