Index: gcc/ipa-split.c
===================================================================
--- gcc/ipa-split.c	(Revision 221427)
+++ gcc/ipa-split.c	(Arbeitskopie)
@@ -1509,6 +1509,16 @@ split_function (struct split_point *split_point)
 	  || DECL_BY_REFERENCE (DECL_RESULT (current_function_decl))))
     gimple_call_set_return_slot_opt (call, true);
 
+  /* Re-insert a TSAN_FUNC_EXIT immediately _before_ the actual call,
+     because we are effectively calling ourselves, so the call stack
+     should look correct this way, and it does not prevent the
+     possible tail-call optimization.  */
+  if ((flag_sanitize & SANITIZE_THREAD) != 0
+      && !lookup_attribute ("no_sanitize_thread",
+			    DECL_ATTRIBUTES (current_function_decl)))
+    gsi_insert_after (&gsi, gimple_build_call_internal (IFN_TSAN_FUNC_EXIT, 0),
+		      GSI_NEW_STMT);
+
   /* Update return value.  This is bit tricky.  When we do not return,
      do nothing.  When we return we might need to update return_bb
      or produce a new return statement.  */
Index: gcc/tsan.c
===================================================================
--- gcc/tsan.c	(Revision 221427)
+++ gcc/tsan.c	(Arbeitskopie)
@@ -682,6 +682,7 @@ instrument_gimple (gimple_stmt_iterator *gsi)
     {
       if (gimple_call_builtin_p (stmt, BUILT_IN_NORMAL))
 	instrument_builtin_call (gsi);
+      gimple_call_set_tail (as_a <gcall *> (stmt), false);
       return true;
     }
   else if (is_gimple_assign (stmt)
