1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 11:13:28 +01:00
llvm-mirror/test/Instrumentation/ThreadSanitizer/tsan_musttail.ll
Xun Li 7bfa6044db [TSAN] Handle musttail call properly in EscapeEnumerator (and TSAN)
Call instructions with musttail tag must be optimized as a tailcall, otherwise could lead to incorrect program behavior.
When TSAN is instrumenting functions, it broke the contract by adding a call to the tsan exit function inbetween the musttail call and return instruction, and also inserted exception handling code.
This happend throguh EscapeEnumerator, which adds exception handling code and returns ret instructions as the place to insert instrumentation calls.
This becomes especially problematic for coroutines, because coroutines rely on tail calls to do symmetric transfers properly.
To fix this, this patch moves the location to insert instrumentation calls prior to the musttail call for ret instructions that are following musttail calls, and also does not handle exception for musttail calls.

Differential Revision: https://reviews.llvm.org/D87620
2020-09-15 15:20:05 -07:00

31 lines
1.2 KiB
LLVM

; To test that __tsan_func_exit always happen before musttaill call and no exception handling code.
; RUN: opt < %s -tsan -S | FileCheck %s
define internal i32 @preallocated_musttail(i32* preallocated(i32) %p) sanitize_thread {
%rv = load i32, i32* %p
ret i32 %rv
}
define i32 @call_preallocated_musttail(i32* preallocated(i32) %a) sanitize_thread {
%r = musttail call i32 @preallocated_musttail(i32* preallocated(i32) %a)
ret i32 %r
}
; CHECK-LABEL: define i32 @call_preallocated_musttail(i32* preallocated(i32) %a)
; CHECK: call void @__tsan_func_exit()
; CHECK-NEXT: %r = musttail call i32 @preallocated_musttail(i32* preallocated(i32) %a)
; CHECK-NEXT: ret i32 %r
define i32 @call_preallocated_musttail_cast(i32* preallocated(i32) %a) sanitize_thread {
%r = musttail call i32 @preallocated_musttail(i32* preallocated(i32) %a)
%t = bitcast i32 %r to i32
ret i32 %t
}
; CHECK-LABEL: define i32 @call_preallocated_musttail_cast(i32* preallocated(i32) %a)
; CHECK: call void @__tsan_func_exit()
; CHECK-NEXT: %r = musttail call i32 @preallocated_musttail(i32* preallocated(i32) %a)
; CHECK-NEXT: %t = bitcast i32 %r to i32
; CHECK-NEXT: ret i32 %t