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]

PATCH: remove unnecessary calls to chkr_set_right()


At present, compilation of this:

foo()
{
    int x = 1;
}

results in a single call to chkr_check_addr().  This is correct, however three spurious calls are made to chkr_set_right() when stacking the args to chkr_check_addr():

foo:
        pushl %ebp
        movl %esp,%ebp
        subl $4,%esp
        pushl %ebx
        leal -4(%ebp),%ebx
        pushl $2
        movl %esp,%eax
        pushl $3
        pushl $4
        pushl %eax
        call chkr_set_right
        addl $12,%esp
        pushl $4
        movl %esp,%eax
        pushl $3
        pushl $4
        pushl %eax
        call chkr_set_right
        addl $12,%esp
        pushl %ebx
        movl %esp,%eax
        pushl $3
        pushl $4
        pushl %eax
        call chkr_set_right
        addl $12,%esp
        call chkr_check_addr
        movl $1,-4(%ebp)
        movl -8(%ebp),%ebx
        movl %ebp,%esp
        popl %ebp
        ret

This patch passes the memcheck testsuite:



        * builtins.c, function.h, calls.c, expr.c, function.c:
          Introduce global int no_chkr_set_right to suppress
          generation of calls to chkr_set_right() when stacking
          args for chkr_check_addr()


Index: builtins.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/builtins.c,v
retrieving revision 1.18
diff -c -3 -p -r1.18 builtins.c
*** builtins.c	1999/10/03 16:08:30	1.18
--- builtins.c	1999/10/23 03:34:24
*************** expand_builtin_memset (exp)
*** 1520,1531 ****
  	   
        /* Just check DST is writable and mark it as readable.  */
        if (current_function_check_memory_usage)
! 	emit_library_call (chkr_check_addr_libfunc, 1, VOIDmode, 3,
! 			   XEXP (dest_mem, 0), Pmode,
! 			   len_rtx, TYPE_MODE (sizetype),
! 			   GEN_INT (MEMORY_USE_WO),
! 			   TYPE_MODE (integer_type_node));
! 
  
        dest_addr = clear_storage (dest_mem, len_rtx, dest_align);
  
--- 1520,1534 ----
  	   
        /* Just check DST is writable and mark it as readable.  */
        if (current_function_check_memory_usage)
!       {
! 	 no_chkr_set_right = 1;
! 	 emit_library_call (chkr_check_addr_libfunc, 1, VOIDmode, 3,
! 			    XEXP (dest_mem, 0), Pmode,
! 			    len_rtx, TYPE_MODE (sizetype),
! 			    GEN_INT (MEMORY_USE_WO),
! 			    TYPE_MODE (integer_type_node));
!          no_chkr_set_right = 0;
!        }
  
        dest_addr = clear_storage (dest_mem, len_rtx, dest_align);
  
Index: function.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/function.h,v
retrieving revision 1.34
diff -c -3 -p -r1.34 function.h
*** function.h	1999/09/26 18:13:28	1.34
--- function.h	1999/10/23 03:34:26
*************** extern struct function *all_functions;
*** 525,530 ****
--- 525,533 ----
  /* The FUNCTION_DECL for an inline function currently being expanded.  */
  extern tree inline_function_decl;
  
+ /* If true, do not emit calls to chkr_set_right() */
+ extern int no_chkr_set_right;
+ 
  /* Given a function decl for a containing function,
     return the `struct function' for it.  */
  struct function *find_function_data PROTO((tree));
Index: calls.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/calls.c,v
retrieving revision 1.64
diff -c -3 -p -r1.64 calls.c
*** calls.c	1999/10/21 16:58:32	1.64
--- calls.c	1999/10/23 03:34:39
*************** expand_call (exp, target, ignore)
*** 2273,2279 ****
  						NULL_RTX)));
  
        /* Mark the memory for the aggregate as write-only.  */
!       if (current_function_check_memory_usage)
  	emit_library_call (chkr_set_right_libfunc, 1,
  			   VOIDmode, 3,
  			   structure_value_addr, Pmode, 
--- 2273,2279 ----
  						NULL_RTX)));
  
        /* Mark the memory for the aggregate as write-only.  */
!       if (current_function_check_memory_usage && ! no_chkr_set_right)
  	emit_library_call (chkr_set_right_libfunc, 1,
  			   VOIDmode, 3,
  			   structure_value_addr, Pmode, 
*************** store_one_arg (arg, argblock, may_be_all
*** 3854,3860 ****
    if (arg->value == arg->stack)
      {
        /* If the value is already in the stack slot, we are done.  */
!       if (current_function_check_memory_usage && GET_CODE (arg->stack) == MEM)
  	{
  	  emit_library_call (chkr_set_right_libfunc, 1, VOIDmode, 3,
  			     XEXP (arg->stack, 0), Pmode, 
--- 3854,3862 ----
    if (arg->value == arg->stack)
      {
        /* If the value is already in the stack slot, we are done.  */
!       if (current_function_check_memory_usage
!           && GET_CODE (arg->stack) == MEM
! 	  && ! no_chkr_set_right)
  	{
  	  emit_library_call (chkr_set_right_libfunc, 1, VOIDmode, 3,
  			     XEXP (arg->stack, 0), Pmode, 
Index: expr.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/expr.c,v
retrieving revision 1.177
diff -c -3 -p -r1.177 expr.c
*** expr.c	1999/10/21 16:58:32	1.177
--- expr.c	1999/10/23 03:35:10
*************** emit_push_insn (x, mode, type, size, ali
*** 2956,2962 ****
  	  move_by_pieces (gen_rtx_MEM (BLKmode, gen_push_operand ()), xinner,
  			  INTVAL (size) - used, align);
  
! 	  if (current_function_check_memory_usage && ! in_check_memory_usage)
  	    {
  	      rtx temp;
  	      
--- 2956,2964 ----
  	  move_by_pieces (gen_rtx_MEM (BLKmode, gen_push_operand ()), xinner,
  			  INTVAL (size) - used, align);
  
! 	  if (current_function_check_memory_usage
! 	      && ! in_check_memory_usage
! 	      && ! no_chkr_set_right)
  	    {
  	      rtx temp;
  	      
*************** emit_push_insn (x, mode, type, size, ali
*** 3013,3019 ****
  								args_addr,
  								args_so_far),
  						  skip));
! 	  if (current_function_check_memory_usage && ! in_check_memory_usage)
  	    {
  	      rtx target;
  	      
--- 3015,3023 ----
  								args_addr,
  								args_so_far),
  						  skip));
! 	  if (current_function_check_memory_usage
! 	      && ! in_check_memory_usage
! 	      && ! no_chkr_set_right)
  	    {
  	      rtx target;
  	      
*************** emit_push_insn (x, mode, type, size, ali
*** 3209,3215 ****
  
        emit_move_insn (gen_rtx_MEM (mode, addr), x);
  
!       if (current_function_check_memory_usage && ! in_check_memory_usage)
  	{
  	  in_check_memory_usage = 1;
  	  if (target == 0)
--- 3213,3221 ----
  
        emit_move_insn (gen_rtx_MEM (mode, addr), x);
  
!       if (current_function_check_memory_usage
!           && ! in_check_memory_usage
! 	  && ! no_chkr_set_right)
  	{
  	  in_check_memory_usage = 1;
  	  if (target == 0)
*************** expand_assignment (to, from, want_value,
*** 3402,3412 ****
--- 3408,3422 ----
  
  	  /* Check the access right of the pointer.  */
  	  if (size)
+ 	  {
+ 	    no_chkr_set_right = 1;
  	    emit_library_call (chkr_check_addr_libfunc, 1, VOIDmode, 3,
  			       to_addr, Pmode,
  			       GEN_INT (size), TYPE_MODE (sizetype),
  			       GEN_INT (MEMORY_USE_WO),
  			       TYPE_MODE (integer_type_node));
+ 	    no_chkr_set_right = 0;
+ 	  }
  	}
  
        result = store_field (to_rtx, bitsize, bitpos, mode1, from,
*************** store_expr (exp, target, want_value)
*** 3755,3770 ****
--- 3765,3786 ----
        && AGGREGATE_TYPE_P (TREE_TYPE (exp)))
      {
        if (GET_CODE (temp) == MEM)
+       {
          emit_library_call (chkr_copy_bitmap_libfunc, 1, VOIDmode, 3,
  			   XEXP (target, 0), Pmode,
  			   XEXP (temp, 0), Pmode,
  			   expr_size (exp), TYPE_MODE (sizetype));
+       }
        else
+       {
+ 	no_chkr_set_right = 1;
          emit_library_call (chkr_check_addr_libfunc, 1, VOIDmode, 3,
  			   XEXP (target, 0), Pmode, 
  			   expr_size (exp), TYPE_MODE (sizetype),
  			   GEN_INT (MEMORY_USE_WO), 
  			   TYPE_MODE (integer_type_node));
+ 	no_chkr_set_right = 0;
+       }
      }
  
    /* If value was not generated in the target, store it there.
*************** store_expr (exp, target, want_value)
*** 3865,3875 ****
--- 3881,3895 ----
  		{
  		  /* Be sure we can write on ADDR.  */
  		  if (current_function_check_memory_usage)
+ 		  {
+ 		    no_chkr_set_right = 1;
  		    emit_library_call (chkr_check_addr_libfunc, 1, VOIDmode, 3,
  				       addr, Pmode,
  				       size, TYPE_MODE (sizetype),
   				       GEN_INT (MEMORY_USE_WO), 
  				       TYPE_MODE (integer_type_node));
+ 		    no_chkr_set_right = 0;
+ 		  }
  #ifdef TARGET_MEM_FUNCTIONS
  		  emit_library_call (memset_libfunc, 0, VOIDmode, 3,
  				     addr, ptr_mode,
*************** expand_expr (exp, target, tmode, modifie
*** 5780,5791 ****
--- 5800,5815 ----
  	  memory_usage = get_memory_usage_from_modifier (modifier);
  
  	  if (memory_usage != MEMORY_USE_DONT)
+ 	  {
+ 	    no_chkr_set_right = 1;
  	    emit_library_call (chkr_check_addr_libfunc, 1, VOIDmode, 3,
  			       XEXP (DECL_RTL (exp), 0), Pmode,
  			       GEN_INT (int_size_in_bytes (type)),
  			       TYPE_MODE (sizetype),
  			       GEN_INT (memory_usage),
  			       TYPE_MODE (integer_type_node));
+ 	    no_chkr_set_right = 0;
+ 	  }
  	}
  
        /* ... fall through ...  */
*************** expand_expr (exp, target, tmode, modifie
*** 6298,6309 ****
--- 6322,6335 ----
              if (memory_usage != MEMORY_USE_DONT)
  	      {
  		in_check_memory_usage = 1;
+ 		no_chkr_set_right = 1;
  		emit_library_call (chkr_check_addr_libfunc, 1, VOIDmode, 3,
  				   op0, Pmode,
  				   GEN_INT (int_size_in_bytes (type)),
  				   TYPE_MODE (sizetype),
  				   GEN_INT (memory_usage),
  				   TYPE_MODE (integer_type_node));
+ 		no_chkr_set_right = 0;
  		in_check_memory_usage = 0;
  	      }
  	  }
*************** expand_expr (exp, target, tmode, modifie
*** 6594,6605 ****
--- 6620,6635 ----
  
          	/* Check the access right of the pointer.  */
  		if (size > BITS_PER_UNIT)
+ 		{
+ 		  no_chkr_set_right = 1;
  		  emit_library_call (chkr_check_addr_libfunc, 1, VOIDmode, 3,
  				     to, Pmode,
  				     GEN_INT (size / BITS_PER_UNIT),
  				     TYPE_MODE (sizetype),
  				     GEN_INT (memory_usage), 
  				     TYPE_MODE (integer_type_node));
+ 		  no_chkr_set_right = 0;
+ 		}
  	      }
  	  }
  
Index: function.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/function.c,v
retrieving revision 1.121
diff -c -3 -p -r1.121 function.c
*** function.c	1999/10/21 16:58:32	1.121
--- function.c	1999/10/23 03:35:37
*************** int current_function_sp_is_unchanging;
*** 112,117 ****
--- 112,120 ----
     sched2) and is useful only if the port defines LEAF_REGISTERS.  */
  int current_function_uses_only_leaf_regs;
  
+ /* If true, do not emit calls to chkr_set_right() */
+ int no_chkr_set_right;
+ 
  /* Nonzero once virtual register instantiation has been done.
     assign_stack_local uses frame_pointer_rtx when this is nonzero.  */
  static int virtuals_instantiated;
*************** put_var_into_stack (decl)
*** 1337,1343 ****
    else
      return;
    
!   if (current_function_check_memory_usage)
      emit_library_call (chkr_set_right_libfunc, 1, VOIDmode, 3,
  		       XEXP (reg, 0), Pmode,
  		       GEN_INT (GET_MODE_SIZE (GET_MODE (reg))),
--- 1340,1346 ----
    else
      return;
    
!   if (current_function_check_memory_usage && ! no_chkr_set_right)
      emit_library_call (chkr_set_right_libfunc, 1, VOIDmode, 3,
  		       XEXP (reg, 0), Pmode,
  		       GEN_INT (GET_MODE_SIZE (GET_MODE (reg))),
*************** assign_parms (fndecl)
*** 4543,4549 ****
  
  	      store_expr (parm, copy, 0);
  	      emit_move_insn (parmreg, XEXP (copy, 0));
! 	      if (current_function_check_memory_usage)
  		emit_library_call (chkr_set_right_libfunc, 1, VOIDmode, 3,
  				   XEXP (copy, 0), Pmode,
  				   GEN_INT (int_size_in_bytes (type)),
--- 4546,4552 ----
  
  	      store_expr (parm, copy, 0);
  	      emit_move_insn (parmreg, XEXP (copy, 0));
! 	      if (current_function_check_memory_usage && ! no_chkr_set_right)
  		emit_library_call (chkr_set_right_libfunc, 1, VOIDmode, 3,
  				   XEXP (copy, 0), Pmode,
  				   GEN_INT (int_size_in_bytes (type)),
*************** assign_parms (fndecl)
*** 4707,4713 ****
  		emit_move_insn (validize_mem (stack_parm),
  				validize_mem (entry_parm));
  	    }
! 	  if (current_function_check_memory_usage)
  	    {
  	      push_to_sequence (conversion_insns);
  	      emit_library_call (chkr_set_right_libfunc, 1, VOIDmode, 3,
--- 4710,4716 ----
  		emit_move_insn (validize_mem (stack_parm),
  				validize_mem (entry_parm));
  	    }
! 	  if (current_function_check_memory_usage && ! no_chkr_set_right)
  	    {
  	      push_to_sequence (conversion_insns);
  	      emit_library_call (chkr_set_right_libfunc, 1, VOIDmode, 3,


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