[Committed] IBM Z: Fix mode in probe_stack pattern

Andreas Krebbel krebbel@linux.ibm.com
Thu Dec 3 16:08:49 GMT 2020


The probe pattern uses Pmode but the middle-end wants to emit a
word_mode probe check.  This - as usual - breaks on Z with -m31 -mzarch
were word_mode doesn't match Pmode.

Bootstrapped and regression-tested on s390x.

gcc/ChangeLog:

	* config/s390/s390.md ("@probe_stack2<mode>"): Change mode
	iterator to W.

gcc/testsuite/ChangeLog:

	* gcc.target/s390/stack-clash-4.c: New test.
---
 gcc/config/s390/s390.md                       |  6 +++---
 gcc/testsuite/gcc.target/s390/stack-clash-4.c | 10 ++++++++++
 2 files changed, 13 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/s390/stack-clash-4.c

diff --git a/gcc/config/s390/s390.md b/gcc/config/s390/s390.md
index d4cfbdf6732..d6d8965a740 100644
--- a/gcc/config/s390/s390.md
+++ b/gcc/config/s390/s390.md
@@ -11116,8 +11116,8 @@ (define_expand "allocate_stack"
 
 (define_expand "@probe_stack2<mode>"
   [(set (reg:CCZ CC_REGNUM)
-	(compare:CCZ (reg:P 0)
-		     (match_operand 0 "memory_operand")))
+	(compare:CCZ (reg:W 0)
+		     (match_operand:W 0 "memory_operand")))
    (unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)]
   "")
 
@@ -11125,7 +11125,7 @@ (define_expand "probe_stack"
   [(match_operand 0 "memory_operand")]
   ""
 {
-  emit_insn (gen_probe_stack2 (Pmode, operands[0]));
+  emit_insn (gen_probe_stack2 (word_mode, operands[0]));
   DONE;
 })
 
diff --git a/gcc/testsuite/gcc.target/s390/stack-clash-4.c b/gcc/testsuite/gcc.target/s390/stack-clash-4.c
new file mode 100644
index 00000000000..619d99ddf69
--- /dev/null
+++ b/gcc/testsuite/gcc.target/s390/stack-clash-4.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-O1 -m31 -mzarch -fstack-clash-protection" } */
+
+extern void c(char*);
+
+void
+a() {
+  char *b = __builtin_alloca(3);
+  c(b);
+}
-- 
2.28.0



More information about the Gcc-patches mailing list