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/78618 -- RANK() should not ICE


The attached patch fixes an ICE, a nearby whitespace issue, and
removed the ATTRIBUTE_UNUSED tag.  THe change has passed regression
testing on x86_64-*-freebsd.  Ok to commit?

2016-12-01  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/78618
	* check.c (gfc_check_rank): Remove ATTRIBUTE_UNUSED.  Fix whitespace.
	Fix ICE where a NULL pointer is dereferenced.
	* simplify.c (gfc_convert_char_constant):  Do not buffer error.

2016-12-01  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/78618
	* gfortran.dg/char_conversion.f90: New test.

-- 
Steve
Index: gcc/fortran/check.c
===================================================================
--- gcc/fortran/check.c	(revision 243142)
+++ gcc/fortran/check.c	(working copy)
@@ -3667,7 +3667,7 @@ gfc_check_range (gfc_expr *x)
 
 
 bool
-gfc_check_rank (gfc_expr *a ATTRIBUTE_UNUSED)
+gfc_check_rank (gfc_expr *a)
 {
   /* Any data object is allowed; a "data object" is a "constant (4.1.3),
      variable (6), or subobject of a constant (2.4.3.2.3)" (F2008, 1.3.45).  */
@@ -3676,9 +3676,16 @@ gfc_check_rank (gfc_expr *a ATTRIBUTE_UN
 
   /* Functions returning pointers are regarded as variable, cf. F2008, R602.  */
   if (a->expr_type == EXPR_FUNCTION)
-    is_variable = a->value.function.esym
-		  ? a->value.function.esym->result->attr.pointer
-		  : a->symtree->n.sym->result->attr.pointer;
+    {
+      if (a->value.function.esym)
+	is_variable = a->value.function.esym->result->attr.pointer;
+      else if (a->symtree->n.sym->result)
+	is_variable = a->symtree->n.sym->result->attr.pointer;
+      else if (a->symtree->n.sym->value)
+	is_variable = true;
+      else
+	gfc_internal_error ("gfc_check_rank(): invalid function result");
+    }
 
   if (a->expr_type == EXPR_OP || a->expr_type == EXPR_NULL
       || a->expr_type == EXPR_COMPCALL|| a->expr_type == EXPR_PPC
Index: gcc/fortran/simplify.c
===================================================================
--- gcc/fortran/simplify.c	(revision 243142)
+++ gcc/fortran/simplify.c	(working copy)
@@ -7148,7 +7148,7 @@ gfc_convert_char_constant (gfc_expr *e, 
 	if (!gfc_check_character_range (result->value.character.string[i],
 					kind))
 	  {
-	    gfc_error ("Character %qs in string at %L cannot be converted "
+	    gfc_error_now ("Character %qs in string at %L cannot be converted "
 		       "into character kind %d",
 		       gfc_print_wide_char (result->value.character.string[i]),
 		       &e->where, kind);
Index: gcc/testsuite/gfortran.dg/char_conversion.f90
===================================================================
--- gcc/testsuite/gfortran.dg/char_conversion.f90	(nonexistent)
+++ gcc/testsuite/gfortran.dg/char_conversion.f90	(working copy)
@@ -0,0 +1,6 @@
+! { dg-do compile }
+! PR fortran/78618
+program p
+   character, parameter :: c = char(256,4) ! { dg-error "cannot be converted" }
+   if (rank(c) /= 0) call abort
+end

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