|
|
22033d |
PR middle-end/83654
|
|
|
22033d |
* explow.c (anti_adjust_stack_and_probe_stack_clash): Test a
|
|
|
22033d |
non-constant residual for zero at runtime and avoid probing in
|
|
|
22033d |
that case. Reorganize code for trailing problem to mirror handling
|
|
|
22033d |
of the residual.
|
|
|
22033d |
|
|
|
22033d |
PR middle-end/83654
|
|
|
22033d |
* gcc.target/i386/stack-check-18.c: New test.
|
|
|
22033d |
* gcc.target/i386/stack-check-19.c: New test.
|
|
|
22033d |
|
|
|
22033d |
diff --git a/gcc/explow.c b/gcc/explow.c
|
|
|
22033d |
index b6c56602152..042e71904ec 100644
|
|
|
22033d |
--- a/gcc/explow.c
|
|
|
22033d |
+++ b/gcc/explow.c
|
|
|
22033d |
@@ -1997,11 +1997,27 @@ anti_adjust_stack_and_probe_stack_clash (rtx size)
|
|
|
22033d |
|
|
|
22033d |
if (residual != CONST0_RTX (Pmode))
|
|
|
22033d |
{
|
|
|
22033d |
+ rtx label = NULL_RTX;
|
|
|
22033d |
+ /* RESIDUAL could be zero at runtime and in that case *sp could
|
|
|
22033d |
+ hold live data. Furthermore, we do not want to probe into the
|
|
|
22033d |
+ red zone.
|
|
|
22033d |
+
|
|
|
22033d |
+ Go ahead and just guard the probe at *sp on RESIDUAL != 0 at
|
|
|
22033d |
+ runtime if RESIDUAL is not a compile time constant. */
|
|
|
22033d |
+ if (!CONST_INT_P (residual))
|
|
|
22033d |
+ {
|
|
|
22033d |
+ label = gen_label_rtx ();
|
|
|
22033d |
+ emit_cmp_and_jump_insns (residual, CONST0_RTX (GET_MODE (residual)),
|
|
|
22033d |
+ EQ, NULL_RTX, Pmode, 1, label);
|
|
|
22033d |
+ }
|
|
|
22033d |
+
|
|
|
22033d |
rtx x = force_reg (Pmode, plus_constant (Pmode, residual,
|
|
|
22033d |
-GET_MODE_SIZE (word_mode)));
|
|
|
22033d |
anti_adjust_stack (residual);
|
|
|
22033d |
emit_stack_probe (gen_rtx_PLUS (Pmode, stack_pointer_rtx, x));
|
|
|
22033d |
emit_insn (gen_blockage ());
|
|
|
22033d |
+ if (!CONST_INT_P (residual))
|
|
|
22033d |
+ emit_label (label);
|
|
|
22033d |
}
|
|
|
22033d |
|
|
|
22033d |
/* Some targets make optimistic assumptions in their prologues about
|
|
|
22033d |
@@ -2014,28 +2030,20 @@ anti_adjust_stack_and_probe_stack_clash (rtx size)
|
|
|
22033d |
live data. Furthermore, we don't want to probe into the red
|
|
|
22033d |
zone.
|
|
|
22033d |
|
|
|
22033d |
- Go ahead and just guard a probe at *sp on SIZE != 0 at runtime
|
|
|
22033d |
+ Go ahead and just guard the probe at *sp on SIZE != 0 at runtime
|
|
|
22033d |
if SIZE is not a compile time constant. */
|
|
|
22033d |
-
|
|
|
22033d |
- /* Ideally we would just probe at *sp. However, if SIZE is not
|
|
|
22033d |
- a compile-time constant, but is zero at runtime, then *sp
|
|
|
22033d |
- might hold live data. So probe at *sp if we know that
|
|
|
22033d |
- an allocation was made, otherwise probe into the red zone
|
|
|
22033d |
- which is obviously undesirable. */
|
|
|
22033d |
- if (CONST_INT_P (size))
|
|
|
22033d |
- {
|
|
|
22033d |
- emit_stack_probe (stack_pointer_rtx);
|
|
|
22033d |
- emit_insn (gen_blockage ());
|
|
|
22033d |
- }
|
|
|
22033d |
- else
|
|
|
22033d |
+ rtx label = NULL_RTX;
|
|
|
22033d |
+ if (!CONST_INT_P (size))
|
|
|
22033d |
{
|
|
|
22033d |
- rtx label = gen_label_rtx ();
|
|
|
22033d |
+ label = gen_label_rtx ();
|
|
|
22033d |
emit_cmp_and_jump_insns (size, CONST0_RTX (GET_MODE (size)),
|
|
|
22033d |
EQ, NULL_RTX, Pmode, 1, label);
|
|
|
22033d |
- emit_stack_probe (stack_pointer_rtx);
|
|
|
22033d |
- emit_insn (gen_blockage ());
|
|
|
22033d |
- emit_label (label);
|
|
|
22033d |
}
|
|
|
22033d |
+
|
|
|
22033d |
+ emit_stack_probe (stack_pointer_rtx);
|
|
|
22033d |
+ emit_insn (gen_blockage ());
|
|
|
22033d |
+ if (!CONST_INT_P (size))
|
|
|
22033d |
+ emit_label (label);
|
|
|
22033d |
}
|
|
|
22033d |
}
|
|
|
22033d |
|
|
|
22033d |
diff --git a/gcc/testsuite/gcc.target/i386/stack-check-18.c b/gcc/testsuite/gcc.target/i386/stack-check-18.c
|
|
|
22033d |
new file mode 100644
|
|
|
22033d |
index 00000000000..6dbff4402da
|
|
|
22033d |
--- /dev/null
|
|
|
22033d |
+++ b/gcc/testsuite/gcc.target/i386/stack-check-18.c
|
|
|
22033d |
@@ -0,0 +1,23 @@
|
|
|
22033d |
+/* { dg-do compile } */
|
|
|
22033d |
+/* { dg-options "-O2 -fstack-clash-protection -mtune=generic -fdump-rtl-expand" } */
|
|
|
22033d |
+/* { dg-require-effective-target supports_stack_clash_protection } */
|
|
|
22033d |
+
|
|
|
22033d |
+int f1 (char *);
|
|
|
22033d |
+
|
|
|
22033d |
+int
|
|
|
22033d |
+f2 (void)
|
|
|
22033d |
+{
|
|
|
22033d |
+ const int size = 4096;
|
|
|
22033d |
+ char buffer[size];
|
|
|
22033d |
+ return f1 (buffer);
|
|
|
22033d |
+}
|
|
|
22033d |
+
|
|
|
22033d |
+/* So we want to verify that at expand time that we probed the main
|
|
|
22033d |
+ VLA allocation as well as the residuals. Then we want to verify
|
|
|
22033d |
+ there was only one probe in the final assembly (implying the
|
|
|
22033d |
+ residual probe was optimized away). */
|
|
|
22033d |
+/* { dg-final { scan-rtl-dump-times "allocation and probing in loop" 1 "expand" } } */
|
|
|
22033d |
+/* { dg-final { scan-rtl-dump-times "allocation and probing residuals" 1 "expand" } } */
|
|
|
22033d |
+
|
|
|
22033d |
+/* { dg-final { scan-assembler-times "or\[ql\]" 1 } } */
|
|
|
22033d |
+
|
|
|
22033d |
diff --git a/gcc/testsuite/gcc.target/i386/stack-check-19.c b/gcc/testsuite/gcc.target/i386/stack-check-19.c
|
|
|
22033d |
new file mode 100644
|
|
|
22033d |
index 00000000000..b92c126d57f
|
|
|
22033d |
--- /dev/null
|
|
|
22033d |
+++ b/gcc/testsuite/gcc.target/i386/stack-check-19.c
|
|
|
22033d |
@@ -0,0 +1,29 @@
|
|
|
22033d |
+/* { dg-do compile } */
|
|
|
22033d |
+/* { dg-options "-O2 -fstack-clash-protection -mtune=generic -fdump-rtl-expand" } */
|
|
|
22033d |
+/* { dg-require-effective-target supports_stack_clash_protection } */
|
|
|
22033d |
+
|
|
|
22033d |
+int f1 (char *);
|
|
|
22033d |
+
|
|
|
22033d |
+int
|
|
|
22033d |
+f2 (const int size)
|
|
|
22033d |
+{
|
|
|
22033d |
+ char buffer[size];
|
|
|
22033d |
+ return f1 (buffer);
|
|
|
22033d |
+}
|
|
|
22033d |
+
|
|
|
22033d |
+/* So we want to verify that at expand time that we probed the main
|
|
|
22033d |
+ VLA allocation as well as the residuals. Then we want to verify
|
|
|
22033d |
+ there are two probes in the final assembly code. */
|
|
|
22033d |
+/* { dg-final { scan-rtl-dump-times "allocation and probing in loop" 1 "expand" } } */
|
|
|
22033d |
+/* { dg-final { scan-rtl-dump-times "allocation and probing residuals" 1 "expand" } } */
|
|
|
22033d |
+/* { dg-final { scan-assembler-times "or\[ql\]" 2 } } */
|
|
|
22033d |
+
|
|
|
22033d |
+/* We also want to verify (indirectly) that the residual probe is
|
|
|
22033d |
+ guarded. We do that by checking the number of conditional
|
|
|
22033d |
+ branches. There should be 3. One that bypasses the probe loop, one
|
|
|
22033d |
+ in the probe loop and one that bypasses the residual probe.
|
|
|
22033d |
+
|
|
|
22033d |
+ These will all be equality tests. */
|
|
|
22033d |
+/* { dg-final { scan-assembler-times "(\?:je|jne)" 3 } } */
|
|
|
22033d |
+
|
|
|
22033d |
+
|