56d343
commit 5fdcac79eb72406c59fa72073dfb3ba21380f56d
56d343
Author: ktkachov <ktkachov@138bc75d-0d04-0410-961f-82ee72b054a4>
56d343
Date:   Tue Apr 10 09:58:57 2018 +0000
56d343
56d343
    [explow] PR target/85173: validize memory before passing it on to target probe_stack
56d343
    
56d343
    In this PR the expansion code emits an invalid memory address for the stack probe, which the backend fails to recognise.
56d343
    The address is created explicitly in anti_adjust_stack_and_probe_stack_clash in explow.c and passed down to gen_probe_stack
56d343
    without any validation in emit_stack_probe.
56d343
    
56d343
    This patch fixes the ICE by calling validize_mem on the memory location before passing it down to the target.
56d343
    Jakub pointed out that we also want to create valid addresses for the probe_stack_address case, so this patch
56d343
    creates an expand operand and legitimizes it before passing it down to the probe_stack_address expander.
56d343
    
56d343
    This patch passes bootstrap and testing on arm-none-linux-gnueabihf and aarch64-none-linux-gnu
56d343
    and ppc64le-redhat-linux on gcc112 in the compile farm.
56d343
    
56d343
            PR target/85173
56d343
            * explow.c (emit_stack_probe): Call validize_mem on memory location
56d343
            before passing it to gen_probe_stack.  Create address operand and
56d343
            legitimize it for the probe_stack_address case.
56d343
    
56d343
            * gcc.target/arm/pr85173.c: New test.
56d343
    
56d343
    
56d343
    
56d343
    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@259266 138bc75d-0d04-0410-961f-82ee72b054a4
56d343
56d343
diff --git a/gcc/explow.c b/gcc/explow.c
56d343
index 9386489..e2253ae 100644
56d343
--- a/gcc/explow.c
56d343
+++ b/gcc/explow.c
56d343
@@ -1549,13 +1549,20 @@ emit_stack_probe (rtx address)
56d343
 {
56d343
 #ifdef HAVE_probe_stack_address
56d343
   if (HAVE_probe_stack_address)
56d343
-    emit_insn (gen_probe_stack_address (address));
56d343
+    {
56d343
+      struct expand_operand ops[1];
56d343
+      insn_code icode = targetm.code_for_probe_stack_address;
56d343
+      create_address_operand (ops, address);
56d343
+      maybe_legitimize_operands (icode, 0, 1, ops);
56d343
+      expand_insn (icode, 1, ops);
56d343
+    }
56d343
   else
56d343
 #endif
56d343
     {
56d343
       rtx memref = gen_rtx_MEM (word_mode, address);
56d343
 
56d343
       MEM_VOLATILE_P (memref) = 1;
56d343
+      memref = validize_mem (memref);
56d343
 
56d343
       /* See if we have an insn to probe the stack.  */
56d343
 #ifdef HAVE_probe_stack
56d343
diff --git a/gcc/testsuite/gcc.target/arm/pr85173.c b/gcc/testsuite/gcc.target/arm/pr85173.c
56d343
new file mode 100644
56d343
index 0000000..36105c9
56d343
--- /dev/null
56d343
+++ b/gcc/testsuite/gcc.target/arm/pr85173.c
56d343
@@ -0,0 +1,20 @@
56d343
+/* PR target/85173.  */
56d343
+
56d343
+/* { dg-do compile } */
56d343
+/* { dg-options "-O2 -fstack-clash-protection --param stack-clash-protection-probe-interval=14" } */
56d343
+/* { dg-require-effective-target arm_thumb2_ok } */
56d343
+
56d343
+__attribute__((noinline, noclone)) void
56d343
+foo (char *p)
56d343
+{
56d343
+  asm volatile ("" : : "r" (p) : "memory");
56d343
+}
56d343
+
56d343
+/* Nonconstant alloca, small local frame.  */
56d343
+__attribute__((noinline, noclone)) void
56d343
+f5 (int x)
56d343
+{
56d343
+  char locals[128];
56d343
+  char *vla = __builtin_alloca (x);
56d343
+  foo (vla);
56d343
+}