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]

[3.3 PATCH] Backport builtin arglist construction fixes


The following patch is a backport of my recent mainline bug fixes to the
way that argument lists are constructed/modified in builtins.c.  The
original code uses chainon to modify the original argument lists, which
can cause problems for the compiler and may even have been shared.  The
patch below treats the input arglist immutable and builds a new argument
list rather than modify the old ones in place.


This patch has been tested against the gcc-3_3-branch with a complete
"make bootstrap" on i686-pc-linux-gnu, all languages except treelang,
and regression tested with a top-level "make -k check" with no new
failures.



2003-06-25  Roger Sayle  <roger@eyesopen.com>

	* builtins.c (expand_builtin_strcpy): Construct new argument list
	manually instead of using chainon to modify the original arglist.
	(expand_builtin_strcmp): Likewise.


Index: builtins.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/builtins.c,v
retrieving revision 1.165.2.4
diff -c -3 -p -r1.165.2.4 builtins.c
*** builtins.c	5 May 2003 16:59:13 -0000	1.165.2.4
--- builtins.c	23 Jun 2003 17:33:37 -0000
*************** expand_builtin_strcpy (exp, target, mode
*** 2030,2036 ****
       enum machine_mode mode;
  {
    tree arglist = TREE_OPERAND (exp, 1);
!   tree fn, len;

    if (!validate_arglist (arglist, POINTER_TYPE, POINTER_TYPE, VOID_TYPE))
      return 0;
--- 2030,2036 ----
       enum machine_mode mode;
  {
    tree arglist = TREE_OPERAND (exp, 1);
!   tree fn, len, src, dst;

    if (!validate_arglist (arglist, POINTER_TYPE, POINTER_TYPE, VOID_TYPE))
      return 0;
*************** expand_builtin_strcpy (exp, target, mode
*** 2039,2050 ****
    if (!fn)
      return 0;

!   len = c_strlen (TREE_VALUE (TREE_CHAIN (arglist)));
    if (len == 0)
      return 0;

    len = size_binop (PLUS_EXPR, len, ssize_int (1));
!   chainon (arglist, build_tree_list (NULL_TREE, len));
    return expand_expr (build_function_call_expr (fn, arglist),
  		      target, mode, EXPAND_NORMAL);
  }
--- 2039,2054 ----
    if (!fn)
      return 0;

!   src = TREE_VALUE (TREE_CHAIN (arglist));
!   len = c_strlen (src);
    if (len == 0)
      return 0;

+   dst = TREE_VALUE (arglist);
    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 expand_expr (build_function_call_expr (fn, arglist),
  		      target, mode, EXPAND_NORMAL);
  }
*************** expand_builtin_strcmp (exp, target, mode
*** 2557,2563 ****
    if (!fn)
      return 0;

!   chainon (arglist, build_tree_list (NULL_TREE, len));
    return expand_expr (build_function_call_expr (fn, arglist),
  		      target, mode, EXPAND_NORMAL);
  }
--- 2561,2569 ----
    if (!fn)
      return 0;

!   arglist = build_tree_list (NULL_TREE, len);
!   arglist = tree_cons (NULL_TREE, arg2, arglist);
!   arglist = tree_cons (NULL_TREE, arg1, arglist);
    return expand_expr (build_function_call_expr (fn, arglist),
  		      target, mode, EXPAND_NORMAL);
  }


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]