Fix stack pointer handling in ms_hook_prologue functions for i386 target.
authorJeff Law <law@torsion.usersys.redhat.com>
Fri, 6 Nov 2020 22:38:00 +0000 (17:38 -0500)
committerJeff Law <law@torsion.usersys.redhat.com>
Fri, 6 Nov 2020 22:38:00 +0000 (17:38 -0500)
gcc/
PR target/91489
* config/i386/i386.md (simple_return): Also check
for ms_hook_prologue function attribute.
* config/i386/i386.c (ix86_can_use_return_insn_p):
Also check for ms_hook_prologue function attribute.
* config/i386/i386-protos.h (ix86_function_ms_hook_prologue): Declare.

gcc/testsuite
PR target/91489
* gcc.target/i386/ms_hook_prologue.c: Expand testcase
to reproduce PR target/91489 issue.

gcc/config/i386/i386-protos.h
gcc/config/i386/i386.c
gcc/config/i386/i386.md
gcc/testsuite/gcc.target/i386/ms_hook_prologue.c

index 69e2b321bd8afabbefdcf4b3562b9fdef8a32a1d..b70d598ce204ca373b8faf2e76d6fb1f998a6c75 100644 (file)
@@ -26,6 +26,7 @@ extern bool ix86_handle_option (struct gcc_options *opts,
 /* Functions in i386.c */
 extern bool ix86_target_stack_probe (void);
 extern bool ix86_can_use_return_insn_p (void);
+extern bool ix86_function_ms_hook_prologue (const_tree fn);
 extern void ix86_setup_frame_addresses (void);
 extern bool ix86_rip_relative_addr_p (struct ix86_address *parts);
 
index 789ef727cf8b429243d9ae1f3782600ea646a192..4396f64e7cb3a1e06bcfd3338cb2034cd88c8142 100644 (file)
@@ -5494,6 +5494,9 @@ symbolic_reference_mentioned_p (rtx op)
 bool
 ix86_can_use_return_insn_p (void)
 {
+  if (ix86_function_ms_hook_prologue (current_function_decl))
+    return false;
+
   if (ix86_function_naked (current_function_decl))
     return false;
 
index 751801daa6fc67287d9f96bc81ed72207d3a73c1..979e49d47232f67766e38da01a0759a664e823b9 100644 (file)
 ;; static chain pointer - the first instruction has to be pushl %esi
 ;; and it can't be moved around, as we use alternate entry points
 ;; in that case.
+;; Also disallow for ms_hook_prologue functions which have frame
+;; pointer set up in function label which is correctly handled in
+;; ix86_expand_{prologue|epligoue}() only.
 
 (define_expand "simple_return"
   [(simple_return)]
-  "!TARGET_SEH && !ix86_static_chain_on_stack"
+  "!TARGET_SEH && !ix86_static_chain_on_stack && !ix86_function_ms_hook_prologue (cfun->decl)"
 {
   if (crtl->args.pops_args)
     {
index e11bcc049cb2ca14f644944e29e17fd92d39c73b..12e54c0e4ad15e18d6727ddd2285eb80db068900 100644 (file)
@@ -4,6 +4,8 @@
 /* { dg-require-effective-target ms_hook_prologue } */
 /* { dg-options "-O2 -fomit-frame-pointer" } */
 
+#include <stdio.h>
+
 int __attribute__ ((__ms_hook_prologue__)) foo ()
 {
   unsigned char *ptr = (unsigned char *) foo;
@@ -32,7 +34,16 @@ int __attribute__ ((__ms_hook_prologue__)) foo ()
   return 0;
 }
 
+unsigned int __attribute__ ((noinline, __ms_hook_prologue__)) test_func()
+{
+  static int value;
+
+  if (value++) puts("");
+
+  return 0;
+}
+
 int main ()
 {
-  return foo();
+  return foo() || test_func();
 }