1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -msan-check-access-address=0 -msan-track-origins=1 -msan-eager-checks -S -passes='module(msan)' 2>&1 | \
3 ; RUN: FileCheck -allow-deprecated-dag-overlap --check-prefix=CHECK %s
4 ; RUN: opt < %s -msan-check-access-address=0 -msan-track-origins=1 -S -passes='msan<eager-checks>' 2>&1 | \
5 ; RUN: FileCheck -allow-deprecated-dag-overlap --check-prefix=CHECK %s
7 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-S128"
8 target triple = "x86_64-unknown-linux-gnu"
10 define noundef i32 @NormalRet() nounwind uwtable sanitize_memory {
11 ; CHECK-LABEL: @NormalRet(
12 ; CHECK-NEXT: call void @llvm.donothing()
13 ; CHECK-NEXT: ret i32 123
18 define i32 @PartialRet() nounwind uwtable sanitize_memory {
19 ; CHECK-LABEL: @PartialRet(
20 ; CHECK-NEXT: call void @llvm.donothing()
21 ; CHECK-NEXT: store i32 0, ptr @__msan_retval_tls, align 8
22 ; CHECK-NEXT: store i32 0, ptr @__msan_retval_origin_tls, align 4
23 ; CHECK-NEXT: ret i32 123
28 define noundef i32 @LoadedRet() nounwind uwtable sanitize_memory {
29 ; CHECK-LABEL: @LoadedRet(
30 ; CHECK-NEXT: call void @llvm.donothing()
31 ; CHECK-NEXT: [[P:%.*]] = inttoptr i64 0 to ptr
32 ; CHECK-NEXT: [[O:%.*]] = load i32, ptr [[P]], align 4
33 ; CHECK-NEXT: [[TMP1:%.*]] = ptrtoint ptr [[P]] to i64
34 ; CHECK-NEXT: [[TMP2:%.*]] = xor i64 [[TMP1]], 87960930222080
35 ; CHECK-NEXT: [[TMP3:%.*]] = inttoptr i64 [[TMP2]] to ptr
36 ; CHECK-NEXT: [[TMP4:%.*]] = add i64 [[TMP2]], 17592186044416
37 ; CHECK-NEXT: [[TMP5:%.*]] = inttoptr i64 [[TMP4]] to ptr
38 ; CHECK-NEXT: [[_MSLD:%.*]] = load i32, ptr [[TMP3]], align 4
39 ; CHECK-NEXT: [[TMP6:%.*]] = load i32, ptr [[TMP5]], align 4
40 ; CHECK-NEXT: [[_MSCMP:%.*]] = icmp ne i32 [[_MSLD]], 0
41 ; CHECK-NEXT: br i1 [[_MSCMP]], label [[TMP7:%.*]], label [[TMP8:%.*]], !prof [[PROF0:![0-9]+]]
43 ; CHECK-NEXT: call void @__msan_warning_with_origin_noreturn(i32 [[TMP6]]) #[[ATTR3:[0-9]+]]
44 ; CHECK-NEXT: unreachable
46 ; CHECK-NEXT: ret i32 [[O]]
48 %p = inttoptr i64 0 to ptr
54 define void @NormalArg(i32 noundef %a) nounwind uwtable sanitize_memory {
55 ; CHECK-LABEL: @NormalArg(
56 ; CHECK-NEXT: call void @llvm.donothing()
57 ; CHECK-NEXT: [[P:%.*]] = inttoptr i64 0 to ptr
58 ; CHECK-NEXT: [[TMP1:%.*]] = ptrtoint ptr [[P]] to i64
59 ; CHECK-NEXT: [[TMP2:%.*]] = xor i64 [[TMP1]], 87960930222080
60 ; CHECK-NEXT: [[TMP3:%.*]] = inttoptr i64 [[TMP2]] to ptr
61 ; CHECK-NEXT: [[TMP4:%.*]] = add i64 [[TMP2]], 17592186044416
62 ; CHECK-NEXT: [[TMP5:%.*]] = inttoptr i64 [[TMP4]] to ptr
63 ; CHECK-NEXT: store i32 0, ptr [[TMP3]], align 4
64 ; CHECK-NEXT: store i32 [[A:%.*]], ptr [[P]], align 4
65 ; CHECK-NEXT: ret void
67 %p = inttoptr i64 0 to ptr
72 define void @NormalArgAfterNoUndef(i32 noundef %a, i32 %b) nounwind uwtable sanitize_memory {
73 ; CHECK-LABEL: @NormalArgAfterNoUndef(
74 ; CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr inttoptr (i64 add (i64 ptrtoint (ptr @__msan_param_tls to i64), i64 8) to ptr), align 8
75 ; CHECK-NEXT: [[TMP2:%.*]] = load i32, ptr inttoptr (i64 add (i64 ptrtoint (ptr @__msan_param_origin_tls to i64), i64 8) to ptr), align 4
76 ; CHECK-NEXT: call void @llvm.donothing()
77 ; CHECK-NEXT: [[P:%.*]] = inttoptr i64 0 to ptr
78 ; CHECK-NEXT: [[TMP3:%.*]] = ptrtoint ptr [[P]] to i64
79 ; CHECK-NEXT: [[TMP4:%.*]] = xor i64 [[TMP3]], 87960930222080
80 ; CHECK-NEXT: [[TMP5:%.*]] = inttoptr i64 [[TMP4]] to ptr
81 ; CHECK-NEXT: [[TMP6:%.*]] = add i64 [[TMP4]], 17592186044416
82 ; CHECK-NEXT: [[TMP7:%.*]] = inttoptr i64 [[TMP6]] to ptr
83 ; CHECK-NEXT: store i32 [[TMP1]], ptr [[TMP5]], align 4
84 ; CHECK-NEXT: [[_MSCMP:%.*]] = icmp ne i32 [[TMP1]], 0
85 ; CHECK-NEXT: br i1 [[_MSCMP]], label [[TMP8:%.*]], label [[TMP9:%.*]], !prof [[PROF0]]
87 ; CHECK-NEXT: store i32 [[TMP2]], ptr [[TMP7]], align 4
88 ; CHECK-NEXT: br label [[TMP9]]
90 ; CHECK-NEXT: store i32 [[B:%.*]], ptr [[P]], align 4
91 ; CHECK-NEXT: ret void
93 %p = inttoptr i64 0 to ptr
98 define void @PartialArg(i32 %a) nounwind uwtable sanitize_memory {
99 ; CHECK-LABEL: @PartialArg(
100 ; CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr @__msan_param_tls, align 8
101 ; CHECK-NEXT: [[TMP2:%.*]] = load i32, ptr @__msan_param_origin_tls, align 4
102 ; CHECK-NEXT: call void @llvm.donothing()
103 ; CHECK-NEXT: [[P:%.*]] = inttoptr i64 0 to ptr
104 ; CHECK-NEXT: [[TMP3:%.*]] = ptrtoint ptr [[P]] to i64
105 ; CHECK-NEXT: [[TMP4:%.*]] = xor i64 [[TMP3]], 87960930222080
106 ; CHECK-NEXT: [[TMP5:%.*]] = inttoptr i64 [[TMP4]] to ptr
107 ; CHECK-NEXT: [[TMP6:%.*]] = add i64 [[TMP4]], 17592186044416
108 ; CHECK-NEXT: [[TMP7:%.*]] = inttoptr i64 [[TMP6]] to ptr
109 ; CHECK-NEXT: store i32 [[TMP1]], ptr [[TMP5]], align 4
110 ; CHECK-NEXT: [[_MSCMP:%.*]] = icmp ne i32 [[TMP1]], 0
111 ; CHECK-NEXT: br i1 [[_MSCMP]], label [[TMP8:%.*]], label [[TMP9:%.*]], !prof [[PROF0]]
113 ; CHECK-NEXT: store i32 [[TMP2]], ptr [[TMP7]], align 4
114 ; CHECK-NEXT: br label [[TMP9]]
116 ; CHECK-NEXT: store i32 [[A:%.*]], ptr [[P]], align 4
117 ; CHECK-NEXT: ret void
119 %p = inttoptr i64 0 to ptr
124 define void @CallNormal() nounwind uwtable sanitize_memory {
125 ; CHECK-LABEL: @CallNormal(
126 ; CHECK-NEXT: call void @llvm.donothing()
127 ; CHECK-NEXT: [[R:%.*]] = call i32 @NormalRet() #[[ATTR0:[0-9]+]]
128 ; CHECK-NEXT: call void @NormalArg(i32 [[R]]) #[[ATTR0]]
129 ; CHECK-NEXT: ret void
131 %r = call i32 @NormalRet() nounwind uwtable sanitize_memory
132 call void @NormalArg(i32 %r) nounwind uwtable sanitize_memory
136 define void @CallNormalArgAfterNoUndef() nounwind uwtable sanitize_memory {
137 ; CHECK-LABEL: @CallNormalArgAfterNoUndef(
138 ; CHECK-NEXT: call void @llvm.donothing()
139 ; CHECK-NEXT: [[R:%.*]] = call i32 @NormalRet() #[[ATTR0]]
140 ; CHECK-NEXT: store i32 0, ptr inttoptr (i64 add (i64 ptrtoint (ptr @__msan_param_tls to i64), i64 8) to ptr), align 8
141 ; CHECK-NEXT: call void @NormalArgAfterNoUndef(i32 [[R]], i32 [[R]]) #[[ATTR0]]
142 ; CHECK-NEXT: ret void
144 %r = call i32 @NormalRet() nounwind uwtable sanitize_memory
145 call void @NormalArgAfterNoUndef(i32 %r, i32 %r) nounwind uwtable sanitize_memory
149 define void @CallWithLoaded() nounwind uwtable sanitize_memory {
150 ; CHECK-LABEL: @CallWithLoaded(
151 ; CHECK-NEXT: call void @llvm.donothing()
152 ; CHECK-NEXT: [[P:%.*]] = inttoptr i64 0 to ptr
153 ; CHECK-NEXT: [[O:%.*]] = load i32, ptr [[P]], align 4
154 ; CHECK-NEXT: [[TMP1:%.*]] = ptrtoint ptr [[P]] to i64
155 ; CHECK-NEXT: [[TMP2:%.*]] = xor i64 [[TMP1]], 87960930222080
156 ; CHECK-NEXT: [[TMP3:%.*]] = inttoptr i64 [[TMP2]] to ptr
157 ; CHECK-NEXT: [[TMP4:%.*]] = add i64 [[TMP2]], 17592186044416
158 ; CHECK-NEXT: [[TMP5:%.*]] = inttoptr i64 [[TMP4]] to ptr
159 ; CHECK-NEXT: [[_MSLD:%.*]] = load i32, ptr [[TMP3]], align 4
160 ; CHECK-NEXT: [[TMP6:%.*]] = load i32, ptr [[TMP5]], align 4
161 ; CHECK-NEXT: [[_MSCMP:%.*]] = icmp ne i32 [[_MSLD]], 0
162 ; CHECK-NEXT: br i1 [[_MSCMP]], label [[TMP7:%.*]], label [[TMP8:%.*]], !prof [[PROF0]]
164 ; CHECK-NEXT: call void @__msan_warning_with_origin_noreturn(i32 [[TMP6]]) #[[ATTR3]]
165 ; CHECK-NEXT: unreachable
167 ; CHECK-NEXT: call void @NormalArg(i32 [[O]]) #[[ATTR0]]
168 ; CHECK-NEXT: ret void
170 %p = inttoptr i64 0 to ptr
171 %o = load i32, ptr %p
172 call void @NormalArg(i32 %o) nounwind uwtable sanitize_memory
176 define void @CallPartial() nounwind uwtable sanitize_memory {
177 ; CHECK-LABEL: @CallPartial(
178 ; CHECK-NEXT: call void @llvm.donothing()
179 ; CHECK-NEXT: store i32 0, ptr @__msan_retval_tls, align 8
180 ; CHECK-NEXT: [[R:%.*]] = call i32 @PartialRet() #[[ATTR0]]
181 ; CHECK-NEXT: [[_MSRET:%.*]] = load i32, ptr @__msan_retval_tls, align 8
182 ; CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr @__msan_retval_origin_tls, align 4
183 ; CHECK-NEXT: store i32 [[_MSRET]], ptr @__msan_param_tls, align 8
184 ; CHECK-NEXT: store i32 [[TMP1]], ptr @__msan_param_origin_tls, align 4
185 ; CHECK-NEXT: call void @PartialArg(i32 [[R]]) #[[ATTR0]]
186 ; CHECK-NEXT: ret void
188 %r = call i32 @PartialRet() nounwind uwtable sanitize_memory
189 call void @PartialArg(i32 %r) nounwind uwtable sanitize_memory