commit:     0368bcaaca6bc5c7d81426e5b69760063f808cad
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Wed Jun 18 09:05:47 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Wed Jun 18 09:05:47 2025 +0000
URL:        https://gitweb.gentoo.org/proj/gcc-patches.git/commit/?id=0368bcaa

16.0.0: add patch for -fstack-clash-protection vs shrink wrapping

Bug: https://gcc.gnu.org/PR120697
Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...fstack-clash-protection-for-shrink-wrap-s.patch | 89 ++++++++++++++++++++++
 1 file changed, 89 insertions(+)

diff --git 
a/16.0.0/gentoo/85_all_PR120697-x86-Handle-fstack-clash-protection-for-shrink-wrap-s.patch
 
b/16.0.0/gentoo/85_all_PR120697-x86-Handle-fstack-clash-protection-for-shrink-wrap-s.patch
new file mode 100644
index 0000000..08e3c49
--- /dev/null
+++ 
b/16.0.0/gentoo/85_all_PR120697-x86-Handle-fstack-clash-protection-for-shrink-wrap-s.patch
@@ -0,0 +1,89 @@
+https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120697#c12
+
+From 4f80288ecb15195c8baa3e0081354c4cab78db36 Mon Sep 17 00:00:00 2001
+From: Lili Cui <[email protected]>
+Date: Tue, 17 Jun 2025 23:49:03 -0700
+Subject: [PATCH] x86: Handle -fstack-clash-protection for shrink wrap separate
+
+gcc/ChangeLog:
+
+        * config/i386/i386.cc (ix86_expand_prologue):
+       Delete 3 assertions and related code.
+
+gcc/testsuite/ChangeLog:
+
+        * g++.target/i386/shrink_wrap_separate.C:
+               Add -fstack-clash-protection into build options.
+---
+ gcc/config/i386/i386.cc                            | 14 +-------------
+ .../g++.target/i386/shrink_wrap_separate.C         |  2 +-
+ 2 files changed, 2 insertions(+), 14 deletions(-)
+
+diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
+index 3824b533989..6dce7cdfdcb 100644
+--- a/gcc/config/i386/i386.cc
++++ b/gcc/config/i386/i386.cc
+@@ -9234,10 +9234,9 @@ ix86_expand_prologue (void)
+        the stack frame saving one cycle of the prologue.  However, avoid
+        doing this if we have to probe the stack; at least on x86_64 the
+        stack probe can turn into a call that clobbers a red zone location. */
+-      else if ((ix86_using_red_zone ()
++      else if (ix86_using_red_zone ()
+               && (! TARGET_STACK_PROBE
+                   || frame.stack_pointer_offset < CHECK_STACK_LIMIT))
+-             || crtl->shrink_wrapped_separate)
+       {
+         HOST_WIDE_INT allocate_offset;
+         if (crtl->shrink_wrapped_separate)
+@@ -9253,11 +9252,6 @@ ix86_expand_prologue (void)
+ 
+         ix86_emit_save_regs_using_mov (frame.reg_save_offset);
+         int_registers_saved = true;
+-
+-        if (ix86_using_red_zone ()
+-            && (! TARGET_STACK_PROBE
+-                || frame.stack_pointer_offset < CHECK_STACK_LIMIT))
+-          cfun->machine->red_zone_used = true;
+       }
+     }
+ 
+@@ -9377,8 +9371,6 @@ ix86_expand_prologue (void)
+       && flag_stack_clash_protection
+       && !ix86_target_stack_probe ())
+     {
+-      gcc_assert (!crtl->shrink_wrapped_separate);
+-
+       ix86_adjust_stack_and_probe (allocate, int_registers_saved, false);
+       allocate = 0;
+     }
+@@ -9389,8 +9381,6 @@ ix86_expand_prologue (void)
+     {
+       const HOST_WIDE_INT probe_interval = get_probe_interval ();
+ 
+-      gcc_assert (!crtl->shrink_wrapped_separate);
+-
+       if (STACK_CHECK_MOVING_SP)
+       {
+         if (crtl->is_leaf
+@@ -9447,8 +9437,6 @@ ix86_expand_prologue (void)
+   else if (!ix86_target_stack_probe ()
+          || frame.stack_pointer_offset < CHECK_STACK_LIMIT)
+     {
+-      gcc_assert (!crtl->shrink_wrapped_separate);
+-
+       pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
+                                GEN_INT (-allocate), -1,
+                                m->fs.cfa_reg == stack_pointer_rtx);
+diff --git a/gcc/testsuite/g++.target/i386/shrink_wrap_separate.C 
b/gcc/testsuite/g++.target/i386/shrink_wrap_separate.C
+index 294dccde5d3..a1772c3a396 100644
+--- a/gcc/testsuite/g++.target/i386/shrink_wrap_separate.C
++++ b/gcc/testsuite/g++.target/i386/shrink_wrap_separate.C
+@@ -1,5 +1,5 @@
+ /* { dg-do compile } */
+-/* { dg-options "-O2 -fdump-rtl-pro_and_epilogue" } */
++/* { dg-options "-O2 -fstack-clash-protection -fdump-rtl-pro_and_epilogue" } 
*/
+ typedef struct a b;
+ typedef double c;
+ struct a {
+-- 
+2.34.1

Reply via email to