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, Fortran] PR 50070: Segmentation fault at size_binop_loc in fold-const.c


Hi all,

here is a small patch for an ICE-on-invalid problem with COMMON and
character length. I was kinda surprised that we don't catch this
already. The fix is rather simple, but after the amount of discussion
(that I had with myself) in the PR, I probably cannot claim that it
was 'obvious' to me.

In any case, the patch was regtested on x86_64-unknown-linux-gnu. Ok for trunk?

Cheers,
Janus


2011-08-16  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/50070
	* resolve.c (resolve_fl_variable): Reject non-constant character lengths
	in COMMON variables.


2011-08-16  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/50070
	* gfortran.dg/common_13.f90: New.
Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c	(revision 177779)
+++ gcc/fortran/resolve.c	(working copy)
@@ -10169,15 +10169,22 @@ resolve_fl_variable (gfc_symbol *sym, int mp_flag)
 
       if (!gfc_is_constant_expr (e)
 	  && !(e->expr_type == EXPR_VARIABLE
-	       && e->symtree->n.sym->attr.flavor == FL_PARAMETER)
-	  && sym->ns->proc_name
-	  && (sym->ns->proc_name->attr.flavor == FL_MODULE
-	      || sym->ns->proc_name->attr.is_main_program)
-	  && !sym->attr.use_assoc)
+	       && e->symtree->n.sym->attr.flavor == FL_PARAMETER))
 	{
-	  gfc_error ("'%s' at %L must have constant character length "
-		     "in this context", sym->name, &sym->declared_at);
-	  return FAILURE;
+	  if (!sym->attr.use_assoc && sym->ns->proc_name
+	      && (sym->ns->proc_name->attr.flavor == FL_MODULE
+		  || sym->ns->proc_name->attr.is_main_program))
+	    {
+	      gfc_error ("'%s' at %L must have constant character length "
+			"in this context", sym->name, &sym->declared_at);
+	      return FAILURE;
+	    }
+	  if (sym->attr.in_common)
+	    {
+	      gfc_error ("COMMON variable '%s' at %L must have constant "
+			 "character length", sym->name, &sym->declared_at);
+	      return FAILURE;
+	    }
 	}
     }
 
! { dg-do compile }
!
! PR 50070: Segmentation fault at size_binop_loc in fold-const.c
!
! Contributed by Vittorio Zecca <zeccav@gmail.com>

subroutine sub
  common n,z
  integer :: n
  character(len=n) :: z  ! { dg-error "must have constant character length" }
end

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