]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
rtl_data: Add sp_is_clobbered_by_asm
authorH.J. Lu <hjl.tools@gmail.com>
Mon, 14 Sep 2020 15:52:27 +0000 (08:52 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Thu, 24 Sep 2020 16:00:51 +0000 (09:00 -0700)
Add sp_is_clobbered_by_asm to rtl_data to inform backends that the stack
pointer is clobbered by asm statement.

gcc/

PR target/97032
* cfgexpand.c (asm_clobber_reg_kind): Set sp_is_clobbered_by_asm
to true if the stack pointer is clobbered by asm statement.
* emit-rtl.h (rtl_data): Add sp_is_clobbered_by_asm.
* config/i386/i386.c (ix86_get_drap_rtx): Set need_drap to true
if the stack pointer is clobbered by asm statement.

gcc/testsuite/

PR target/97032
* gcc.target/i386/pr97032.c: New test.

(cherry picked from commit 453a20c65722719b9e2d84339f215e7ec87692dc)

gcc/cfgexpand.c
gcc/config/i386/i386.c
gcc/emit-rtl.h
gcc/testsuite/gcc.target/i386/pr97032.c [new file with mode: 0644]

index c534cb31a472fb39873ff06c0083aa0db59ed5d5..122a5ff7b65ac78f6eebdf76279a9700b6a8a436 100644 (file)
@@ -2868,11 +2868,15 @@ asm_clobber_reg_is_valid (int regno, int nregs, const char *regname)
      as it was before, so no asm can validly clobber the stack pointer in
      the usual sense.  Adding the stack pointer to the clobber list has
      traditionally had some undocumented and somewhat obscure side-effects.  */
-  if (overlaps_hard_reg_set_p (regset, Pmode, STACK_POINTER_REGNUM)
-      && warning (OPT_Wdeprecated, "listing the stack pointer register"
-                 " %qs in a clobber list is deprecated", regname))
-    inform (input_location, "the value of the stack pointer after an %<asm%>"
-           " statement must be the same as it was before the statement");
+  if (overlaps_hard_reg_set_p (regset, Pmode, STACK_POINTER_REGNUM))
+    {
+      crtl->sp_is_clobbered_by_asm = true;
+      if (warning (OPT_Wdeprecated, "listing the stack pointer register"
+                  " %qs in a clobber list is deprecated", regname))
+       inform (input_location, "the value of the stack pointer after"
+               " an %<asm%> statement must be the same as it was before"
+               " the statement");
+    }
 
   return is_valid;
 }
index 6e03abf6b4772681294a462b5a83fbaa829c1e44..839b9929f6d77f2c3ec4e1a9dbe48dbcb30c88f7 100644 (file)
@@ -6965,10 +6965,12 @@ ix86_update_stack_boundary (void)
 static rtx
 ix86_get_drap_rtx (void)
 {
-  /* We must use DRAP if there are outgoing arguments on stack and
+  /* We must use DRAP if there are outgoing arguments on stack or
+     the stack pointer register is clobbered by asm statment and
      ACCUMULATE_OUTGOING_ARGS is false.  */
   if (ix86_force_drap
-      || (cfun->machine->outgoing_args_on_stack
+      || ((cfun->machine->outgoing_args_on_stack
+          || crtl->sp_is_clobbered_by_asm)
          && !ACCUMULATE_OUTGOING_ARGS))
     crtl->need_drap = true;
 
index a878efe3cf7e86e9e5068904a3094eb0ba704b38..0c96c52fc7b30db7ad70ced3e2e541047e16a1a9 100644 (file)
@@ -275,6 +275,9 @@ struct GTY(()) rtl_data {
      pass_stack_ptr_mod has run.  */
   bool sp_is_unchanging;
 
+  /* True if the stack pointer is clobbered by asm statement.  */
+  bool sp_is_clobbered_by_asm;
+
   /* Nonzero if function being compiled doesn't contain any calls
      (ignoring the prologue and epilogue).  This is set prior to
      register allocation in IRA and is valid for the remaining
diff --git a/gcc/testsuite/gcc.target/i386/pr97032.c b/gcc/testsuite/gcc.target/i386/pr97032.c
new file mode 100644 (file)
index 0000000..7cbbe9b
--- /dev/null
@@ -0,0 +1,23 @@
+/* { dg-do compile { target { ia32 && fstack_protector } } } */
+/* { dg-options "-O2 -mincoming-stack-boundary=2 -fstack-protector-all" } */
+
+#include <stdarg.h>
+
+extern int *__errno_location (void);
+
+long
+sys_socketcall (int op, ...)
+{
+  long int res;
+  va_list ap;
+  va_start (ap, op);
+  asm volatile ("push %%ebx; movl %2, %%ebx; int $0x80; pop %%ebx"
+  /* { dg-warning "listing the stack pointer register" "" { target *-*-* } .-1 } */
+               : "=a" (res) : "0" (102), "ri" (16), "c" (ap) : "memory", "esp");
+  if (__builtin_expect (res > 4294963200UL, 0))
+    *__errno_location () = -res;
+  va_end (ap);
+  return res;
+}
+
+/* { dg-final { scan-assembler "call\[ \t\]*_?__errno_location" } } */