1 ; RUN: opt < %s -tsan -S | FileCheck %s
2 ; RUN: opt < %s -passes='function(tsan),module(tsan-module)' -S | FileCheck %s
4 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
5 target triple = "x86_64-unknown-linux-gnu"
7 define i32 @read_4_bytes(i32* %a) sanitize_thread {
9 %tmp1 = load i32, i32* %a, align 4
13 ; CHECK: @llvm.global_ctors = {{.*}}@tsan.module_ctor
15 ; CHECK: define i32 @read_4_bytes(i32* %a)
16 ; CHECK: call void @__tsan_func_entry(i8* %0)
17 ; CHECK-NEXT: %1 = bitcast i32* %a to i8*
18 ; CHECK-NEXT: call void @__tsan_read4(i8* %1)
19 ; CHECK-NEXT: %tmp1 = load i32, i32* %a, align 4
20 ; CHECK-NEXT: call void @__tsan_func_exit()
24 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i1)
25 declare void @llvm.memmove.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i1)
26 declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i1)
29 ; Check that tsan converts mem intrinsics back to function calls.
31 define void @MemCpyTest(i8* nocapture %x, i8* nocapture %y) sanitize_thread {
33 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 %x, i8* align 4 %y, i64 16, i1 false)
35 ; CHECK: define void @MemCpyTest
36 ; CHECK: call i8* @memcpy
40 define void @MemMoveTest(i8* nocapture %x, i8* nocapture %y) sanitize_thread {
42 tail call void @llvm.memmove.p0i8.p0i8.i64(i8* align 4 %x, i8* align 4 %y, i64 16, i1 false)
44 ; CHECK: define void @MemMoveTest
45 ; CHECK: call i8* @memmove
49 define void @MemSetTest(i8* nocapture %x) sanitize_thread {
51 tail call void @llvm.memset.p0i8.i64(i8* align 4 %x, i8 77, i64 16, i1 false)
53 ; CHECK: define void @MemSetTest
54 ; CHECK: call i8* @memset
58 ; CHECK-LABEL: @SwiftError
59 ; CHECK-NOT: __tsan_read
60 ; CHECK-NOT: __tsan_write
62 define void @SwiftError(i8** swifterror) sanitize_thread {
63 %swifterror_ptr_value = load i8*, i8** %0
64 store i8* null, i8** %0
65 %swifterror_addr = alloca swifterror i8*
66 %swifterror_ptr_value_2 = load i8*, i8** %swifterror_addr
67 store i8* null, i8** %swifterror_addr
71 ; CHECK-LABEL: @SwiftErrorCall
72 ; CHECK-NOT: __tsan_read
73 ; CHECK-NOT: __tsan_write
75 define void @SwiftErrorCall(i8** swifterror) sanitize_thread {
76 %swifterror_addr = alloca swifterror i8*
77 store i8* null, i8** %0
78 call void @SwiftError(i8** %0)
81 ; CHECK: define internal void @tsan.module_ctor()
82 ; CHECK: call void @__tsan_init()