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] Re: fold_builtin_memcpy cannot optimize <retval>?


On Fri, Jan 21, 2005 at 11:51:58AM +0100, Jakub Jelinek wrote:
> The arguments to __builtin_memcpy fail validation (validate_arglist).
> The reason is that second argument in this case is not POINTER_TYPE
> as memcpy requires, but REFERENCE_TYPE.
> 
> Not sure if it is better to just make sure __builtin_memcpy will
> never see a REFERENCE_TYPE argument in this case, or make argument
> validation in builtins.c less strict and for POINTER_TYPE requirements
> allow REFERENCE_TYPEs as well.

The following patch does the former, is that the right fix?

2005-01-21  Jakub Jelinek  <jakub@redhat.com>

	* call.c (build_over_call): Avoid passing REFERENCE_TYPE arguments to
	__builtin_memcpy.

	* g++.dg/tree-ssa/empty-1.C: New test.

--- gcc/cp/call.c.jj	2005-01-18 17:03:09.000000000 +0100
+++ gcc/cp/call.c	2005-01-21 15:35:19.016122583 +0100
@@ -4849,7 +4849,11 @@ build_over_call (struct z_candidate *can
 	  tree args, t;
 
 	  args = tree_cons (NULL, TYPE_SIZE_UNIT (as_base), NULL);
-	  args = tree_cons (NULL, arg, args);
+	  if (TREE_CODE (TREE_TYPE (arg)) == REFERENCE_TYPE)
+	    t = build_unary_op (ADDR_EXPR, fold_if_not_in_template (arg), 0);
+	  else
+	    t = arg;
+	  args = tree_cons (NULL, t, args);
 	  t = build_unary_op (ADDR_EXPR, to, 0);
 	  args = tree_cons (NULL, t, args);
 	  t = implicit_built_in_decls[BUILT_IN_MEMCPY];
--- gcc/testsuite/g++.dg/tree-ssa/empty-1.C.jj	2005-01-21 15:45:06.725456780 +0100
+++ gcc/testsuite/g++.dg/tree-ssa/empty-1.C	2005-01-21 15:46:07.895561667 +0100
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+struct S {};
+S bar(const S &a)
+{
+  S s;
+  s = a;
+  return s;
+}
+
+/* Test whether memcpy call has been optimized out.  */
+/* { dg-final { scan-tree-dump-times "memcpy" 0 "optimized"} } */


	Jakub


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