PR fortran/85687 -- Check argument of RANK.

Message ID 20180509222844.GA46292@troutmask.apl.washington.edu
State New
Headers show
Series
  • PR fortran/85687 -- Check argument of RANK.
Related show

Commit Message

Steve Kargl May 9, 2018, 10:28 p.m.
I plan to commit the attached patch on Saturday unless 
someone voices an objection.

2018-05-09  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/85687
	* check.c (gfc_check_rank): Check that the argument is a data object.

2018-05-09  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/85687
	* gfortran.dg/pr85687.f90: new test.

Patch

Index: gcc/fortran/check.c
===================================================================
--- gcc/fortran/check.c	(revision 260098)
+++ gcc/fortran/check.c	(working copy)
@@ -3886,8 +3886,11 @@  gfc_check_rank (gfc_expr *a)
 		  ? a->value.function.esym->result->attr.pointer
 		  : a->symtree->n.sym->result->attr.pointer;
 
-  if (a->expr_type == EXPR_OP || a->expr_type == EXPR_NULL
-      || a->expr_type == EXPR_COMPCALL|| a->expr_type == EXPR_PPC
+  if (a->expr_type == EXPR_OP
+      || a->expr_type == EXPR_NULL
+      || a->expr_type == EXPR_COMPCALL
+      || a->expr_type == EXPR_PPC
+      || a->ts.type == BT_PROCEDURE
       || !is_variable)
     {
       gfc_error ("The argument of the RANK intrinsic at %L must be a data "
Index: gcc/testsuite/gfortran.dg/pr85687.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr85687.f90	(nonexistent)
+++ gcc/testsuite/gfortran.dg/pr85687.f90	(working copy)
@@ -0,0 +1,8 @@ 
+! { dg-do compile }
+! PR fortran/85687
+! Code original contributed by Gerhard Steinmetz gscfq at t-oline dot de
+program p
+   type t
+   end type
+   print *, rank(t)  ! { dg-error "must be a data object" }
+end