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] PR29392 -Segfault on data character initialization


:ADDPATCH fortran:

The fix here was simple... literally. The expression for the substring start and end needed copying, so that it doesn't get frozen for one value of the iterator, and simplifying. The testcase is that of the reporter.

Regtested on PIV/Cygwin_NT - OK for trunk?

Paul


Index: gcc/fortran/ChangeLog
===================================================================
*** gcc/fortran/ChangeLog	(révision 117568)
--- gcc/fortran/ChangeLog	(copie de travail)
***************
*** 1,3 ****
--- 1,10 ----
+ 2006-10-16  Paul Thomas  <pault@gcc.gnu.org>
+ 
+ 	PR fortran/29392
+ 	* data.c (create_character_intializer): Copy and simplify
+ 	the expressions for the start and end of a sub-string
+ 	reference.
+ 
  2006-10-08  Erik Edelmann <edelmann@gcc.gnu.org>
  	    Paul Thomas <pault@gcc.gnu.org>
  
Index: gcc/fortran/data.c
===================================================================
*** gcc/fortran/data.c	(révision 117568)
--- gcc/fortran/data.c	(copie de travail)
*************** create_character_intializer (gfc_expr * 
*** 167,179 ****
  
    if (ref)
      {
        gcc_assert (ref->type == REF_SUBSTRING);
  
        /* Only set a substring of the destination.  Fortran substring bounds
           are one-based [start, end], we want zero based [start, end).  */
!       gfc_extract_int (ref->u.ss.start, &start);
        start--;
!       gfc_extract_int (ref->u.ss.end, &end);
      }
    else
      {
--- 167,192 ----
  
    if (ref)
      {
+       gfc_expr *start_expr, *end_expr;
+ 
        gcc_assert (ref->type == REF_SUBSTRING);
  
        /* Only set a substring of the destination.  Fortran substring bounds
           are one-based [start, end], we want zero based [start, end).  */
!       start_expr = gfc_copy_expr (ref->u.ss.start);
!       end_expr = gfc_copy_expr (ref->u.ss.end);
! 
!       if ((gfc_simplify_expr (start_expr, 1) == FAILURE)
! 	     || (gfc_simplify_expr (end_expr, 1)) == FAILURE)
! 	{
! 	  gfc_error ("failure to simplify substring reference in DATA"
! 		     "statement at %L", &ref->u.ss.start->where);
! 	  return NULL;
! 	}
! 
!       gfc_extract_int (start_expr, &start);
        start--;
!       gfc_extract_int (end_expr, &end);
      }
    else
      {
Index: gcc/testsuite/ChangeLog
===================================================================
*** gcc/testsuite/ChangeLog	(révision 117568)
--- gcc/testsuite/ChangeLog	(copie de travail)
***************
*** 1,3 ****
--- 1,8 ----
+ 2006-10-16  Paul Thomas  <pault@gcc.gnu.org>
+ 
+ 	PR fortran/29392
+ 	* gfortran.dg/data_char_3.f90: New test.
+ 
  2006-10-08  Erik Edelmann  <edelmann@gcc.gnu.org>
  	    Paul Thomas  <pault@gcc.gnu.org>
  
Index: gcc/testsuite/gfortran.dg/data_char_3.f90
===================================================================
*** gcc/testsuite/gfortran.dg/data_char_3.f90	(révision 0)
--- gcc/testsuite/gfortran.dg/data_char_3.f90	(révision 0)
***************
*** 0 ****
--- 1,11 ----
+ ! { dg-do run }
+ ! { dg-options "-O2" }
+ ! Tests the fix PR29392, in which the iterator valued substring
+ ! reference would cause a segfault.
+ !
+ ! Contributed by Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>   
+ !
+   character(LEN=2) :: a(2) 
+   data ((a(I)(k:k),I=1,2),k=1,2) /2*'a',2*'z'/ 
+   IF (ANY(a.NE."az")) CALL ABORT() 
+   END 

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