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] PR29371 Coredump when using -fbounds-check with pointer & nullify


:ADDPATCH fortran:

This problem is quite specific to NULLIFY or the pointer assignment
of NULL() when -fbounds-check is used.  The code shows that a temporary
for the index expression, which is produced by the bounds check, is used
before it is set.  The reason for this is that the expression is added
to the block, followed by the se->pre, which carries the code associated
with bounds checking. The patch is easy; change &block to &se->pre, so
that everything happens in the right order.

The test case is that of the reporter.

Regtested on amd64/Cygwin_NT - OK for trunk?

It is probable that this patch has gained some whitespace problems
because of the way in which it was transmitted (copy and paste to a
Citrix client - my ISP mail server is down.).

Paul

2006-10-12 Paul Thomas <pault@gcc.gnu.org>

	PR fortran/29371
	* trans-expr.c.c (gfc_trans_pointer_assignment): Add the expression
	for the assignment of null to the data field to se->pre, rather
	than block.	

2006-10-12 Paul Thomas <pault@gcc.gnu.org>

	PR fortran/29371
	* gfortran.dg/nullify_3.f90: New test.


Index: gcc/fortran/trans-expr.c
===================================================================
*** gcc/fortran/trans-expr.c	(revision 117614)
--- gcc/fortran/trans-expr.c	(working copy)
*************** gfc_trans_pointer_assignment (gfc_expr *
*** 3149,3155 ****
  	{
  	case EXPR_NULL:
  	  /* Just set the data pointer to null.  */
! 	  gfc_conv_descriptor_data_set (&block, lse.expr, null_pointer_node);
  	  break;
  
  	case EXPR_VARIABLE:
--- 3149,3155 ----
  	{
  	case EXPR_NULL:
  	  /* Just set the data pointer to null.  */
! 	  gfc_conv_descriptor_data_set (&lse.pre, lse.expr, null_pointer_node);
  	  break;
  
  	case EXPR_VARIABLE:
Index: gcc/testsuite/gfortran.dg/nullify_3.f90
===================================================================
*** gcc/testsuite/gfortran.dg/nullify_3.f90	(revision 0)
--- gcc/testsuite/gfortran.dg/nullify_3.f90	(revision 0)
***************
*** 0 ****
--- 1,26 ----
+ ! { dg-do run }
+ ! { dg-options "-O0 -fbounds-check" }
+ ! Tests patch for PR29371, in which the null pointer
+ ! assignment would cause a segfault with the bounds
+ ! check on.
+ !
+ ! Contributed by Tobias Burnus <tobias.burnus@physik.fu-berlin.de>
+ !
+ program test
+   implicit none
+   type projector_t
+     real,   pointer :: ket(:, :), bra(:, :)
+   end type projector_t
+ 
+   type(projector_t),pointer, dimension(:) :: p
+   integer :: stat,i
+   allocate(p(2),stat=stat)
+   do i = 1, 2
+         nullify(p(i)%bra)
+         nullify(p(i)%ket)
+   end do
+   do i = 1, 2
+         if (associated (p(i)%bra)) call abort ()
+         if (associated (p(i)%ket)) call abort ()
+   end do
+ end program


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