+2018-07-03 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR target/85620
+ * config/i386/i386.c (rest_of_insert_endbranch): Also generate
+ ENDBRANCH for non-tail call which may return via indirect branch.
+ * doc/extend.texi: Document indirect_return attribute.
+
2018-07-03 Martin Sebor <msebor@redhat.com>
PR tree-optimization/86274
{
if (CALL_P (insn))
{
- if (find_reg_note (insn, REG_SETJMP, NULL) == NULL)
+ bool need_endbr;
+ need_endbr = find_reg_note (insn, REG_SETJMP, NULL) != NULL;
+ if (!need_endbr && !SIBLING_CALL_P (insn))
+ {
+ rtx call = get_call_rtx_from (insn);
+ rtx fnaddr = XEXP (call, 0);
+
+ /* Also generate ENDBRANCH for non-tail call which
+ may return via indirect branch. */
+ if (MEM_P (fnaddr)
+ && GET_CODE (XEXP (fnaddr, 0)) == SYMBOL_REF)
+ {
+ tree fndecl = SYMBOL_REF_DECL (XEXP (fnaddr, 0));
+ if (fndecl
+ && lookup_attribute ("indirect_return",
+ DECL_ATTRIBUTES (fndecl)))
+ need_endbr = true;
+ }
+ }
+ if (!need_endbr)
continue;
/* Generate ENDBRANCH after CALL, which can return more than
twice, setjmp-like functions. */
ix86_handle_fndecl_attribute, NULL },
{ "function_return", 1, 1, true, false, false, false,
ix86_handle_fndecl_attribute, NULL },
+ { "indirect_return", 0, 0, true, false, false, false,
+ ix86_handle_fndecl_attribute, NULL },
/* End element. */
{ NULL, 0, 0, false, false, false, false, NULL, NULL }
+2018-07-03 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR target/85620
+ * gcc.target/i386/pr85620-1.c: New test.
+ * gcc.target/i386/pr85620-2.c: Likewise.
+ * gcc.target/i386/pr85620-3.c: Likewise.
+ * gcc.target/i386/pr85620-4.c: Likewise.
+
2018-07-03 Martin Sebor <msebor@redhat.com>
PR tree-optimization/86274