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]

[Fortran, patch] PR 38095 - Fix segfault in gfc_map_intrinsic_function


Hi all,

the following patch is close to trivial: If arg1->ts.cl->length == NULL
then one should not access arg1->ts.cl->length->expr_type.

Build and regtested on x86-64-linux.
OK for the trunk?

Tobias
2008-11-16  Tobias Burnus  <burnus@net-b.de>

	PR fortran/38095
	* trans-expr.c (gfc_map_intrinsic_function): Fix pointer access.

2008-11-16  Tobias Burnus  <burnus@net-b.de>

	PR fortran/38095
	* gfortran.dg/char_length_13.f90: New test.

Index: gcc/fortran/trans-expr.c
===================================================================
--- gcc/fortran/trans-expr.c	(Revision 141913)
+++ gcc/fortran/trans-expr.c	(Arbeitskopie)
@@ -1921,8 +1921,9 @@ gfc_map_intrinsic_function (gfc_expr *ex
     case GFC_ISYM_LEN:
       /* TODO figure out why this condition is necessary.  */
       if (sym->attr.function
-	    && arg1->ts.cl->length->expr_type != EXPR_CONSTANT
-	    && arg1->ts.cl->length->expr_type != EXPR_VARIABLE)
+	  && (arg1->ts.cl->length == NULL
+	      || (arg1->ts.cl->length->expr_type != EXPR_CONSTANT
+		  && arg1->ts.cl->length->expr_type != EXPR_VARIABLE)))
 	return false;
 
       new_expr = gfc_copy_expr (arg1->ts.cl->length);
Index: gcc/testsuite/gfortran.dg/char_length_13.f90
===================================================================
--- gcc/testsuite/gfortran.dg/char_length_13.f90	(Revision 0)
+++ gcc/testsuite/gfortran.dg/char_length_13.f90	(Revision 0)
@@ -0,0 +1,36 @@
+! { dg-do compile }
+!
+! PR fortran/38095
+!
+! Contributed by Vivek Rao
+!
+! Compiling the program below gave an ICE
+!
+module bar
+  implicit none
+contains
+elemental function trim_append(xx,yy) result(xy)
+  character (len=*), intent(in) :: xx,yy
+  character (len=len(xx) + len(yy)) :: xy
+  xy = trim(xx) // yy
+end function trim_append
+function same(xx) result(yy)
+  character (len=*), intent(in) :: xx(:)
+  character (len=len(xx))       :: yy(size(xx))
+  yy = [xx]
+end function same
+subroutine foo(labels)
+  character (len=*), intent(in) :: labels(:)
+  print*,"size(labels)=",size(labels)
+end subroutine foo
+subroutine xmain()
+  call foo(trim_append(["a"],same(["b"])))
+end subroutine xmain
+end module bar
+
+program main
+  use bar
+  call xmain()
+end program main
+
+! { dg-final { cleanup-modules "bar" } }

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