This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] PR Fortran/83093 -- Check the type of character length


When parsing code and implicit typing is used, the
type of an entity used as a character length is not
known until after resolution.  The attach patch 
checks the type of length and response accordingly.
Regression tested on x86_64-*-freebsd.  Ok to commit?

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

	PR fortran/83093
	* resolve.c (resolve_charlen): Check the type of cl->length
	after resolution.

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

	PR fortran/83093
	* gfortran.dg/allocate_with_typespec_7.f90: New test.

-- 
Steve
Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c	(revision 256390)
+++ gcc/fortran/resolve.c	(working copy)
@@ -11664,10 +11664,17 @@ resolve_charlen (gfc_charlen *cl)
 	  specification_expr = saved_specification_expr;
 	  return false;
 	}
+
+      /* cl->length has been resolved.  It should have an integer type.  */
+      if (cl->length->ts.type != BT_INTEGER)
+	{
+	  gfc_error ("Scalar INTEGER expression expected at %L",
+		     &cl->length->where);
+	  return false;
+	}
     }
   else
     {
-
       if (!resolve_index_expr (cl->length))
 	{
 	  specification_expr = saved_specification_expr;
Index: gcc/testsuite/gfortran.dg/allocate_with_typespec_7.f90
===================================================================
--- gcc/testsuite/gfortran.dg/allocate_with_typespec_7.f90	(nonexistent)
+++ gcc/testsuite/gfortran.dg/allocate_with_typespec_7.f90	(working copy)
@@ -0,0 +1,14 @@
+! { dg-do compile }
+! PR Fortran/83093
+! Contributed by Gerhard Steinmetz  <gscfq at t-online dot de>
+program p
+   integer, parameter :: n(2) = [1,2]
+   real :: x = 2
+   character(:), allocatable :: z, zz, zzz
+   character(:), allocatable :: y, yy
+   allocate (character(a) :: z)     ! { dg-error "Scalar INTEGER expression" }
+   allocate (character(x) :: zz)    ! { dg-error "Scalar INTEGER expression" }
+   allocate (character((1.0)) :: z) ! { dg-error "Scalar INTEGER expression" }
+   allocate (character(y) :: y)     ! { dg-error "Scalar INTEGER expression" }
+   allocate (character(n(1:2)) :: y)! { dg-error "Scalar INTEGER expression" }
+end

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]