Patchwork Fix x86_64 va_arg (PR target/45843)

login
register
mail settings
Submitter Jakub Jelinek
Date Sept. 30, 2010, 7:13 p.m.
Message ID <20100930191345.GM10599@tyan-ft48-01.lab.bos.redhat.com>
Download mbox | patch
Permalink /patch/66237/
State New
Headers show

Comments

Jakub Jelinek - Sept. 30, 2010, 7:13 p.m.
Hi!

On the attached testcase the first 8 bytes of the struct are NOCLASS, thus
construct_container returns a PARALLEL that starts at 8 bytes.  The check
for last incomplete chunk weren't expecting this.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux.
Ok for trunk and release branches?

2010-09-30  Jakub Jelinek  <jakub@redhat.com>

	PR target/45843
	* config/i386/i386.c (ix86_gimplify_va_arg): Use
	INTVAL (XEXP (slot, 1)) as prev_size.

	* g++.dg/torture/pr45843.C: New test.


	Jakub
Richard Henderson - Sept. 30, 2010, 8:19 p.m.
> 	PR target/45843
> 	* config/i386/i386.c (ix86_gimplify_va_arg): Use
> 	INTVAL (XEXP (slot, 1)) as prev_size.
> 
> 	* g++.dg/torture/pr45843.C: New test.

Ok.


r~

Patch

--- gcc/config/i386/i386.c.jj	2010-09-22 17:15:39.000000000 +0200
+++ gcc/config/i386/i386.c	2010-09-30 14:39:46.000000000 +0200
@@ -7502,6 +7502,8 @@  ix86_gimplify_va_arg (tree valist, tree 
 	      tree dest_addr, dest;
 	      int cur_size = GET_MODE_SIZE (mode);
 
+	      gcc_assert (prev_size <= INTVAL (XEXP (slot, 1)));
+	      prev_size = INTVAL (XEXP (slot, 1));
 	      if (prev_size + cur_size > size)
 		{
 		  cur_size = size - prev_size;
@@ -7534,7 +7536,7 @@  ix86_gimplify_va_arg (tree valist, tree 
 
 	      dest_addr = fold_convert (daddr_type, addr);
 	      dest_addr = fold_build2 (POINTER_PLUS_EXPR, daddr_type, dest_addr,
-				       size_int (INTVAL (XEXP (slot, 1))));
+				       size_int (prev_size));
 	      if (cur_size == GET_MODE_SIZE (mode))
 		{
 		  src = build_va_arg_indirect_ref (src_addr);
--- gcc/testsuite/g++.dg/torture/pr45843.C.jj	2010-09-30 14:45:54.000000000 +0200
+++ gcc/testsuite/g++.dg/torture/pr45843.C	2010-09-30 14:45:33.000000000 +0200
@@ -0,0 +1,28 @@ 
+// PR target/45843
+// { dg-do run }
+
+#include <stdarg.h>
+
+extern "C" void abort ();
+struct S { struct T { } a[14]; char b; };
+struct S arg, s;
+
+void
+foo (int z, ...)
+{
+  char c;
+  va_list ap;
+  va_start (ap, z);
+  c = 'a';
+  arg = va_arg (ap, struct S);
+  if (c != 'a')
+    abort ();
+  va_end (ap);
+}
+
+int
+main ()
+{
+  foo (1, s);
+  return 0;
+}