re PR middle-end/8028 (__builtin_apply() passes wrong arguments)
authorEric Botcazou <ebotcazou@libertysurf.fr>
Thu, 27 Nov 2003 05:20:11 +0000 (06:20 +0100)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Thu, 27 Nov 2003 05:20:11 +0000 (05:20 +0000)
PR middle-end/8028
PR middle-end/9890
PR middle-end/11151
PR middle-end/12210
PR middle-end/12503
PR middle-end/12692
* builtins.c (expand_builtin_apply): Use virtual_outgoing_args_rtx
as the base address to copy the memory arguments to.

From-SVN: r73976

gcc/ChangeLog
gcc/builtins.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/builtin-apply2.c [new file with mode: 0644]

index 7c9c3846746e2059b44f1138988c3b0354f29a5d..f68c34b8c57811a2db678148c931cc3313dbae6c 100644 (file)
@@ -1,3 +1,14 @@
+2003-11-27  Eric Botcazou  <ebotcazou@libertysurf.fr>
+
+       PR middle-end/8028
+       PR middle-end/9890
+       PR middle-end/11151
+       PR middle-end/12210
+       PR middle-end/12503
+       PR middle-end/12692
+       * builtins.c (expand_builtin_apply): Use virtual_outgoing_args_rtx
+       as the base address to copy the memory arguments to.
+
 2003-11-26  Danny Smith  <dannysmith@users.sourceforge.net>
 
        * config/i386/cygming.h (ASM_OUTPUT_DEF_FROM_DECLS): Declare
index 7ff87899925109bd4215a479d316c68f72b8ec5a..a48c5af9a5437787c761ff85e54ab410f3f616ac 100644 (file)
@@ -1219,12 +1219,16 @@ expand_builtin_apply (rtx function, rtx arguments, rtx argsize)
 #endif
     emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
 
-  /* Push a block of memory onto the stack to store the memory arguments.
-     Save the address in a register, and copy the memory arguments.  ??? I
-     haven't figured out how the calling convention macros effect this,
-     but it's likely that the source and/or destination addresses in
-     the block copy will need updating in machine specific ways.  */
-  dest = allocate_dynamic_stack_space (argsize, 0, BITS_PER_UNIT);
+  /* Allocate a block of memory onto the stack and copy the memory
+     arguments to the outgoing arguments address.  */
+  allocate_dynamic_stack_space (argsize, 0, BITS_PER_UNIT);
+  dest = virtual_outgoing_args_rtx;
+#ifndef STACK_GROWS_DOWNWARD
+  if (GET_CODE (argsize) == CONST_INT)
+    dest = plus_constant (dest, -INTVAL (argsize));
+  else
+    dest = gen_rtx_PLUS (Pmode, dest, negate_rtx (Pmode, argsize));
+#endif
   dest = gen_rtx_MEM (BLKmode, dest);
   set_mem_align (dest, PARM_BOUNDARY);
   src = gen_rtx_MEM (BLKmode, incoming_args);
index 4b8fe13c88f72153b4c244d4e409becf69d294c5..20faca0c1f57c830f7596f9d047790cdf8c8aff4 100644 (file)
@@ -1,3 +1,7 @@
+2003-11-27  Eric Botcazou  <ebotcazou@libertysurf.fr>
+
+       * gcc.dg/builtin-apply2.c: New test.
+
 2003-11-26  Eric Botcazou  <ebotcazou@libertysurf.fr>
 
        * gcc.c-torture/compile/20031023-4.c: Don't XFAIL on SPARC64.
diff --git a/gcc/testsuite/gcc.dg/builtin-apply2.c b/gcc/testsuite/gcc.dg/builtin-apply2.c
new file mode 100644 (file)
index 0000000..56b27a1
--- /dev/null
@@ -0,0 +1,39 @@
+/* PR target/12503 */
+/* Origin: <pierre.nguyen-tuong@asim.lip6.fr> */
+
+/* Verify that __builtin_apply behaves correctly on targets
+   with pre-pushed arguments (e.g. SPARC).  */
+
+/* { dg-do run } */
+   
+
+#define INTEGER_ARG  5
+
+typedef __SIZE_TYPE__ size_t;
+
+extern void abort(void);
+
+void foo(char *name, double d, double e, double f, int g)
+{
+  if (g != INTEGER_ARG)
+    abort();
+}
+
+void bar(char *name, ...)
+{
+  size_t size;
+  void *arguments;
+
+  size = sizeof(char *) + 3 * sizeof(double) + sizeof(int);
+
+  arguments = __builtin_apply_args();
+
+  __builtin_apply(foo, arguments, size);
+}
+
+int main(void)
+{
+  bar("eeee", 5.444567, 8.90765, 4.567789, INTEGER_ARG);
+
+  return 0;
+}