https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78444

--- Comment #12 from Iain Sandoe <iains at gcc dot gnu.org> ---
So i've tested this on Darwin
- and doing x86_64-linux now;

along with the change, I removed 'profile_flag' hack and added 

+  /* If we're profiling, we don't have a leaf.  */
+  gcc_assert (!crtl->is_leaf || !crtl->profile);

to ix86_compute_frame_layout(),

I haven't seen the assert fire on Darwin and the subq $8 is correctly => subq
$16.  Suppose that a test case will need a scanasm, making an executable one
would be fiddly.

---

    [patch] Fix PR78444, update stack aligment for non-leaf functions.

diff --git a/gcc/config/i386/darwin.h b/gcc/config/i386/darwin.h
index 1ea5dc3..53789e7 100644
--- a/gcc/config/i386/darwin.h
+++ b/gcc/config/i386/darwin.h
@@ -111,9 +111,6 @@ extern int darwin_emit_branch_islands;
 /* On Darwin, the stack is 128-bit aligned at the point of every call.
    Failure to ensure this will lead to a crash in the system libraries
    or dynamic loader.  */
-#undef STACK_BOUNDARY
-#define STACK_BOUNDARY \
-  ((profile_flag || TARGET_64BIT_MS_ABI) ? 128 : BITS_PER_WORD)

 #undef MAIN_STACK_BOUNDARY
 #define MAIN_STACK_BOUNDARY 128
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index c18c60a..842dfdf 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -11154,8 +11154,13 @@ ix86_compute_frame_layout (void)
   /* 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)
+     force_align_arg_pointer attribute.
+
+     Darwin's ABI specifies 128b alignment for both 32 and  64 bit variants
+     at call sites.
+ */
+  if (((TARGET_64BIT_MS_ABI || TARGET_MACHO)
+        && crtl->preferred_stack_boundary < 128)
       && (!crtl->is_leaf || cfun->calls_alloca != 0
          || ix86_current_function_calls_tls_descriptor
          || ix86_incoming_stack_boundary < 128))
@@ -11164,6 +11169,8 @@ ix86_compute_frame_layout (void)
       crtl->stack_alignment_needed = 128;
     }

+  /* If we're profiling, we don't have a leaf.  */
+  gcc_assert (!crtl->is_leaf || !crtl->profile);
   stack_alignment_needed = crtl->stack_alignment_needed / BITS_PER_UNIT;
   preferred_alignment = crtl->preferred_stack_boundary / BITS_PER_UNIT;

Reply via email to