OSDN Git Service

Make sure that all variable sized adjustments are multiple of preferred
authorhjl <hjl@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 17 Sep 2010 18:00:40 +0000 (18:00 +0000)
committerhjl <hjl@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 17 Sep 2010 18:00:40 +0000 (18:00 +0000)
stack boundary after stack alignment.

gcc/

2010-09-17  H.J. Lu  <hongjiu.lu@intel.com>

PR middle-end/45234
* calls.c (expand_call): Make sure that all variable sized
adjustments are multiple of preferred stack boundary after
stack alignment.

gcc/testsuite/

2010-09-17  H.J. Lu  <hongjiu.lu@intel.com>

PR middle-end/45234
* gcc.dg/torture/stackalign/alloca-5.c: New.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@164377 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/calls.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/stackalign/alloca-5.c [new file with mode: 0644]

index cb1bbd1..5301e8d 100644 (file)
@@ -1,3 +1,10 @@
+2010-09-17  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR middle-end/45234
+       * calls.c (expand_call): Make sure that all variable sized
+       adjustments are multiple of preferred stack boundary after
+       stack alignment.
+
 2010-09-17  DJ Delorie  <dj@redhat.com>
 
        * config/rx/rx.c (rx_print_operand): If __builtin_rx_setpsw() is
index 3888831..b3109ce 100644 (file)
@@ -2385,6 +2385,19 @@ expand_call (tree exp, rtx target, int ignore)
 
   preferred_unit_stack_boundary = preferred_stack_boundary / BITS_PER_UNIT;
 
+  if (SUPPORTS_STACK_ALIGNMENT)
+    {
+      /* All variable sized adjustments must be multiple of preferred
+        stack boundary.  Stack alignment may change preferred stack
+        boundary after variable sized adjustments have been made.  We
+        need to compensate it here.  */
+      unsigned HOST_WIDE_INT delta
+       = ((stack_pointer_delta - pending_stack_adjust)
+          % preferred_unit_stack_boundary);
+      if (delta)
+       anti_adjust_stack (GEN_INT (preferred_unit_stack_boundary - delta));
+    }
+
   /* We want to make two insn chains; one for a sibling call, the other
      for a normal call.  We will select one of the two chains after
      initial RTL generation is complete.  */
index 1552fa1..6bec743 100644 (file)
@@ -1,5 +1,10 @@
 2010-09-17  H.J. Lu  <hongjiu.lu@intel.com>
 
+       PR middle-end/45234
+       * gcc.dg/torture/stackalign/alloca-5.c: New.
+
+2010-09-17  H.J. Lu  <hongjiu.lu@intel.com>
+
        PR middle-end/45678
        * gcc.dg/torture/pr45678-2.c: New.
 
diff --git a/gcc/testsuite/gcc.dg/torture/stackalign/alloca-5.c b/gcc/testsuite/gcc.dg/torture/stackalign/alloca-5.c
new file mode 100644 (file)
index 0000000..a91d3fc
--- /dev/null
@@ -0,0 +1,32 @@
+/* PR middle-end/45234 */
+/* { dg-do run { target { { i?86-*-* x86_64-*-* } && ilp32 } } } */
+/* { dg-options "-m32 -mincoming-stack-boundary=2 -mpreferred-stack-boundary=2" } */
+
+#include "check.h"
+
+void
+__attribute__ ((noinline))
+bar (__float128 f)
+{
+  check (&f, __alignof__(f));
+}
+
+int
+main (void)
+{
+  char *p = __builtin_alloca (6);
+
+  bar (0);
+
+  __builtin_strncpy (p, "good", 5);
+  if (__builtin_strncmp (p, "good", 5) != 0)
+    {
+#ifdef DEBUG
+      p[size] = '\0';
+      printf ("Failed: %s != good\n", p);
+#endif
+     abort ();
+    }
+
+  return 0;
+}