1 ; RUN: opt < %s -passes='function(tsan),module(tsan-module)' -S | FileCheck %s
3 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"
4 target triple = "x86_64-unknown-linux-gnu"
6 define i32 @read_4_bytes(ptr %a) sanitize_thread {
8 %tmp1 = load i32, ptr %a, align 4
12 ; CHECK: @llvm.used = appending global [1 x ptr] [ptr @tsan.module_ctor]
13 ; CHECK: @llvm.global_ctors = {{.*}}@tsan.module_ctor
15 ; CHECK: define i32 @read_4_bytes(ptr %a)
16 ; CHECK: call void @__tsan_func_entry(ptr %0)
17 ; CHECK-NEXT: call void @__tsan_read4(ptr %a)
18 ; CHECK-NEXT: %tmp1 = load i32, ptr %a, align 4
19 ; CHECK-NEXT: call void @__tsan_func_exit()
23 declare void @llvm.memcpy.p0.p0.i64(ptr nocapture, ptr nocapture, i64, i1)
24 declare void @llvm.memcpy.inline.p0.p0.i64(ptr nocapture, ptr nocapture, i64, i1)
25 declare void @llvm.memmove.p0.p0.i64(ptr nocapture, ptr nocapture, i64, i1)
26 declare void @llvm.memset.p0.i64(ptr nocapture, i8, i64, i1)
27 declare void @llvm.memset.inline.p0.i64(ptr nocapture, i8, i64, i1)
30 ; Check that tsan converts mem intrinsics back to function calls.
32 define void @MemCpyTest(ptr nocapture %x, ptr nocapture %y) sanitize_thread {
34 tail call void @llvm.memcpy.p0.p0.i64(ptr align 4 %x, ptr align 4 %y, i64 16, i1 false)
36 ; CHECK: define void @MemCpyTest
37 ; CHECK: call ptr @__tsan_memcpy
41 define void @MemCpyInlineTest(ptr nocapture %x, ptr nocapture %y) sanitize_thread {
43 tail call void @llvm.memcpy.inline.p0.p0.i64(ptr align 4 %x, ptr align 4 %y, i64 16, i1 false)
45 ; CHECK: define void @MemCpyInlineTest
46 ; CHECK: call ptr @__tsan_memcpy
50 define void @MemMoveTest(ptr nocapture %x, ptr nocapture %y) sanitize_thread {
52 tail call void @llvm.memmove.p0.p0.i64(ptr align 4 %x, ptr align 4 %y, i64 16, i1 false)
54 ; CHECK: define void @MemMoveTest
55 ; CHECK: call ptr @__tsan_memmove
59 define void @MemSetTest(ptr nocapture %x) sanitize_thread {
61 tail call void @llvm.memset.p0.i64(ptr align 4 %x, i8 77, i64 16, i1 false)
63 ; CHECK: define void @MemSetTest
64 ; CHECK: call ptr @__tsan_memset
68 define void @MemSetInlineTest(ptr nocapture %x) sanitize_thread {
70 tail call void @llvm.memset.inline.p0.i64(ptr align 4 %x, i8 77, i64 16, i1 false)
72 ; CHECK: define void @MemSetInlineTest
73 ; CHECK: call ptr @__tsan_memset
77 ; CHECK-LABEL: @SwiftError
78 ; CHECK-NOT: __tsan_read
79 ; CHECK-NOT: __tsan_write
81 define void @SwiftError(ptr swifterror) sanitize_thread {
82 %swifterror_ptr_value = load ptr, ptr %0
83 store ptr null, ptr %0
84 %swifterror_addr = alloca swifterror ptr
85 %swifterror_ptr_value_2 = load ptr, ptr %swifterror_addr
86 store ptr null, ptr %swifterror_addr
90 ; CHECK-LABEL: @SwiftErrorCall
91 ; CHECK-NOT: __tsan_read
92 ; CHECK-NOT: __tsan_write
94 define void @SwiftErrorCall(ptr swifterror) sanitize_thread {
95 %swifterror_addr = alloca swifterror ptr
96 store ptr null, ptr %0
97 call void @SwiftError(ptr %0)
101 ; CHECK-LABEL: @NakedTest()
102 ; CHECK-NEXT: %a = call ptr @foo()
103 ; CHECK-NEXT: %tmp1 = load i32, ptr %a, align 4
104 ; CHECK-NEXT: ret i32 %tmp1
105 define i32 @NakedTest() naked sanitize_thread {
107 %tmp1 = load i32, ptr %a, align 4
111 ; vscale is unsupported, just don't crash here.
112 define void @test_load_store_i32(ptr %a, ptr %b) sanitize_thread {
113 ; CHECK-LABEL: define void @test_load_store_i32(
114 ; CHECK-SAME: ptr [[A:%.*]], ptr [[B:%.*]])
115 ; CHECK-NEXT: [[TMP1:%.*]] = load <vscale x 4 x i32>, ptr [[A]], align 16
116 ; CHECK-NEXT: store <vscale x 4 x i32> [[TMP1]], ptr [[B]], align 16
117 ; CHECK-NEXT: ret void
118 %1 = load <vscale x 4 x i32>, ptr %a
119 store <vscale x 4 x i32> %1, ptr %b
123 declare void @foo() nounwind
125 ; CHECK: define internal void @tsan.module_ctor()
126 ; CHECK: call void @__tsan_init()