diff mbox

[i386] : Fix PR 68018, ICE: in ix86_compute_frame_layout on MS_ABI target with -mstackrealign

Message ID CAFULd4aG6+x43ZQCSxUmK_VGZ9ioRHL_f37SaHnpevMLws7A+A@mail.gmail.com
State New
Headers show

Commit Message

Uros Bizjak Oct. 21, 2015, 8:49 a.m. UTC
Hello!

As said in the PR:

-mstackrealign is a new functionality on MS_ABI targets, and there are
some places in the compiler that assume that these targets are always
aligned to 16bytes. This alignment is in fact mandated by ABI, and all
deviations can be considered ABI violations. However, we can relax
this restriction in order to handle rough applications that misalign
the stack, but this should in general be an exception, not the rule.

Even if -mstackrealign can be declared as unsupported on MS_ABI
targets, the infrastructure handles realignment just fine also for
MS_ABI targets, we just need to enable correct code paths when
incoming stack boundary is less than 16 bytes. This is exactly what
the attached patch does.

2015-10-21  Uros Bizjak  <ubizjak@gmail.com>

    PR target/68018
    * config/i386/i386.c (ix86_compute_frame_layout): Realign the stack
    for 64-bit MS_ABI targets also when default incoming stack boundary
    is overriden.

testsuite/ChangeLog:

2015-10-21  Uros Bizjak  <ubizjak@gmail.com>

    PR target/68018
    * gcc.target/i386/pr68018.c: New test.

Patch was bootstrapped and regression tested on x86_64-linux-gnu
{,-m32}, committed to mainline SVN.

Uros.
diff mbox

Patch

Index: testsuite/gcc.target/i386/pr68018.c
===================================================================
--- testsuite/gcc.target/i386/pr68018.c	(revision 0)
+++ testsuite/gcc.target/i386/pr68018.c	(revision 0)
@@ -0,0 +1,10 @@ 
+/* { dg-do compile { target { *-*-linux* && { ! ia32 } } } } */
+/* { dg-options "-O -mabi=ms -mstackrealign" } */
+
+typedef float V __attribute__ ((vector_size (16)));
+
+int fn1 (V * x)
+{
+  V a = *x;
+  return a[0];
+}
Index: config/i386/i386.c
===================================================================
--- config/i386/i386.c	(revision 229110)
+++ config/i386/i386.c	(working copy)
@@ -11271,11 +11271,14 @@  ix86_compute_frame_layout (struct ix86_frame *fram
   frame->nregs = ix86_nsaved_regs ();
   frame->nsseregs = ix86_nsaved_sseregs ();
 
-  /* 64-bit MS ABI seem to require stack alignment to be always 16 except for
-     function prologues and leaf.  */
+  /* 64-bit MS ABI seem to require stack alignment to be always 16,
+     except for function prologues, leaf functions and when the defult
+     incoming stack boundary is overriden at command line or via
+     force_align_arg_pointer attribute.  */
   if ((TARGET_64BIT_MS_ABI && crtl->preferred_stack_boundary < 128)
       && (!crtl->is_leaf || cfun->calls_alloca != 0
-          || ix86_current_function_calls_tls_descriptor))
+	  || ix86_current_function_calls_tls_descriptor
+	  || ix86_incoming_stack_boundary < 128))
     {
       crtl->preferred_stack_boundary = 128;
       crtl->stack_alignment_needed = 128;