Blame SOURCES/gcc48-rh1535655-3.patch

001c85
commit 2ad2b4c4d8f0776012d36f1f3ae17c5fef55c7f9
001c85
Author: root <root@lenovo-x3950-01.khw.lab.eng.bos.redhat.com>
001c85
Date:   Thu Jan 18 17:43:15 2018 -0500
001c85
001c85
    HJ's patch #2
001c85
001c85
diff --git a/gcc/config/i386/i386-protos.h b/gcc/config/i386/i386-protos.h
001c85
index ecdf108..4e4b210 100644
001c85
--- a/gcc/config/i386/i386-protos.h
001c85
+++ b/gcc/config/i386/i386-protos.h
001c85
@@ -307,6 +307,7 @@ extern enum attr_cpu ix86_schedule;
001c85
 
001c85
 extern const char * ix86_output_call_insn (rtx insn, rtx call_op);
001c85
 extern const char * ix86_output_indirect_jmp (rtx call_op, bool ret_p);
001c85
+extern const char * ix86_output_function_return (bool long_p);
001c85
 
001c85
 #ifdef RTX_CODE
001c85
 /* Target data for multipass lookahead scheduling.
001c85
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
001c85
index ebc9a90..9dffd02f 100644
001c85
--- a/gcc/config/i386/i386.c
001c85
+++ b/gcc/config/i386/i386.c
001c85
@@ -4635,6 +4635,31 @@ ix86_set_indirect_branch_type (tree fndecl)
001c85
       else
001c85
 	cfun->machine->indirect_branch_type = ix86_indirect_branch;
001c85
     }
001c85
+
001c85
+  if (cfun->machine->function_return_type == indirect_branch_unset)
001c85
+    {
001c85
+      tree attr = lookup_attribute ("function_return",
001c85
+				    DECL_ATTRIBUTES (fndecl));
001c85
+      if (attr != NULL)
001c85
+	{
001c85
+	  tree args = TREE_VALUE (attr);
001c85
+	  if (args == NULL)
001c85
+	    gcc_unreachable ();
001c85
+	  tree cst = TREE_VALUE (args);
001c85
+	  if (strcmp (TREE_STRING_POINTER (cst), "keep") == 0)
001c85
+	    cfun->machine->function_return_type = indirect_branch_keep;
001c85
+	  else if (strcmp (TREE_STRING_POINTER (cst), "thunk") == 0)
001c85
+	    cfun->machine->function_return_type = indirect_branch_thunk;
001c85
+	  else if (strcmp (TREE_STRING_POINTER (cst), "thunk-inline") == 0)
001c85
+	    cfun->machine->function_return_type = indirect_branch_thunk_inline;
001c85
+	  else if (strcmp (TREE_STRING_POINTER (cst), "thunk-extern") == 0)
001c85
+	    cfun->machine->function_return_type = indirect_branch_thunk_extern;
001c85
+	  else
001c85
+	    gcc_unreachable ();
001c85
+	}
001c85
+      else
001c85
+	cfun->machine->function_return_type = ix86_function_return;
001c85
+    }
001c85
 }
001c85
 
001c85
 /* Remember the last target of ix86_set_current_function.  */
001c85
@@ -8733,8 +8758,11 @@ static int indirect_thunks_used;
001c85
 /* Fills in the label name that should be used for the indirect thunk.  */
001c85
 
001c85
 static void
001c85
-indirect_thunk_name (char name[32], int regno)
001c85
+indirect_thunk_name (char name[32], int regno, bool ret_p)
001c85
 {
001c85
+  if (regno >= 0 && ret_p)
001c85
+    gcc_unreachable ();
001c85
+
001c85
   if (USE_HIDDEN_LINKONCE)
001c85
     {
001c85
       if (regno >= 0)
001c85
@@ -8748,14 +8776,22 @@ indirect_thunk_name (char name[32], int regno)
001c85
 		   reg_prefix, reg_names[regno]);
001c85
 	}
001c85
       else
001c85
-	sprintf (name, "__x86_indirect_thunk");
001c85
+	{
001c85
+	  const char *ret = ret_p ? "return" : "indirect";
001c85
+	  sprintf (name, "__x86_%s_thunk", ret);
001c85
+	}
001c85
     }
001c85
   else
001c85
     {
001c85
       if (regno >= 0)
001c85
 	ASM_GENERATE_INTERNAL_LABEL (name, "LITR", regno);
001c85
       else
001c85
-	ASM_GENERATE_INTERNAL_LABEL (name, "LIT", 0);
001c85
+	{
001c85
+	  if (ret_p)
001c85
+	    ASM_GENERATE_INTERNAL_LABEL (name, "LRT", 0);
001c85
+	  else
001c85
+	    ASM_GENERATE_INTERNAL_LABEL (name, "LIT", 0);
001c85
+	}
001c85
     }
001c85
 }
001c85
 
001c85
@@ -8841,7 +8877,7 @@ output_indirect_thunk_function (int regno)
001c85
   tree decl;
001c85
 
001c85
   /* Create __x86_indirect_thunk.  */
001c85
-  indirect_thunk_name (name, regno);
001c85
+  indirect_thunk_name (name, regno, false);
001c85
   decl = build_decl (BUILTINS_LOCATION, FUNCTION_DECL,
001c85
 		     get_identifier (name),
001c85
 		     build_function_type_list (void_type_node, NULL_TREE));
001c85
@@ -8885,6 +8921,36 @@ output_indirect_thunk_function (int regno)
001c85
 	ASM_OUTPUT_LABEL (asm_out_file, name);
001c85
       }
001c85
 
001c85
+  if (regno < 0)
001c85
+    {
001c85
+      /* Create alias for __x86.return_thunk/__x86.return_thunk_bnd.  */
001c85
+      char alias[32];
001c85
+
001c85
+      indirect_thunk_name (alias, regno, true);
001c85
+#if TARGET_MACHO
001c85
+      if (TARGET_MACHO)
001c85
+	{
001c85
+	  fputs ("\t.weak_definition\t", asm_out_file);
001c85
+	  assemble_name (asm_out_file, alias);
001c85
+	  fputs ("\n\t.private_extern\t", asm_out_file);
001c85
+	  assemble_name (asm_out_file, alias);
001c85
+	  putc ('\n', asm_out_file);
001c85
+	  ASM_OUTPUT_LABEL (asm_out_file, alias);
001c85
+	}
001c85
+#else
001c85
+      ASM_OUTPUT_DEF (asm_out_file, alias, name);
001c85
+      if (USE_HIDDEN_LINKONCE)
001c85
+	{
001c85
+	  fputs ("\t.globl\t", asm_out_file);
001c85
+	  assemble_name (asm_out_file, alias);
001c85
+	  putc ('\n', asm_out_file);
001c85
+	  fputs ("\t.hidden\t", asm_out_file);
001c85
+	  assemble_name (asm_out_file, alias);
001c85
+	  putc ('\n', asm_out_file);
001c85
+	}
001c85
+#endif
001c85
+    }
001c85
+
001c85
   DECL_INITIAL (decl) = make_node (BLOCK);
001c85
   current_function_decl = decl;
001c85
   allocate_struct_function (decl, false);
001c85
@@ -24353,7 +24419,7 @@ ix86_output_indirect_branch_via_reg (rtx call_op, bool sibcall_p)
001c85
 	    i -= (FIRST_REX_INT_REG - LAST_INT_REG - 1);
001c85
 	  indirect_thunks_used |= 1 << i;
001c85
 	}
001c85
-      indirect_thunk_name (thunk_name_buf, regno);
001c85
+      indirect_thunk_name (thunk_name_buf, regno, false);
001c85
       thunk_name = thunk_name_buf;
001c85
     }
001c85
   else
001c85
@@ -24437,7 +24503,7 @@ ix86_output_indirect_branch_via_push (rtx call_op, const char *xasm,
001c85
     {
001c85
       if (cfun->machine->indirect_branch_type == indirect_branch_thunk)
001c85
 	indirect_thunk_needed = true;
001c85
-      indirect_thunk_name (thunk_name_buf, regno);
001c85
+      indirect_thunk_name (thunk_name_buf, regno, false);
001c85
       thunk_name = thunk_name_buf;
001c85
     }
001c85
   else
001c85
@@ -24559,6 +24625,37 @@ ix86_output_indirect_jmp (rtx call_op, bool ret_p)
001c85
     return "jmp\t%A0";
001c85
 }
001c85
 
001c85
+/* Output function return.  CALL_OP is the jump target.  Add a REP
001c85
+   prefix to RET if LONG_P is true and function return is kept.  */
001c85
+
001c85
+const char *
001c85
+ix86_output_function_return (bool long_p)
001c85
+{
001c85
+  if (cfun->machine->function_return_type != indirect_branch_keep)
001c85
+    {
001c85
+      char thunk_name[32];
001c85
+
001c85
+      if (cfun->machine->function_return_type
001c85
+	  != indirect_branch_thunk_inline)
001c85
+	{
001c85
+	  bool need_thunk = (cfun->machine->function_return_type
001c85
+			     == indirect_branch_thunk);
001c85
+	  indirect_thunk_name (thunk_name, -1, true);
001c85
+	  indirect_thunk_needed |= need_thunk;
001c85
+	  fprintf (asm_out_file, "\tjmp\t%s\n", thunk_name);
001c85
+	}
001c85
+      else
001c85
+	output_indirect_thunk (-1);
001c85
+
001c85
+      return "";
001c85
+    }
001c85
+
001c85
+  if (!long_p)
001c85
+    return "ret";
001c85
+
001c85
+  return "rep%; ret";
001c85
+}
001c85
+
001c85
 /* Output the assembly for a call instruction.  */
001c85
 
001c85
 const char *
001c85
@@ -35972,6 +36069,28 @@ ix86_handle_fndecl_attribute (tree *node, tree name,
001c85
 	}
001c85
     }
001c85
 
001c85
+  if (is_attribute_p ("function_return", name))
001c85
+    {
001c85
+      tree cst = TREE_VALUE (args);
001c85
+      if (TREE_CODE (cst) != STRING_CST)
001c85
+	{
001c85
+	  warning (OPT_Wattributes,
001c85
+		   "%qE attribute requires a string constant argument",
001c85
+		   name);
001c85
+	  *no_add_attrs = true;
001c85
+	}
001c85
+      else if (strcmp (TREE_STRING_POINTER (cst), "keep") != 0
001c85
+	       && strcmp (TREE_STRING_POINTER (cst), "thunk") != 0
001c85
+	       && strcmp (TREE_STRING_POINTER (cst), "thunk-inline") != 0
001c85
+	       && strcmp (TREE_STRING_POINTER (cst), "thunk-extern") != 0)
001c85
+	{
001c85
+	  warning (OPT_Wattributes,
001c85
+		   "argument to %qE attribute is not "
001c85
+		   "(keep|thunk|thunk-inline|thunk-extern)", name);
001c85
+	  *no_add_attrs = true;
001c85
+	}
001c85
+    }
001c85
+
001c85
   return NULL_TREE;
001c85
 }
001c85
 
001c85
@@ -39492,6 +39611,9 @@ static const struct attribute_spec ix86_attribute_table[] =
001c85
     ix86_handle_callee_pop_aggregate_return, true },
001c85
   { "indirect_branch", 1, 1, true, false, false,
001c85
     ix86_handle_fndecl_attribute, false },
001c85
+  { "function_return", 1, 1, true, false, false,
001c85
+    ix86_handle_fndecl_attribute, false },
001c85
+
001c85
   /* End element.  */
001c85
   { NULL,        0, 0, false, false, false, NULL, false }
001c85
 };
001c85
diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
001c85
index 8183cee7..8ff7026 100644
001c85
--- a/gcc/config/i386/i386.h
001c85
+++ b/gcc/config/i386/i386.h
001c85
@@ -2329,6 +2329,9 @@ struct GTY(()) machine_function {
001c85
      "indirect_jump" or "tablejump".  */
001c85
   BOOL_BITFIELD has_local_indirect_jump : 1;
001c85
 
001c85
+  /* How to generate function return.  */
001c85
+  ENUM_BITFIELD(indirect_branch) function_return_type : 3;
001c85
+
001c85
   /* During prologue/epilogue generation, the current frame state.
001c85
      Otherwise, the frame state at the end of the prologue.  */
001c85
   struct machine_frame_state fs;
001c85
diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
001c85
index b943849..ef16cf5 100644
001c85
--- a/gcc/config/i386/i386.md
001c85
+++ b/gcc/config/i386/i386.md
001c85
@@ -11749,7 +11749,7 @@
001c85
 (define_insn "simple_return_internal"
001c85
   [(simple_return)]
001c85
   "reload_completed"
001c85
-  "ret"
001c85
+  "* return ix86_output_function_return (false);"
001c85
   [(set_attr "length" "1")
001c85
    (set_attr "atom_unit" "jeu")
001c85
    (set_attr "length_immediate" "0")
001c85
@@ -11762,7 +11762,7 @@
001c85
   [(simple_return)
001c85
    (unspec [(const_int 0)] UNSPEC_REP)]
001c85
   "reload_completed"
001c85
-  "rep%; ret"
001c85
+  "* return ix86_output_function_return (true);"
001c85
   [(set_attr "length" "2")
001c85
    (set_attr "atom_unit" "jeu")
001c85
    (set_attr "length_immediate" "0")
001c85
diff --git a/gcc/config/i386/i386.opt b/gcc/config/i386/i386.opt
001c85
index 0f6965a..9dfa2cb 100644
001c85
--- a/gcc/config/i386/i386.opt
001c85
+++ b/gcc/config/i386/i386.opt
001c85
@@ -635,9 +635,13 @@ mindirect-branch=
001c85
 Target Report RejectNegative Joined Enum(indirect_branch) Var(ix86_indirect_branch) Init(indirect_branch_keep)
001c85
 Convert indirect call and jump to call and return thunks.
001c85
 
001c85
+mfunction-return=
001c85
+Target Report RejectNegative Joined Enum(indirect_branch) Var(ix86_function_return) Init(indirect_branch_keep)
001c85
+Convert function return to call and return thunk.
001c85
+
001c85
 Enum
001c85
 Name(indirect_branch) Type(enum indirect_branch)
001c85
-Known indirect branch choices (for use with the -mindirect-branch= option):
001c85
+Known indirect branch choices (for use with the -mindirect-branch=/-mfunction-return= options):
001c85
 
001c85
 EnumValue
001c85
 Enum(indirect_branch) String(keep) Value(indirect_branch_keep)
001c85
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
001c85
index 847991c..add4f18 100644
001c85
--- a/gcc/doc/extend.texi
001c85
+++ b/gcc/doc/extend.texi
001c85
@@ -3821,6 +3821,15 @@ call and jump to call and return thunk.  @samp{thunk-inline} converts
001c85
 indirect call and jump to inlined call and return thunk.
001c85
 @samp{thunk-extern} converts indirect call and jump to external call
001c85
 and return thunk provided in a separate object file.
001c85
+
001c85
+@item function_return("@var{choice}")
001c85
+@cindex @code{function_return} function attribute, x86
001c85
+On x86 targets, the @code{function_return} attribute causes the compiler
001c85
+to convert function return with @var{choice}.  @samp{keep} keeps function
001c85
+return unmodified.  @samp{thunk} converts function return to call and
001c85
+return thunk.  @samp{thunk-inline} converts function return to inlined
001c85
+call and return thunk.  @samp{thunk-extern} converts function return to
001c85
+external call and return thunk provided in a separate object file.
001c85
 @end table
001c85
 
001c85
 On the PowerPC, the following options are allowed:
001c85
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
001c85
index b299fbf..5acd23a 100644
001c85
--- a/gcc/doc/invoke.texi
001c85
+++ b/gcc/doc/invoke.texi
001c85
@@ -658,7 +658,7 @@ Objective-C and Objective-C++ Dialects}.
001c85
 -m32 -m64 -mx32 -mlarge-data-threshold=@var{num} @gol
001c85
 -msse2avx -mfentry -m8bit-idiv @gol
001c85
 -mavx256-split-unaligned-load -mavx256-split-unaligned-store @gol
001c85
--mindirect-branch=@var{choice}}
001c85
+-mindirect-branch=@var{choice} -mfunction-return==@var{choice}}
001c85
 
001c85
 @emph{i386 and x86-64 Windows Options}
001c85
 @gccoptlist{-mconsole -mcygwin -mno-cygwin -mdll @gol
001c85
@@ -14658,6 +14658,17 @@ to external call and return thunk provided in a separate object file.
001c85
 You can control this behavior for a specific function by using the
001c85
 function attribute @code{indirect_branch}.  @xref{Function Attributes}.
001c85
 
001c85
+@item -mfunction-return=@var{choice}
001c85
+@opindex -mfunction-return
001c85
+Convert function return with @var{choice}.  The default is @samp{keep},
001c85
+which keeps function return unmodified.  @samp{thunk} converts function
001c85
+return to call and return thunk.  @samp{thunk-inline} converts function
001c85
+return to inlined call and return thunk.  @samp{thunk-extern} converts
001c85
+function return to external call and return thunk provided in a separate
001c85
+object file.  You can control this behavior for a specific function by
001c85
+using the function attribute @code{function_return}.
001c85
+@xref{Function Attributes}.
001c85
+
001c85
 @end table
001c85
 
001c85
 These @samp{-m} switches are supported in addition to the above
001c85
diff --git a/gcc/testsuite/gcc.target/i386/indirect-thunk-1.c b/gcc/testsuite/gcc.target/i386/indirect-thunk-1.c
001c85
index 87f6dae..034b4cc 100644
001c85
--- a/gcc/testsuite/gcc.target/i386/indirect-thunk-1.c
001c85
+++ b/gcc/testsuite/gcc.target/i386/indirect-thunk-1.c
001c85
@@ -1,5 +1,5 @@
001c85
 /* { dg-do compile } */
001c85
-/* { dg-options "-O2 -mindirect-branch=thunk -fno-pic" } */
001c85
+/* { dg-options "-O2 -mfunction-return=keep -mindirect-branch=thunk -fno-pic" } */
001c85
 
001c85
 typedef void (*dispatch_t)(long offset);
001c85
 
001c85
diff --git a/gcc/testsuite/gcc.target/i386/indirect-thunk-2.c b/gcc/testsuite/gcc.target/i386/indirect-thunk-2.c
001c85
index 6bc4f0a..e0c57cb 100644
001c85
--- a/gcc/testsuite/gcc.target/i386/indirect-thunk-2.c
001c85
+++ b/gcc/testsuite/gcc.target/i386/indirect-thunk-2.c
001c85
@@ -1,5 +1,5 @@
001c85
 /* { dg-do compile } */
001c85
-/* { dg-options "-O2 -mindirect-branch=thunk -fno-pic" } */
001c85
+/* { dg-options "-O2 -mfunction-return=keep -mindirect-branch=thunk -fno-pic" } */
001c85
 
001c85
 typedef void (*dispatch_t)(long offset);
001c85
 
001c85
diff --git a/gcc/testsuite/gcc.target/i386/indirect-thunk-3.c b/gcc/testsuite/gcc.target/i386/indirect-thunk-3.c
001c85
index f20d35c..3c0d4c3 100644
001c85
--- a/gcc/testsuite/gcc.target/i386/indirect-thunk-3.c
001c85
+++ b/gcc/testsuite/gcc.target/i386/indirect-thunk-3.c
001c85
@@ -1,5 +1,5 @@
001c85
 /* { dg-do compile } */
001c85
-/* { dg-options "-O2 -mindirect-branch=thunk -fno-pic" } */
001c85
+/* { dg-options "-O2 -mfunction-return=keep -mindirect-branch=thunk -fno-pic" } */
001c85
 
001c85
 typedef void (*dispatch_t)(long offset);
001c85
 
001c85
@@ -12,7 +12,7 @@ male_indirect_jump (long offset)
001c85
   return 0;
001c85
 }
001c85
 
001c85
-/* { dg-final { scan-assembler "push(?:l|q)\[ \t\]*_?dispatch" { target { ! x32 } } } } */
001c85
+/* { dg-final { scan-assembler "push(?:l|q)\[ \t\]*_?dispatch" { target { { ! x32 } && *-*-linux* } } } } */
001c85
 /* { dg-final { scan-assembler "jmp\[ \t\]*__x86_indirect_thunk" { target { ! x32 } } } } */
001c85
 /* { dg-final { scan-assembler "call\[ \t\]*__x86_indirect_thunk_(r|e)ax" { target x32 } } } */
001c85
 /* { dg-final { scan-assembler "jmp\[ \t\]*\.LIND" } } */
001c85
diff --git a/gcc/testsuite/gcc.target/i386/indirect-thunk-4.c b/gcc/testsuite/gcc.target/i386/indirect-thunk-4.c
001c85
index 0eff8fb..14d4ef6 100644
001c85
--- a/gcc/testsuite/gcc.target/i386/indirect-thunk-4.c
001c85
+++ b/gcc/testsuite/gcc.target/i386/indirect-thunk-4.c
001c85
@@ -1,5 +1,5 @@
001c85
 /* { dg-do compile } */
001c85
-/* { dg-options "-O2 -mindirect-branch=thunk -fno-pic" } */
001c85
+/* { dg-options "-O2 -mfunction-return=keep -mindirect-branch=thunk -fno-pic" } */
001c85
 
001c85
 typedef void (*dispatch_t)(long offset);
001c85
 
001c85
@@ -12,7 +12,7 @@ male_indirect_jump (long offset)
001c85
   return 0;
001c85
 }
001c85
 
001c85
-/* { dg-final { scan-assembler "push(?:l|q)\[ \t\]*_?dispatch" { target { ! x32 } } } } */
001c85
+/* { dg-final { scan-assembler "push(?:l|q)\[ \t\]*_?dispatch" { target { { ! x32 } && *-*-linux* } } } } */
001c85
 /* { dg-final { scan-assembler "jmp\[ \t\]*__x86_indirect_thunk" { target { ! x32 } } } } */
001c85
 /* { dg-final { scan-assembler "call\[ \t\]*__x86_indirect_thunk_(r|e)ax" { target x32 } } } */
001c85
 /* { dg-final { scan-assembler "jmp\[ \t\]*\.LIND" } } */
001c85
diff --git a/gcc/testsuite/gcc.target/i386/indirect-thunk-7.c b/gcc/testsuite/gcc.target/i386/indirect-thunk-7.c
001c85
index afdb600..bc6b47a 100644
001c85
--- a/gcc/testsuite/gcc.target/i386/indirect-thunk-7.c
001c85
+++ b/gcc/testsuite/gcc.target/i386/indirect-thunk-7.c
001c85
@@ -1,5 +1,5 @@
001c85
 /* { dg-do compile } */
001c85
-/* { dg-options "-O2 -mindirect-branch=thunk -fno-pic" } */
001c85
+/* { dg-options "-O2 -mfunction-return=keep -mindirect-branch=thunk -fno-pic" } */
001c85
 
001c85
 void func0 (void);
001c85
 void func1 (void);
001c85
@@ -35,7 +35,7 @@ bar (int i)
001c85
     }
001c85
 }
001c85
 
001c85
-/* { dg-final { scan-assembler "push(?:l|q)\[ \t\]*\.L\[0-9\]+\\(,%" { target { ! x32 } } } } */
001c85
+/* { dg-final { scan-assembler "push(?:l|q)\[ \t\]*\.L\[0-9\]+\\(,%" { target { { ! x32 } && *-*-linux* } } } } */
001c85
 /* { dg-final { scan-assembler "jmp\[ \t\]*__x86_indirect_thunk" { target { ! x32 } } } } */
001c85
 /* { dg-final { scan-assembler "jmp\[ \t\]*__x86_indirect_thunk_(r|e)ax" { target x32 } } } */
001c85
 /* { dg-final { scan-assembler "jmp\[ \t\]*\.LIND" } } */
001c85
diff --git a/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-1.c b/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-1.c
001c85
index efccdec..7c45142 100644
001c85
--- a/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-1.c
001c85
+++ b/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-1.c
001c85
@@ -1,5 +1,5 @@
001c85
 /* { dg-do compile } */
001c85
-/* { dg-options "-O2 -fno-pic" } */
001c85
+/* { dg-options "-O2 -mfunction-return=keep -fno-pic" } */
001c85
 
001c85
 typedef void (*dispatch_t)(long offset);
001c85
 
001c85
diff --git a/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-2.c b/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-2.c
001c85
index ca3814e..9eebc84 100644
001c85
--- a/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-2.c
001c85
+++ b/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-2.c
001c85
@@ -1,5 +1,5 @@
001c85
 /* { dg-do compile } */
001c85
-/* { dg-options "-O2 -fno-pic" } */
001c85
+/* { dg-options "-O2 -mfunction-return=keep -fno-pic" } */
001c85
 
001c85
 typedef void (*dispatch_t)(long offset);
001c85
 
001c85
diff --git a/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-3.c b/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-3.c
001c85
index 97744d6..f938db0 100644
001c85
--- a/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-3.c
001c85
+++ b/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-3.c
001c85
@@ -1,5 +1,5 @@
001c85
 /* { dg-do compile } */
001c85
-/* { dg-options "-O2 -fno-pic" } */
001c85
+/* { dg-options "-O2 -mfunction-return=keep -fno-pic" } */
001c85
 
001c85
 typedef void (*dispatch_t)(long offset);
001c85
 
001c85
@@ -14,7 +14,7 @@ male_indirect_jump (long offset)
001c85
   return 0;
001c85
 }
001c85
 
001c85
-/* { dg-final { scan-assembler "push(?:l|q)\[ \t\]*_?dispatch" { target { ! x32 } } } } */
001c85
+/* { dg-final { scan-assembler "push(?:l|q)\[ \t\]*_?dispatch" { target { { ! x32 } && *-*-linux* } } } } */
001c85
 /* { dg-final { scan-assembler-times "jmp\[ \t\]*\.LIND" 2 } } */
001c85
 /* { dg-final { scan-assembler-times "call\[ \t\]*\.LIND" 2 } } */
001c85
 /* { dg-final { scan-assembler {\tpause} } } */
001c85
diff --git a/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-4.c b/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-4.c
001c85
index bfce3ea..4e58599 100644
001c85
--- a/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-4.c
001c85
+++ b/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-4.c
001c85
@@ -1,5 +1,5 @@
001c85
 /* { dg-do compile } */
001c85
-/* { dg-options "-O2 -fno-pic" } */
001c85
+/* { dg-options "-O2 -mfunction-return=keep -fno-pic" } */
001c85
 
001c85
 typedef void (*dispatch_t)(long offset);
001c85
 
001c85
@@ -13,7 +13,7 @@ male_indirect_jump (long offset)
001c85
   return 0;
001c85
 }
001c85
 
001c85
-/* { dg-final { scan-assembler "push(?:l|q)\[ \t\]*_?dispatch" { target { ! x32 } } } } */
001c85
+/* { dg-final { scan-assembler "push(?:l|q)\[ \t\]*_?dispatch" { target { { ! x32 } && *-*-linux* } } } } */
001c85
 /* { dg-final { scan-assembler-times "jmp\[ \t\]*\.LIND" 2 } } */
001c85
 /* { dg-final { scan-assembler-times "call\[ \t\]*\.LIND" 2 } } */
001c85
 /* { dg-final { scan-assembler {\tpause} } } */
001c85
diff --git a/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-5.c b/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-5.c
001c85
index 0833606..b8d5024 100644
001c85
--- a/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-5.c
001c85
+++ b/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-5.c
001c85
@@ -1,5 +1,5 @@
001c85
 /* { dg-do compile } */
001c85
-/* { dg-options "-O2 -fno-pic" } */
001c85
+/* { dg-options "-O2 -mfunction-return=keep -fno-pic" } */
001c85
 
001c85
 typedef void (*dispatch_t)(long offset);
001c85
 
001c85
@@ -14,7 +14,7 @@ male_indirect_jump (long offset)
001c85
   return 0;
001c85
 }
001c85
 
001c85
-/* { dg-final { scan-assembler "push(?:l|q)\[ \t\]*_?dispatch" { target { ! x32 } } } } */
001c85
+/* { dg-final { scan-assembler "push(?:l|q)\[ \t\]*_?dispatch" { target { { ! x32 } && *-*-linux* } } } } */
001c85
 /* { dg-final { scan-assembler-times "jmp\[ \t\]*\.LIND" 1 { target { ! x32 } } } } */
001c85
 /* { dg-final { scan-assembler-times "call\[ \t\]*\.LIND" 1 { target { ! x32 } } } } */
001c85
 /* { dg-final { scan-assembler "jmp\[ \t\]*__x86_indirect_thunk" { target { ! x32 } } } } */
001c85
diff --git a/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-6.c b/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-6.c
001c85
index 2eba0fb..455adab 100644
001c85
--- a/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-6.c
001c85
+++ b/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-6.c
001c85
@@ -1,5 +1,5 @@
001c85
 /* { dg-do compile } */
001c85
-/* { dg-options "-O2 -fno-pic" } */
001c85
+/* { dg-options "-O2 -mfunction-return=keep -fno-pic" } */
001c85
 
001c85
 typedef void (*dispatch_t)(long offset);
001c85
 
001c85
@@ -13,7 +13,7 @@ male_indirect_jump (long offset)
001c85
   return 0;
001c85
 }
001c85
 
001c85
-/* { dg-final { scan-assembler "push(?:l|q)\[ \t\]*_?dispatch" { target { ! x32 } } } } */
001c85
+/* { dg-final { scan-assembler "push(?:l|q)\[ \t\]*_?dispatch" { target { { ! x32 } && *-*-linux* } } } } */
001c85
 /* { dg-final { scan-assembler-times "jmp\[ \t\]*\.LIND" 1 { target { ! x32 } } } } */
001c85
 /* { dg-final { scan-assembler-times "call\[ \t\]*\.LIND" 1 { target { ! x32 } } } } */
001c85
 /* { dg-final { scan-assembler "jmp\[ \t\]*__x86_indirect_thunk" { target { ! x32 } } } } */
001c85
diff --git a/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-7.c b/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-7.c
001c85
index f58427e..4595b84 100644
001c85
--- a/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-7.c
001c85
+++ b/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-7.c
001c85
@@ -1,5 +1,5 @@
001c85
 /* { dg-do compile } */
001c85
-/* { dg-options "-O2 -fno-pic" } */
001c85
+/* { dg-options "-O2 -mfunction-return=keep -fno-pic" } */
001c85
 
001c85
 void func0 (void);
001c85
 void func1 (void);
001c85
@@ -36,7 +36,7 @@ bar (int i)
001c85
     }
001c85
 }
001c85
 
001c85
-/* { dg-final { scan-assembler "push(?:l|q)\[ \t\]*\.L\[0-9\]+\\(,%" { target { ! x32 } } } } */
001c85
+/* { dg-final { scan-assembler "push(?:l|q)\[ \t\]*\.L\[0-9\]+\\(,%" { target { { ! x32 } && *-*-linux* } } } } */
001c85
 /* { dg-final { scan-assembler "jmp\[ \t\]*__x86_indirect_thunk_(r|e)ax" { target x32 } } } */
001c85
 /* { dg-final { scan-assembler "jmp\[ \t\]*__x86_indirect_thunk" } } */
001c85
 /* { dg-final { scan-assembler-not {\t(lfence|pause)} } } */
001c85
diff --git a/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-8.c b/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-8.c
001c85
index 564ed39..d730d31 100644
001c85
--- a/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-8.c
001c85
+++ b/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-8.c
001c85
@@ -1,5 +1,5 @@
001c85
 /* { dg-do compile } */
001c85
-/* { dg-options "-O2 -mindirect-branch=thunk -fno-pic" } */
001c85
+/* { dg-options "-O2 -mfunction-return=keep -mindirect-branch=thunk -fno-pic" } */
001c85
 
001c85
 void func0 (void);
001c85
 void func1 (void);
001c85
diff --git a/gcc/testsuite/gcc.target/i386/indirect-thunk-extern-1.c b/gcc/testsuite/gcc.target/i386/indirect-thunk-extern-1.c
001c85
index 7fd01d6..f424181 100644
001c85
--- a/gcc/testsuite/gcc.target/i386/indirect-thunk-extern-1.c
001c85
+++ b/gcc/testsuite/gcc.target/i386/indirect-thunk-extern-1.c
001c85
@@ -1,5 +1,5 @@
001c85
 /* { dg-do compile } */
001c85
-/* { dg-options "-O2 -mindirect-branch=thunk-extern -fno-pic" } */
001c85
+/* { dg-options "-O2 -mfunction-return=keep -mindirect-branch=thunk-extern -fno-pic" } */
001c85
 
001c85
 typedef void (*dispatch_t)(long offset);
001c85
 
001c85
diff --git a/gcc/testsuite/gcc.target/i386/indirect-thunk-extern-2.c b/gcc/testsuite/gcc.target/i386/indirect-thunk-extern-2.c
001c85
index 825f6b2..ac54868 100644
001c85
--- a/gcc/testsuite/gcc.target/i386/indirect-thunk-extern-2.c
001c85
+++ b/gcc/testsuite/gcc.target/i386/indirect-thunk-extern-2.c
001c85
@@ -1,5 +1,5 @@
001c85
 /* { dg-do compile } */
001c85
-/* { dg-options "-O2 -mindirect-branch=thunk-extern -fno-pic" } */
001c85
+/* { dg-options "-O2 -mfunction-return=keep -mindirect-branch=thunk-extern -fno-pic" } */
001c85
 
001c85
 typedef void (*dispatch_t)(long offset);
001c85
 
001c85
diff --git a/gcc/testsuite/gcc.target/i386/indirect-thunk-extern-3.c b/gcc/testsuite/gcc.target/i386/indirect-thunk-extern-3.c
001c85
index 395634e..06ebf1c 100644
001c85
--- a/gcc/testsuite/gcc.target/i386/indirect-thunk-extern-3.c
001c85
+++ b/gcc/testsuite/gcc.target/i386/indirect-thunk-extern-3.c
001c85
@@ -1,5 +1,5 @@
001c85
 /* { dg-do compile } */
001c85
-/* { dg-options "-O2 -mindirect-branch=thunk-extern -fno-pic" } */
001c85
+/* { dg-options "-O2 -mfunction-return=keep -mindirect-branch=thunk-extern -fno-pic" } */
001c85
 
001c85
 typedef void (*dispatch_t)(long offset);
001c85
 
001c85
@@ -12,7 +12,7 @@ male_indirect_jump (long offset)
001c85
   return 0;
001c85
 }
001c85
 
001c85
-/* { dg-final { scan-assembler "push(?:l|q)\[ \t\]*_?dispatch" { target { ! x32 } } } } */
001c85
+/* { dg-final { scan-assembler "push(?:l|q)\[ \t\]*_?dispatch" { target { { ! x32 } && *-*-linux* } } } } */
001c85
 /* { dg-final { scan-assembler "jmp\[ \t\]*__x86_indirect_thunk" { target { ! x32 } } } } */
001c85
 /* { dg-final { scan-assembler-times "jmp\[ \t\]*\.LIND" 1 { target { ! x32 } } } } */
001c85
 /* { dg-final { scan-assembler-times "call\[ \t\]*\.LIND" 1 { target { ! x32 } } } } */
001c85
diff --git a/gcc/testsuite/gcc.target/i386/indirect-thunk-extern-4.c b/gcc/testsuite/gcc.target/i386/indirect-thunk-extern-4.c
001c85
index fd3f633..1c8f944 100644
001c85
--- a/gcc/testsuite/gcc.target/i386/indirect-thunk-extern-4.c
001c85
+++ b/gcc/testsuite/gcc.target/i386/indirect-thunk-extern-4.c
001c85
@@ -1,5 +1,5 @@
001c85
 /* { dg-do compile } */
001c85
-/* { dg-options "-O2 -mindirect-branch=thunk-extern -fno-pic" } */
001c85
+/* { dg-options "-O2 -mfunction-return=keep -mindirect-branch=thunk-extern -fno-pic" } */
001c85
 
001c85
 typedef void (*dispatch_t)(long offset);
001c85
 
001c85
@@ -12,7 +12,7 @@ male_indirect_jump (long offset)
001c85
   return 0;
001c85
 }
001c85
 
001c85
-/* { dg-final { scan-assembler "push(?:l|q)\[ \t\]*_?dispatch" { target { ! x32 } } } } */
001c85
+/* { dg-final { scan-assembler "push(?:l|q)\[ \t\]*_?dispatch" { target { { ! x32 } && *-*-linux* } } } } */
001c85
 /* { dg-final { scan-assembler "jmp\[ \t\]*__x86_indirect_thunk" { target { ! x32 } } } } */
001c85
 /* { dg-final { scan-assembler-times "jmp\[ \t\]*\.LIND" 1 { target { ! x32 } } } } */
001c85
 /* { dg-final { scan-assembler-times "call\[ \t\]*\.LIND" 1 { target { ! x32 } } } } */
001c85
diff --git a/gcc/testsuite/gcc.target/i386/indirect-thunk-extern-7.c b/gcc/testsuite/gcc.target/i386/indirect-thunk-extern-7.c
001c85
index 6652523..86e9fd1 100644
001c85
--- a/gcc/testsuite/gcc.target/i386/indirect-thunk-extern-7.c
001c85
+++ b/gcc/testsuite/gcc.target/i386/indirect-thunk-extern-7.c
001c85
@@ -1,5 +1,5 @@
001c85
 /* { dg-do compile } */
001c85
-/* { dg-options "-O2 -mindirect-branch=thunk-extern -fno-pic" } */
001c85
+/* { dg-options "-O2 -mfunction-return=keep -mindirect-branch=thunk-extern -fno-pic" } */
001c85
 
001c85
 void func0 (void);
001c85
 void func1 (void);
001c85
@@ -35,7 +35,7 @@ bar (int i)
001c85
     }
001c85
 }
001c85
 
001c85
-/* { dg-final { scan-assembler "push(?:l|q)\[ \t\]*\.L\[0-9\]+\\(,%" { target { ! x32 } } } } */
001c85
+/* { dg-final { scan-assembler "push(?:l|q)\[ \t\]*\.L\[0-9\]+\\(,%" { target { { ! x32 } && *-*-linux* } } } } */
001c85
 /* { dg-final { scan-assembler "jmp\[ \t\]*__x86_indirect_thunk" { target { ! x32 } } } } */
001c85
 /* { dg-final { scan-assembler "jmp\[ \t\]*__x86_indirect_thunk_(r|e)ax" { target x32 } } } */
001c85
 /* { dg-final { scan-assembler-not {\t(lfence|pause)} } } */
001c85
diff --git a/gcc/testsuite/gcc.target/i386/indirect-thunk-inline-1.c b/gcc/testsuite/gcc.target/i386/indirect-thunk-inline-1.c
001c85
index 48c4dd4..4117a35 100644
001c85
--- a/gcc/testsuite/gcc.target/i386/indirect-thunk-inline-1.c
001c85
+++ b/gcc/testsuite/gcc.target/i386/indirect-thunk-inline-1.c
001c85
@@ -1,5 +1,5 @@
001c85
 /* { dg-do compile } */
001c85
-/* { dg-options "-O2 -mindirect-branch=thunk-inline -fno-pic" } */
001c85
+/* { dg-options "-O2 -mfunction-return=keep -mindirect-branch=thunk-inline -fno-pic" } */
001c85
 
001c85
 typedef void (*dispatch_t)(long offset);
001c85
 
001c85
diff --git a/gcc/testsuite/gcc.target/i386/indirect-thunk-inline-2.c b/gcc/testsuite/gcc.target/i386/indirect-thunk-inline-2.c
001c85
index 355dad5..650d55c 100644
001c85
--- a/gcc/testsuite/gcc.target/i386/indirect-thunk-inline-2.c
001c85
+++ b/gcc/testsuite/gcc.target/i386/indirect-thunk-inline-2.c
001c85
@@ -1,5 +1,5 @@
001c85
 /* { dg-do compile } */
001c85
-/* { dg-options "-O2 -mindirect-branch=thunk-inline -fno-pic" } */
001c85
+/* { dg-options "-O2 -mfunction-return=keep -mindirect-branch=thunk-inline -fno-pic" } */
001c85
 
001c85
 typedef void (*dispatch_t)(long offset);
001c85
 
001c85
diff --git a/gcc/testsuite/gcc.target/i386/indirect-thunk-inline-3.c b/gcc/testsuite/gcc.target/i386/indirect-thunk-inline-3.c
001c85
index 244fec7..9540996 100644
001c85
--- a/gcc/testsuite/gcc.target/i386/indirect-thunk-inline-3.c
001c85
+++ b/gcc/testsuite/gcc.target/i386/indirect-thunk-inline-3.c
001c85
@@ -1,5 +1,5 @@
001c85
 /* { dg-do compile } */
001c85
-/* { dg-options "-O2 -mindirect-branch=thunk-inline -fno-pic" } */
001c85
+/* { dg-options "-O2 -mfunction-return=keep -mindirect-branch=thunk-inline -fno-pic" } */
001c85
 
001c85
 typedef void (*dispatch_t)(long offset);
001c85
 
001c85
@@ -12,7 +12,7 @@ male_indirect_jump (long offset)
001c85
   return 0;
001c85
 }
001c85
 
001c85
-/* { dg-final { scan-assembler "push(?:l|q)\[ \t\]*_?dispatch" { target { ! x32 } } } } */
001c85
+/* { dg-final { scan-assembler "push(?:l|q)\[ \t\]*_?dispatch" { target { { ! x32 } && *-*-linux* } } } } */
001c85
 /* { dg-final { scan-assembler-times "jmp\[ \t\]*\.LIND" 2 } } */
001c85
 /* { dg-final { scan-assembler-times "call\[ \t\]*\.LIND" 2 } } */
001c85
 /* { dg-final { scan-assembler-times {\tpause} 1 } } */
001c85
diff --git a/gcc/testsuite/gcc.target/i386/indirect-thunk-inline-4.c b/gcc/testsuite/gcc.target/i386/indirect-thunk-inline-4.c
001c85
index 107ebe3..f3db6e2 100644
001c85
--- a/gcc/testsuite/gcc.target/i386/indirect-thunk-inline-4.c
001c85
+++ b/gcc/testsuite/gcc.target/i386/indirect-thunk-inline-4.c
001c85
@@ -1,5 +1,5 @@
001c85
 /* { dg-do compile } */
001c85
-/* { dg-options "-O2 -mindirect-branch=thunk-inline -fno-pic" } */
001c85
+/* { dg-options "-O2 -mfunction-return=keep -mindirect-branch=thunk-inline -fno-pic" } */
001c85
 
001c85
 typedef void (*dispatch_t)(long offset);
001c85
 
001c85
@@ -12,7 +12,7 @@ male_indirect_jump (long offset)
001c85
   return 0;
001c85
 }
001c85
 
001c85
-/* { dg-final { scan-assembler "push(?:l|q)\[ \t\]*_?dispatch" { target { ! x32 } } } } */
001c85
+/* { dg-final { scan-assembler "push(?:l|q)\[ \t\]*_?dispatch" { target { { ! x32 } && *-*-linux* } } } } */
001c85
 /* { dg-final { scan-assembler-times "jmp\[ \t\]*\.LIND" 2 } } */
001c85
 /* { dg-final { scan-assembler-times "call\[ \t\]*\.LIND" 2 } } */
001c85
 /* { dg-final { scan-assembler-times {\tpause} 1 } } */
001c85
diff --git a/gcc/testsuite/gcc.target/i386/indirect-thunk-inline-7.c b/gcc/testsuite/gcc.target/i386/indirect-thunk-inline-7.c
001c85
index d02b1dc..764a375 100644
001c85
--- a/gcc/testsuite/gcc.target/i386/indirect-thunk-inline-7.c
001c85
+++ b/gcc/testsuite/gcc.target/i386/indirect-thunk-inline-7.c
001c85
@@ -1,5 +1,5 @@
001c85
 /* { dg-do compile } */
001c85
-/* { dg-options "-O2 -mindirect-branch=thunk-inline -fno-pic" } */
001c85
+/* { dg-options "-O2 -mfunction-return=keep -mindirect-branch=thunk-inline -fno-pic" } */
001c85
 
001c85
 void func0 (void);
001c85
 void func1 (void);
001c85
@@ -35,7 +35,7 @@ bar (int i)
001c85
     }
001c85
 }
001c85
 
001c85
-/* { dg-final { scan-assembler "push(?:l|q)\[ \t\]*\.L\[0-9\]+\\(,%" { target { ! x32 } } } } */
001c85
+/* { dg-final { scan-assembler "push(?:l|q)\[ \t\]*\.L\[0-9\]+\\(,%" { target { { ! x32 } && *-*-linux* } } } } */
001c85
 /* { dg-final { scan-assembler-not "pushq\[ \t\]%rax" { target x32 } } } */
001c85
 /* { dg-final { scan-assembler "jmp\[ \t\]*\.LIND" } } */
001c85
 /* { dg-final { scan-assembler "call\[ \t\]*\.LIND" } } */
001c85
diff --git a/gcc/testsuite/gcc.target/i386/ret-thunk-1.c b/gcc/testsuite/gcc.target/i386/ret-thunk-1.c
001c85
new file mode 100644
001c85
index 0000000..7223f67
001c85
--- /dev/null
001c85
+++ b/gcc/testsuite/gcc.target/i386/ret-thunk-1.c
001c85
@@ -0,0 +1,13 @@
001c85
+/* { dg-do compile } */
001c85
+/* { dg-options "-O2 -mfunction-return=thunk" } */
001c85
+
001c85
+void
001c85
+foo (void)
001c85
+{
001c85
+}
001c85
+
001c85
+/* { dg-final { scan-assembler "jmp\[ \t\]*__x86_return_thunk" } } */
001c85
+/* { dg-final { scan-assembler "jmp\[ \t\]*\.LIND" } } */
001c85
+/* { dg-final { scan-assembler "call\[ \t\]*\.LIND" } } */
001c85
+/* { dg-final { scan-assembler {\tpause} } } */
001c85
+/* { dg-final { scan-assembler {\tlfence} } } */
001c85
diff --git a/gcc/testsuite/gcc.target/i386/ret-thunk-10.c b/gcc/testsuite/gcc.target/i386/ret-thunk-10.c
001c85
new file mode 100644
001c85
index 0000000..3a6727b
001c85
--- /dev/null
001c85
+++ b/gcc/testsuite/gcc.target/i386/ret-thunk-10.c
001c85
@@ -0,0 +1,23 @@
001c85
+/* { dg-do compile } */
001c85
+/* { dg-options "-O2 -mfunction-return=thunk-inline -mindirect-branch=thunk -fno-pic" } */
001c85
+
001c85
+extern void (*bar) (void);
001c85
+
001c85
+int
001c85
+foo (void)
001c85
+{
001c85
+  bar ();
001c85
+  return 0;
001c85
+}
001c85
+
001c85
+/* { dg-final { scan-assembler "jmp\[ \t\]*\.LIND" } } */
001c85
+/* { dg-final { scan-assembler "call\[ \t\]*\.LIND" } } */
001c85
+/* { dg-final { scan-assembler-not "jmp\[ \t\]*__x86_return_thunk" } } */
001c85
+/* { dg-final { scan-assembler-times {\tpause} 2 } } */
001c85
+/* { dg-final { scan-assembler-times {\tlfence} 2 } } */
001c85
+/* { dg-final { scan-assembler "push(?:l|q)\[ \t\]*_?bar" { target { { ! x32 } && *-*-linux* } } } } */
001c85
+/* { dg-final { scan-assembler "jmp\[ \t\]*__x86_indirect_thunk" { target { ! x32 } }  } } */
001c85
+/* { dg-final { scan-assembler "__x86_indirect_thunk:" { target { ! x32 } }  } } */
001c85
+/* { dg-final { scan-assembler "call\[ \t\]*__x86_indirect_thunk_(r|e)ax" { target { x32 } }  } } */
001c85
+/* { dg-final { scan-assembler "__x86_indirect_thunk_(r|e)ax:" { target { x32 } }  } } */
001c85
+/* { dg-final { scan-assembler-not "pushq\[ \t\]%rax" { target x32 } } } */
001c85
diff --git a/gcc/testsuite/gcc.target/i386/ret-thunk-11.c b/gcc/testsuite/gcc.target/i386/ret-thunk-11.c
001c85
new file mode 100644
001c85
index 0000000..b8f6818
001c85
--- /dev/null
001c85
+++ b/gcc/testsuite/gcc.target/i386/ret-thunk-11.c
001c85
@@ -0,0 +1,23 @@
001c85
+/* { dg-do compile } */
001c85
+/* { dg-options "-O2 -mfunction-return=thunk-extern -mindirect-branch=thunk -fno-pic" } */
001c85
+
001c85
+extern void (*bar) (void);
001c85
+
001c85
+int
001c85
+foo (void)
001c85
+{
001c85
+  bar ();
001c85
+  return 0;
001c85
+}
001c85
+
001c85
+/* { dg-final { scan-assembler "jmp\[ \t\]*__x86_return_thunk" } } */
001c85
+/* { dg-final { scan-assembler-times {\tpause} 1 } } */
001c85
+/* { dg-final { scan-assembler-times {\tlfence} 1 } } */
001c85
+/* { dg-final { scan-assembler "jmp\[ \t\]*\.LIND" } } */
001c85
+/* { dg-final { scan-assembler "call\[ \t\]*\.LIND" } } */
001c85
+/* { dg-final { scan-assembler "push(?:l|q)\[ \t\]*_?bar" { target { { ! x32 } && *-*-linux* } } } } */
001c85
+/* { dg-final { scan-assembler "jmp\[ \t\]*__x86_indirect_thunk" { target { ! x32 } } } } */
001c85
+/* { dg-final { scan-assembler "__x86_indirect_thunk:" { target { ! x32 } }  } } */
001c85
+/* { dg-final { scan-assembler "call\[ \t\]*__x86_indirect_thunk_(r|e)ax" { target { x32 } }  } } */
001c85
+/* { dg-final { scan-assembler "__x86_indirect_thunk_(r|e)ax:" { target { x32 } }  } } */
001c85
+/* { dg-final { scan-assembler-not "pushq\[ \t\]%rax" { target x32 } } } */
001c85
diff --git a/gcc/testsuite/gcc.target/i386/ret-thunk-12.c b/gcc/testsuite/gcc.target/i386/ret-thunk-12.c
001c85
new file mode 100644
001c85
index 0000000..01b0a02
001c85
--- /dev/null
001c85
+++ b/gcc/testsuite/gcc.target/i386/ret-thunk-12.c
001c85
@@ -0,0 +1,22 @@
001c85
+/* { dg-do compile } */
001c85
+/* { dg-options "-O2 -mfunction-return=keep -mindirect-branch=thunk -fno-pic" } */
001c85
+
001c85
+extern void (*bar) (void);
001c85
+
001c85
+int
001c85
+foo (void)
001c85
+{
001c85
+  bar ();
001c85
+  return 0;
001c85
+}
001c85
+
001c85
+/* { dg-final { scan-assembler-not "jmp\[ \t\]*__x86_return_thunk" } } */
001c85
+/* { dg-final { scan-assembler-times {\tpause} 1 } } */
001c85
+/* { dg-final { scan-assembler-times {\tlfence} 1 } } */
001c85
+/* { dg-final { scan-assembler "jmp\[ \t\]*\.LIND" } } */
001c85
+/* { dg-final { scan-assembler "call\[ \t\]*\.LIND" } } */
001c85
+/* { dg-final { scan-assembler "jmp\[ \t\]*__x86_indirect_thunk" { target { ! x32 } } } } */
001c85
+/* { dg-final { scan-assembler "__x86_indirect_thunk:" { target { ! x32 } }  } } */
001c85
+/* { dg-final { scan-assembler "call\[ \t\]*__x86_indirect_thunk_(r|e)ax" { target { x32 } }  } } */
001c85
+/* { dg-final { scan-assembler "__x86_indirect_thunk_(r|e)ax:" { target { x32 } }  } } */
001c85
+/* { dg-final { scan-assembler-not "pushq\[ \t\]%rax" { target x32 } } } */
001c85
diff --git a/gcc/testsuite/gcc.target/i386/ret-thunk-13.c b/gcc/testsuite/gcc.target/i386/ret-thunk-13.c
001c85
new file mode 100644
001c85
index 0000000..4b497b5
001c85
--- /dev/null
001c85
+++ b/gcc/testsuite/gcc.target/i386/ret-thunk-13.c
001c85
@@ -0,0 +1,22 @@
001c85
+/* { dg-do compile } */
001c85
+/* { dg-options "-O2 -mfunction-return=keep -mindirect-branch=thunk-inline -fno-pic" } */
001c85
+
001c85
+extern void (*bar) (void);
001c85
+extern int foo (void) __attribute__ ((function_return("thunk")));
001c85
+
001c85
+int
001c85
+foo (void)
001c85
+{
001c85
+  bar ();
001c85
+  return 0;
001c85
+}
001c85
+
001c85
+/* { dg-final { scan-assembler "jmp\[ \t\]*__x86_return_thunk" } } */
001c85
+/* { dg-final { scan-assembler-times {\tpause} 2 } } */
001c85
+/* { dg-final { scan-assembler-times {\tlfence} 2 } } */
001c85
+/* { dg-final { scan-assembler "push(?:l|q)\[ \t\]*_?bar" { target { { ! x32 } && *-*-linux* } } } } */
001c85
+/* { dg-final { scan-assembler-times "jmp\[ \t\]*\.LIND" 3 } } */
001c85
+/* { dg-final { scan-assembler-times "call\[ \t\]*\.LIND" 3 } } */
001c85
+/* { dg-final { scan-assembler-not "jmp\[ \t\]*__x86_indirect_thunk" } } */
001c85
+/* { dg-final { scan-assembler-not "call\[ \t\]*__x86_indirect_thunk_(r|e)ax" { target { x32 } }  } } */
001c85
+/* { dg-final { scan-assembler-not "pushq\[ \t\]%rax" { target x32 } } } */
001c85
diff --git a/gcc/testsuite/gcc.target/i386/ret-thunk-14.c b/gcc/testsuite/gcc.target/i386/ret-thunk-14.c
001c85
new file mode 100644
001c85
index 0000000..4ae4c44
001c85
--- /dev/null
001c85
+++ b/gcc/testsuite/gcc.target/i386/ret-thunk-14.c
001c85
@@ -0,0 +1,22 @@
001c85
+/* { dg-do compile } */
001c85
+/* { dg-options "-O2 -mfunction-return=keep -mindirect-branch=thunk-extern -fno-pic" } */
001c85
+
001c85
+extern void (*bar) (void);
001c85
+
001c85
+__attribute__ ((function_return("thunk-inline")))
001c85
+int
001c85
+foo (void)
001c85
+{
001c85
+  bar ();
001c85
+  return 0;
001c85
+}
001c85
+
001c85
+/* { dg-final { scan-assembler-times {\tpause} 1 } } */
001c85
+/* { dg-final { scan-assembler-times {\tlfence} 1 } } */
001c85
+/* { dg-final { scan-assembler-not "jmp\[ \t\]*__x86_return_thunk" } } */
001c85
+/* { dg-final { scan-assembler "jmp\[ \t\]*\.LIND" } } */
001c85
+/* { dg-final { scan-assembler "call\[ \t\]*\.LIND" } } */
001c85
+/* { dg-final { scan-assembler "push(?:l|q)\[ \t\]*_?bar" { target { { ! x32 } && *-*-linux* } } } } */
001c85
+/* { dg-final { scan-assembler "jmp\[ \t\]*__x86_indirect_thunk" { target { ! x32 } } } } */
001c85
+/* { dg-final { scan-assembler "call\[ \t\]*__x86_indirect_thunk_(r|e)ax" { target { x32 } }  } } */
001c85
+/* { dg-final { scan-assembler-not "pushq\[ \t\]%rax" { target x32 } } } */
001c85
diff --git a/gcc/testsuite/gcc.target/i386/ret-thunk-15.c b/gcc/testsuite/gcc.target/i386/ret-thunk-15.c
001c85
new file mode 100644
001c85
index 0000000..5b5bc76
001c85
--- /dev/null
001c85
+++ b/gcc/testsuite/gcc.target/i386/ret-thunk-15.c
001c85
@@ -0,0 +1,22 @@
001c85
+/* { dg-do compile } */
001c85
+/* { dg-options "-O2 -mfunction-return=keep -mindirect-branch=keep -fno-pic" } */
001c85
+
001c85
+extern void (*bar) (void);
001c85
+
001c85
+__attribute__ ((function_return("thunk-extern"), indirect_branch("thunk")))
001c85
+int
001c85
+foo (void)
001c85
+{
001c85
+  bar ();
001c85
+  return 0;
001c85
+}
001c85
+
001c85
+/* { dg-final { scan-assembler "jmp\[ \t\]*__x86_return_thunk" } } */
001c85
+/* { dg-final { scan-assembler "jmp\[ \t\]*\.LIND" } } */
001c85
+/* { dg-final { scan-assembler "call\[ \t\]*\.LIND" } } */
001c85
+/* { dg-final { scan-assembler-times {\tpause} 1 } } */
001c85
+/* { dg-final { scan-assembler-times {\tlfence} 1 } } */
001c85
+/* { dg-final { scan-assembler "push(?:l|q)\[ \t\]*_?bar" { target { { ! x32 } && *-*-linux* } } } } */
001c85
+/* { dg-final { scan-assembler "jmp\[ \t\]*__x86_indirect_thunk" { target { ! x32 } } } } */
001c85
+/* { dg-final { scan-assembler "call\[ \t\]*__x86_indirect_thunk_(r|e)ax" { target x32 } } } */
001c85
+/* { dg-final { scan-assembler-not "pushq\[ \t\]%rax" { target x32 } } } */
001c85
diff --git a/gcc/testsuite/gcc.target/i386/ret-thunk-16.c b/gcc/testsuite/gcc.target/i386/ret-thunk-16.c
001c85
new file mode 100644
001c85
index 0000000..a16cad1
001c85
--- /dev/null
001c85
+++ b/gcc/testsuite/gcc.target/i386/ret-thunk-16.c
001c85
@@ -0,0 +1,18 @@
001c85
+/* { dg-do compile } */
001c85
+/* { dg-options "-O2 -mfunction-return=thunk-inline -mindirect-branch=thunk-extern -fno-pic" } */
001c85
+
001c85
+extern void (*bar) (void);
001c85
+
001c85
+__attribute__ ((function_return("keep"), indirect_branch("keep")))
001c85
+int
001c85
+foo (void)
001c85
+{
001c85
+  bar ();
001c85
+  return 0;
001c85
+}
001c85
+
001c85
+/* { dg-final { scan-assembler-not "__x86_indirect_thunk" } } */
001c85
+/* { dg-final { scan-assembler-not "__x86_return_thunk" } } */
001c85
+/* { dg-final { scan-assembler-not {\t(lfence|pause)} } } */
001c85
+/* { dg-final { scan-assembler-not "jmp\[ \t\]*\.LIND" } } */
001c85
+/* { dg-final { scan-assembler-not "call\[ \t\]*\.LIND" } } */
001c85
diff --git a/gcc/testsuite/gcc.target/i386/ret-thunk-2.c b/gcc/testsuite/gcc.target/i386/ret-thunk-2.c
001c85
new file mode 100644
001c85
index 0000000..c6659e3
001c85
--- /dev/null
001c85
+++ b/gcc/testsuite/gcc.target/i386/ret-thunk-2.c
001c85
@@ -0,0 +1,13 @@
001c85
+/* { dg-do compile } */
001c85
+/* { dg-options "-O2 -mfunction-return=thunk-inline" } */
001c85
+
001c85
+void
001c85
+foo (void)
001c85
+{
001c85
+}
001c85
+
001c85
+/* { dg-final { scan-assembler "jmp\[ \t\]*\.LIND" } } */
001c85
+/* { dg-final { scan-assembler "call\[ \t\]*\.LIND" } } */
001c85
+/* { dg-final { scan-assembler {\tpause} } } */
001c85
+/* { dg-final { scan-assembler {\tlfence} } } */
001c85
+/* { dg-final { scan-assembler-not "jmp\[ \t\]*__x86_return_thunk" } } */
001c85
diff --git a/gcc/testsuite/gcc.target/i386/ret-thunk-3.c b/gcc/testsuite/gcc.target/i386/ret-thunk-3.c
001c85
new file mode 100644
001c85
index 0000000..0f7f388
001c85
--- /dev/null
001c85
+++ b/gcc/testsuite/gcc.target/i386/ret-thunk-3.c
001c85
@@ -0,0 +1,12 @@
001c85
+/* { dg-do compile } */
001c85
+/* { dg-options "-O2 -mfunction-return=thunk-extern" } */
001c85
+
001c85
+void
001c85
+foo (void)
001c85
+{
001c85
+}
001c85
+
001c85
+/* { dg-final { scan-assembler "jmp\[ \t\]*__x86_return_thunk" } } */
001c85
+/* { dg-final { scan-assembler-not {\t(lfence|pause)} } } */
001c85
+/* { dg-final { scan-assembler-not "jmp\[ \t\]*\.LIND" } } */
001c85
+/* { dg-final { scan-assembler-not "call\[ \t\]*\.LIND" } } */
001c85
diff --git a/gcc/testsuite/gcc.target/i386/ret-thunk-4.c b/gcc/testsuite/gcc.target/i386/ret-thunk-4.c
001c85
new file mode 100644
001c85
index 0000000..9ae37e8
001c85
--- /dev/null
001c85
+++ b/gcc/testsuite/gcc.target/i386/ret-thunk-4.c
001c85
@@ -0,0 +1,12 @@
001c85
+/* { dg-do compile } */
001c85
+/* { dg-options "-O2 -mfunction-return=keep" } */
001c85
+
001c85
+void
001c85
+foo (void)
001c85
+{
001c85
+}
001c85
+
001c85
+/* { dg-final { scan-assembler-not "jmp\[ \t\]*__x86_return_thunk" } } */
001c85
+/* { dg-final { scan-assembler-not {\t(lfence|pause)} } } */
001c85
+/* { dg-final { scan-assembler-not "jmp\[ \t\]*\.LIND" } } */
001c85
+/* { dg-final { scan-assembler-not "call\[ \t\]*\.LIND" } } */
001c85
diff --git a/gcc/testsuite/gcc.target/i386/ret-thunk-5.c b/gcc/testsuite/gcc.target/i386/ret-thunk-5.c
001c85
new file mode 100644
001c85
index 0000000..4bd0d2a
001c85
--- /dev/null
001c85
+++ b/gcc/testsuite/gcc.target/i386/ret-thunk-5.c
001c85
@@ -0,0 +1,15 @@
001c85
+/* { dg-do compile } */
001c85
+/* { dg-options "-O2 -mfunction-return=keep" } */
001c85
+
001c85
+extern void foo (void) __attribute__ ((function_return("thunk")));
001c85
+
001c85
+void
001c85
+foo (void)
001c85
+{
001c85
+}
001c85
+
001c85
+/* { dg-final { scan-assembler "jmp\[ \t\]*__x86_return_thunk" } } */
001c85
+/* { dg-final { scan-assembler "jmp\[ \t\]*\.LIND" } } */
001c85
+/* { dg-final { scan-assembler "call\[ \t\]*\.LIND" } } */
001c85
+/* { dg-final { scan-assembler {\tpause} } } */
001c85
+/* { dg-final { scan-assembler {\tlfence} } } */
001c85
diff --git a/gcc/testsuite/gcc.target/i386/ret-thunk-6.c b/gcc/testsuite/gcc.target/i386/ret-thunk-6.c
001c85
new file mode 100644
001c85
index 0000000..053841f
001c85
--- /dev/null
001c85
+++ b/gcc/testsuite/gcc.target/i386/ret-thunk-6.c
001c85
@@ -0,0 +1,14 @@
001c85
+/* { dg-do compile } */
001c85
+/* { dg-options "-O2 -mfunction-return=keep" } */
001c85
+
001c85
+__attribute__ ((function_return("thunk-inline")))
001c85
+void
001c85
+foo (void)
001c85
+{
001c85
+}
001c85
+
001c85
+/* { dg-final { scan-assembler "jmp\[ \t\]*\.LIND" } } */
001c85
+/* { dg-final { scan-assembler "call\[ \t\]*\.LIND" } } */
001c85
+/* { dg-final { scan-assembler {\tpause} } } */
001c85
+/* { dg-final { scan-assembler {\tlfence} } } */
001c85
+/* { dg-final { scan-assembler-not "jmp\[ \t\]*__x86_return_thunk" } } */
001c85
diff --git a/gcc/testsuite/gcc.target/i386/ret-thunk-7.c b/gcc/testsuite/gcc.target/i386/ret-thunk-7.c
001c85
new file mode 100644
001c85
index 0000000..262e678
001c85
--- /dev/null
001c85
+++ b/gcc/testsuite/gcc.target/i386/ret-thunk-7.c
001c85
@@ -0,0 +1,13 @@
001c85
+/* { dg-do compile } */
001c85
+/* { dg-options "-O2 -mfunction-return=keep" } */
001c85
+
001c85
+__attribute__ ((function_return("thunk-extern")))
001c85
+void
001c85
+foo (void)
001c85
+{
001c85
+}
001c85
+
001c85
+/* { dg-final { scan-assembler "jmp\[ \t\]*__x86_return_thunk" } } */
001c85
+/* { dg-final { scan-assembler-not {\t(lfence|pause)} } } */
001c85
+/* { dg-final { scan-assembler-not "jmp\[ \t\]*\.LIND" } } */
001c85
+/* { dg-final { scan-assembler-not "call\[ \t\]*\.LIND" } } */
001c85
diff --git a/gcc/testsuite/gcc.target/i386/ret-thunk-8.c b/gcc/testsuite/gcc.target/i386/ret-thunk-8.c
001c85
new file mode 100644
001c85
index 0000000..c1658e9
001c85
--- /dev/null
001c85
+++ b/gcc/testsuite/gcc.target/i386/ret-thunk-8.c
001c85
@@ -0,0 +1,14 @@
001c85
+/* { dg-do compile } */
001c85
+/* { dg-options "-O2 -mfunction-return=thunk-inline" } */
001c85
+
001c85
+extern void foo (void) __attribute__ ((function_return("keep")));
001c85
+
001c85
+void
001c85
+foo (void)
001c85
+{
001c85
+}
001c85
+
001c85
+/* { dg-final { scan-assembler-not "jmp\[ \t\]*__x86_return_thunk" } } */
001c85
+/* { dg-final { scan-assembler-not {\t(lfence|pause)} } } */
001c85
+/* { dg-final { scan-assembler-not "jmp\[ \t\]*\.LIND" } } */
001c85
+/* { dg-final { scan-assembler-not "call\[ \t\]*\.LIND" } } */
001c85
diff --git a/gcc/testsuite/gcc.target/i386/ret-thunk-9.c b/gcc/testsuite/gcc.target/i386/ret-thunk-9.c
001c85
new file mode 100644
001c85
index 0000000..fa24a1f
001c85
--- /dev/null
001c85
+++ b/gcc/testsuite/gcc.target/i386/ret-thunk-9.c
001c85
@@ -0,0 +1,24 @@
001c85
+/* { dg-do compile } */
001c85
+/* { dg-options "-O2 -mfunction-return=thunk -mindirect-branch=thunk -fno-pic" } */
001c85
+
001c85
+extern void (*bar) (void);
001c85
+
001c85
+int
001c85
+foo (void)
001c85
+{
001c85
+  bar ();
001c85
+  return 0;
001c85
+}
001c85
+
001c85
+/* { dg-final { scan-assembler "jmp\[ \t\]*__x86_return_thunk" } } */
001c85
+/* { dg-final { scan-assembler "jmp\[ \t\]*\.LIND" } } */
001c85
+/* { dg-final { scan-assembler "call\[ \t\]*\.LIND" } } */
001c85
+/* { dg-final { scan-assembler "__x86_indirect_thunk:" } } */
001c85
+/* { dg-final { scan-assembler-times {\tpause} 1 { target { ! x32 } } } } */
001c85
+/* { dg-final { scan-assembler-times {\tlfence} 1 { target { ! x32 } } } } */
001c85
+/* { dg-final { scan-assembler "push(?:l|q)\[ \t\]*_?bar" { target { { ! x32 } && *-*-linux* } } } } */
001c85
+/* { dg-final { scan-assembler "jmp\[ \t\]*__x86_indirect_thunk" { target { ! x32 } } } } */
001c85
+/* { dg-final { scan-assembler-times {\tpause} 2 { target { x32 } } } } */
001c85
+/* { dg-final { scan-assembler-times {\tlfence} 2 { target { x32 } } } } */
001c85
+/* { dg-final { scan-assembler "call\[ \t\]*__x86_indirect_thunk_(r|e)ax" { target { x32 } } } } */
001c85
+/* { dg-final { scan-assembler-not "pushq\[ \t\]%rax" { target x32 } } } */