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 | FileCheck -allow-deprecated-dag-overlap --check-prefix=CHECK %s
3 ; RUN: opt < %s -msan-check-access-address=0 -msan-track-origins=1 -S -passes='msan<eager-checks>' 2>&1 | FileCheck -allow-deprecated-dag-overlap --check-prefix=CHECK %s
5 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"
6 target triple = "x86_64-unknown-linux-gnu"
8 define noundef i32 @NormalRet() nounwind uwtable sanitize_memory {
9 ; CHECK-LABEL: @NormalRet(
10 ; CHECK-NEXT: call void @llvm.donothing()
11 ; CHECK-NEXT: ret i32 123
16 define i32 @PartialRet() nounwind uwtable sanitize_memory {
17 ; CHECK-LABEL: @PartialRet(
18 ; CHECK-NEXT: call void @llvm.donothing()
19 ; CHECK-NEXT: store i32 0, ptr @__msan_retval_tls, align 8
20 ; CHECK-NEXT: store i32 0, ptr @__msan_retval_origin_tls, align 4
21 ; CHECK-NEXT: ret i32 123
26 define noundef i32 @LoadedRet() nounwind uwtable sanitize_memory {
27 ; CHECK-LABEL: @LoadedRet(
28 ; CHECK-NEXT: call void @llvm.donothing()
29 ; CHECK-NEXT: [[P:%.*]] = inttoptr i64 0 to ptr
30 ; CHECK-NEXT: [[O:%.*]] = load i32, ptr [[P]], align 4
31 ; CHECK-NEXT: [[TMP1:%.*]] = ptrtoint ptr [[P]] to i64
32 ; CHECK-NEXT: [[TMP2:%.*]] = xor i64 [[TMP1]], 87960930222080
33 ; CHECK-NEXT: [[TMP3:%.*]] = inttoptr i64 [[TMP2]] to ptr
34 ; CHECK-NEXT: [[TMP4:%.*]] = add i64 [[TMP2]], 17592186044416
35 ; CHECK-NEXT: [[TMP5:%.*]] = inttoptr i64 [[TMP4]] to ptr
36 ; CHECK-NEXT: [[_MSLD:%.*]] = load i32, ptr [[TMP3]], align 4
37 ; CHECK-NEXT: [[TMP6:%.*]] = load i32, ptr [[TMP5]], align 4
38 ; CHECK-NEXT: [[_MSCMP:%.*]] = icmp ne i32 [[_MSLD]], 0
39 ; CHECK-NEXT: br i1 [[_MSCMP]], label [[TMP7:%.*]], label [[TMP8:%.*]], !prof [[PROF0:![0-9]+]]
41 ; CHECK-NEXT: call void @__msan_warning_with_origin_noreturn(i32 [[TMP6]]) #[[ATTR3:[0-9]+]]
42 ; CHECK-NEXT: unreachable
44 ; CHECK-NEXT: ret i32 [[O]]
46 %p = inttoptr i64 0 to ptr
52 define void @NormalArg(i32 noundef %a) nounwind uwtable sanitize_memory {
53 ; CHECK-LABEL: @NormalArg(
54 ; CHECK-NEXT: call void @llvm.donothing()
55 ; CHECK-NEXT: [[P:%.*]] = inttoptr i64 0 to ptr
56 ; CHECK-NEXT: [[TMP1:%.*]] = ptrtoint ptr [[P]] to i64
57 ; CHECK-NEXT: [[TMP2:%.*]] = xor i64 [[TMP1]], 87960930222080
58 ; CHECK-NEXT: [[TMP3:%.*]] = inttoptr i64 [[TMP2]] to ptr
59 ; CHECK-NEXT: [[TMP4:%.*]] = add i64 [[TMP2]], 17592186044416
60 ; CHECK-NEXT: [[TMP5:%.*]] = inttoptr i64 [[TMP4]] to ptr
61 ; CHECK-NEXT: store i32 0, ptr [[TMP3]], align 4
62 ; CHECK-NEXT: store i32 [[A:%.*]], ptr [[P]], align 4
63 ; CHECK-NEXT: ret void
65 %p = inttoptr i64 0 to ptr
70 define void @NormalArgAfterNoUndef(i32 noundef %a, i32 %b) nounwind uwtable sanitize_memory {
71 ; CHECK-LABEL: @NormalArgAfterNoUndef(
72 ; CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr inttoptr (i64 add (i64 ptrtoint (ptr @__msan_param_tls to i64), i64 8) to ptr), align 8
73 ; CHECK-NEXT: [[TMP2:%.*]] = load i32, ptr inttoptr (i64 add (i64 ptrtoint (ptr @__msan_param_origin_tls to i64), i64 8) to ptr), align 4
74 ; CHECK-NEXT: call void @llvm.donothing()
75 ; CHECK-NEXT: [[P:%.*]] = inttoptr i64 0 to ptr
76 ; CHECK-NEXT: [[TMP3:%.*]] = ptrtoint ptr [[P]] to i64
77 ; CHECK-NEXT: [[TMP4:%.*]] = xor i64 [[TMP3]], 87960930222080
78 ; CHECK-NEXT: [[TMP5:%.*]] = inttoptr i64 [[TMP4]] to ptr
79 ; CHECK-NEXT: [[TMP6:%.*]] = add i64 [[TMP4]], 17592186044416
80 ; CHECK-NEXT: [[TMP7:%.*]] = inttoptr i64 [[TMP6]] to ptr
81 ; CHECK-NEXT: store i32 [[TMP1]], ptr [[TMP5]], align 4
82 ; CHECK-NEXT: [[_MSCMP:%.*]] = icmp ne i32 [[TMP1]], 0
83 ; CHECK-NEXT: br i1 [[_MSCMP]], label [[TMP8:%.*]], label [[TMP9:%.*]], !prof [[PROF0]]
85 ; CHECK-NEXT: store i32 [[TMP2]], ptr [[TMP7]], align 4
86 ; CHECK-NEXT: br label [[TMP9]]
88 ; CHECK-NEXT: store i32 [[B:%.*]], ptr [[P]], align 4
89 ; CHECK-NEXT: ret void
91 %p = inttoptr i64 0 to ptr
96 define void @PartialArg(i32 %a) nounwind uwtable sanitize_memory {
97 ; CHECK-LABEL: @PartialArg(
98 ; CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr @__msan_param_tls, align 8
99 ; CHECK-NEXT: [[TMP2:%.*]] = load i32, ptr @__msan_param_origin_tls, align 4
100 ; CHECK-NEXT: call void @llvm.donothing()
101 ; CHECK-NEXT: [[P:%.*]] = inttoptr i64 0 to ptr
102 ; CHECK-NEXT: [[TMP3:%.*]] = ptrtoint ptr [[P]] to i64
103 ; CHECK-NEXT: [[TMP4:%.*]] = xor i64 [[TMP3]], 87960930222080
104 ; CHECK-NEXT: [[TMP5:%.*]] = inttoptr i64 [[TMP4]] to ptr
105 ; CHECK-NEXT: [[TMP6:%.*]] = add i64 [[TMP4]], 17592186044416
106 ; CHECK-NEXT: [[TMP7:%.*]] = inttoptr i64 [[TMP6]] to ptr
107 ; CHECK-NEXT: store i32 [[TMP1]], ptr [[TMP5]], align 4
108 ; CHECK-NEXT: [[_MSCMP:%.*]] = icmp ne i32 [[TMP1]], 0
109 ; CHECK-NEXT: br i1 [[_MSCMP]], label [[TMP8:%.*]], label [[TMP9:%.*]], !prof [[PROF0]]
111 ; CHECK-NEXT: store i32 [[TMP2]], ptr [[TMP7]], align 4
112 ; CHECK-NEXT: br label [[TMP9]]
114 ; CHECK-NEXT: store i32 [[A:%.*]], ptr [[P]], align 4
115 ; CHECK-NEXT: ret void
117 %p = inttoptr i64 0 to ptr
122 define void @CallNormal() nounwind uwtable sanitize_memory {
123 ; CHECK-LABEL: @CallNormal(
124 ; CHECK-NEXT: call void @llvm.donothing()
125 ; CHECK-NEXT: [[R:%.*]] = call i32 @NormalRet() #[[ATTR0:[0-9]+]]
126 ; CHECK-NEXT: call void @NormalArg(i32 [[R]]) #[[ATTR0]]
127 ; CHECK-NEXT: ret void
129 %r = call i32 @NormalRet() nounwind uwtable sanitize_memory
130 call void @NormalArg(i32 %r) nounwind uwtable sanitize_memory
134 define void @CallNormalArgAfterNoUndef() nounwind uwtable sanitize_memory {
135 ; CHECK-LABEL: @CallNormalArgAfterNoUndef(
136 ; CHECK-NEXT: call void @llvm.donothing()
137 ; CHECK-NEXT: [[R:%.*]] = call i32 @NormalRet() #[[ATTR0]]
138 ; CHECK-NEXT: store i32 0, ptr inttoptr (i64 add (i64 ptrtoint (ptr @__msan_param_tls to i64), i64 8) to ptr), align 8
139 ; CHECK-NEXT: call void @NormalArgAfterNoUndef(i32 [[R]], i32 [[R]]) #[[ATTR0]]
140 ; CHECK-NEXT: ret void
142 %r = call i32 @NormalRet() nounwind uwtable sanitize_memory
143 call void @NormalArgAfterNoUndef(i32 %r, i32 %r) nounwind uwtable sanitize_memory
147 define void @CallWithLoaded() nounwind uwtable sanitize_memory {
148 ; CHECK-LABEL: @CallWithLoaded(
149 ; CHECK-NEXT: call void @llvm.donothing()
150 ; CHECK-NEXT: [[P:%.*]] = inttoptr i64 0 to ptr
151 ; CHECK-NEXT: [[O:%.*]] = load i32, ptr [[P]], align 4
152 ; CHECK-NEXT: [[TMP1:%.*]] = ptrtoint ptr [[P]] to i64
153 ; CHECK-NEXT: [[TMP2:%.*]] = xor i64 [[TMP1]], 87960930222080
154 ; CHECK-NEXT: [[TMP3:%.*]] = inttoptr i64 [[TMP2]] to ptr
155 ; CHECK-NEXT: [[TMP4:%.*]] = add i64 [[TMP2]], 17592186044416
156 ; CHECK-NEXT: [[TMP5:%.*]] = inttoptr i64 [[TMP4]] to ptr
157 ; CHECK-NEXT: [[_MSLD:%.*]] = load i32, ptr [[TMP3]], align 4
158 ; CHECK-NEXT: [[TMP6:%.*]] = load i32, ptr [[TMP5]], align 4
159 ; CHECK-NEXT: [[_MSCMP:%.*]] = icmp ne i32 [[_MSLD]], 0
160 ; CHECK-NEXT: br i1 [[_MSCMP]], label [[TMP7:%.*]], label [[TMP8:%.*]], !prof [[PROF0]]
162 ; CHECK-NEXT: call void @__msan_warning_with_origin_noreturn(i32 [[TMP6]]) #[[ATTR3]]
163 ; CHECK-NEXT: unreachable
165 ; CHECK-NEXT: call void @NormalArg(i32 [[O]]) #[[ATTR0]]
166 ; CHECK-NEXT: ret void
168 %p = inttoptr i64 0 to ptr
169 %o = load i32, ptr %p
170 call void @NormalArg(i32 %o) nounwind uwtable sanitize_memory
174 define void @CallPartial() nounwind uwtable sanitize_memory {
175 ; CHECK-LABEL: @CallPartial(
176 ; CHECK-NEXT: call void @llvm.donothing()
177 ; CHECK-NEXT: store i32 0, ptr @__msan_retval_tls, align 8
178 ; CHECK-NEXT: [[R:%.*]] = call i32 @PartialRet() #[[ATTR0]]
179 ; CHECK-NEXT: [[_MSRET:%.*]] = load i32, ptr @__msan_retval_tls, align 8
180 ; CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr @__msan_retval_origin_tls, align 4
181 ; CHECK-NEXT: store i32 [[_MSRET]], ptr @__msan_param_tls, align 8
182 ; CHECK-NEXT: store i32 [[TMP1]], ptr @__msan_param_origin_tls, align 4
183 ; CHECK-NEXT: call void @PartialArg(i32 [[R]]) #[[ATTR0]]
184 ; CHECK-NEXT: ret void
186 %r = call i32 @PartialRet() nounwind uwtable sanitize_memory
187 call void @PartialArg(i32 %r) nounwind uwtable sanitize_memory