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]

[Committed] Avoid use of chainon in simplify_builtin_strcpy


The following patch removes the use of "chainon" from the function
simplify_builtin_strcpy.  This usage modifies the strcpy's argument
list in-place to append an additional length argument suitable for
calling memcpy.  However, the middle-end's fold and simplify machinery
should avoid modifying the original trees, which may be shared or
continue to be used if the returned tree isn't suitable (non-gimple).

The original use of chainon in expand_builtin_strcpy was previously
removed by a similar patch.  This just does the same here.


This patch was tested on i686-pc-linux-gnu with a complete "make
bootstrap", all current languages, and regression tested with a
top-level "make -k check" with no new failures.


2004-05-15  Roger Sayle  <roger@eyesopen.com>

	* builtins.c (simplify_builtin_strcpy): Avoid use of chainon, so
	that simplify_builtin doesn't destructively modify its argument.


Index: builtins.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/builtins.c,v
retrieving revision 1.322
diff -c -3 -p -r1.322 builtins.c
*** builtins.c	13 May 2004 06:39:27 -0000	1.322
--- builtins.c	15 May 2004 14:19:06 -0000
*************** simplify_builtin_strpbrk (tree arglist)
*** 8298,8304 ****
  tree
  simplify_builtin_strcpy (tree arglist, tree len)
  {
!   tree fn;

    if (!validate_arglist (arglist, POINTER_TYPE, POINTER_TYPE, VOID_TYPE))
      return 0;
--- 8298,8304 ----
  tree
  simplify_builtin_strcpy (tree arglist, tree len)
  {
!   tree fn, src, dst;

    if (!validate_arglist (arglist, POINTER_TYPE, POINTER_TYPE, VOID_TYPE))
      return 0;
*************** simplify_builtin_strcpy (tree arglist, t
*** 8307,8323 ****
    if (!fn)
      return 0;

    if (!len)
      {
!       len = c_strlen (TREE_VALUE (TREE_CHAIN (arglist)), 1);
!       if (!len)
! 	return 0;
!       if (TREE_SIDE_EFFECTS (len))
  	return 0;
      }

    len = size_binop (PLUS_EXPR, len, ssize_int (1));
!   chainon (arglist, build_tree_list (NULL_TREE, len));
    return build_function_call_expr (fn, arglist);
  }

--- 8307,8326 ----
    if (!fn)
      return 0;

+   src = TREE_VALUE (TREE_CHAIN (arglist));
+   dst = TREE_VALUE (arglist);
+
    if (!len)
      {
!       len = c_strlen (src, 1);
!       if (!len || TREE_SIDE_EFFECTS (len))
  	return 0;
      }

    len = size_binop (PLUS_EXPR, len, ssize_int (1));
!   arglist = build_tree_list (NULL_TREE, len);
!   arglist = tree_cons (NULL_TREE, src, arglist);
!   arglist = tree_cons (NULL_TREE, dst, arglist);
    return build_function_call_expr (fn, arglist);
  }


Roger
--
Roger Sayle,                         E-mail: roger@eyesopen.com
OpenEye Scientific Software,         WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road,     Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507.         Fax: (+1) 505-473-0833


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