llvm.org GIT mirror llvm / 62776a8
[asan] Don't skip instrumentation of masked load/store unless we've seen a full load/store on that pointer. Reviewers: kcc, RKSimon Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D27625 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289718 91177308-0d34-0410-b5e6-96231b3b80d8 Filipe Cabecinhas 3 years ago
2 changed file(s) with 74 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
20652065 int NumInsnsPerBB = 0;
20662066 for (auto &Inst : BB) {
20672067 if (LooksLikeCodeInBug11395(&Inst)) return false;
2068 Value *MaybeMask = nullptr;
20682069 if (Value *Addr = isInterestingMemoryAccess(&Inst, &IsWrite, &TypeSize,
2069 &Alignment)) {
2070 &Alignment, &MaybeMask)) {
20702071 if (ClOpt && ClOptSameTemp) {
2071 if (!TempsToInstrument.insert(Addr).second)
2072 continue; // We've seen this temp in the current BB.
2072 // If we have a mask, skip instrumentation if we've already
2073 // instrumented the full object. But don't add to TempsToInstrument
2074 // because we might get another load/store with a different mask.
2075 if (MaybeMask) {
2076 if (TempsToInstrument.count(Addr))
2077 continue; // We've seen this (whole) temp in the current BB.
2078 } else {
2079 if (!TempsToInstrument.insert(Addr).second)
2080 continue; // We've seen this temp in the current BB.
2081 }
20732082 }
20742083 } else if (ClInvalidPointerPairs &&
20752084 isInterestingPointerComparisonOrSubtraction(&Inst)) {
7474 %p = load <4 x float>*, <4 x float>** @v4f32, align 8
7575 ; ALL-NOT: call void @__asan_store
7676 tail call void @llvm.masked.store.v4f32.p0v4f32(<4 x float> %arg, <4 x float>* %p, i32 4, <4 x i1> %mask)
77 ret void
78 }
79
80 ;; Store using two masked.stores, which should instrument them both.
81 define void @store.v4f32.1010.split(<4 x float> %arg) sanitize_address {
82 ; BOTH-LABEL: @store.v4f32.1010.split
83 %p = load <4 x float>*, <4 x float>** @v4f32, align 8
84 ; STORE: [[GEP0:%[0-9A-Za-z]+]] = getelementptr <4 x float>, <4 x float>* %p, i64 0, i64 0
85 ; STORE: [[PGEP0:%[0-9A-Za-z]+]] = ptrtoint float* [[GEP0]] to i64
86 ; STORE: call void @__asan_store4(i64 [[PGEP0]])
87 ; STORE: tail call void @llvm.masked.store.v4f32.p0v4f32(<4 x float> %arg, <4 x float>* %p, i32 4, <4 x i1> )
88 tail call void @llvm.masked.store.v4f32.p0v4f32(<4 x float> %arg, <4 x float>* %p, i32 4, <4 x i1> )
89 ; STORE: [[GEP1:%[0-9A-Za-z]+]] = getelementptr <4 x float>, <4 x float>* %p, i64 0, i64 2
90 ; STORE: [[PGEP1:%[0-9A-Za-z]+]] = ptrtoint float* [[GEP1]] to i64
91 ; STORE: call void @__asan_store4(i64 [[PGEP1]])
92 ; STORE: tail call void @llvm.masked.store.v4f32.p0v4f32(<4 x float> %arg, <4 x float>* %p, i32 4, <4 x i1> )
93 tail call void @llvm.masked.store.v4f32.p0v4f32(<4 x float> %arg, <4 x float>* %p, i32 4, <4 x i1> )
94 ret void
95 }
96
97 ;; Store using a masked.store after a full store. Shouldn't instrument the second one.
98 define void @store.v4f32.0010.after.full.store(<4 x float> %arg) sanitize_address {
99 ; BOTH-LABEL: @store.v4f32.0010.after.full.store
100 %p = load <4 x float>*, <4 x float>** @v4f32, align 8
101 ; STORE: [[PTRTOINT:%[0-9A-Za-z]+]] = ptrtoint <4 x float>* %p to i64
102 ; STORE: call void @__asan_store16(i64 [[PTRTOINT]])
103 ; STORE: store <4 x float> %arg, <4 x float>* %p
104 store <4 x float> %arg, <4 x float>* %p
105 ; STORE-NOT: call void @__asan_store
106 ; STORE: tail call void @llvm.masked.store.v4f32.p0v4f32(<4 x float> %arg, <4 x float>* %p, i32 4, <4 x i1> )
107 tail call void @llvm.masked.store.v4f32.p0v4f32(<4 x float> %arg, <4 x float>* %p, i32 4, <4 x i1> )
77108 ret void
78109 }
79110
137168 %res = tail call <4 x float> @llvm.masked.load.v4f32.p0v4f32(<4 x float>* %p, i32 4, <4 x i1> %mask, <4 x float> %arg)
138169 ret <4 x float> %res
139170 }
171
172 ;; Load using two masked.loads, which should instrument them both.
173 define <4 x float> @load.v4f32.1001.split(<4 x float> %arg) sanitize_address {
174 ; BOTH-LABEL: @load.v4f32.1001
175 %p = load <4 x float>*, <4 x float>** @v4f32, align 8
176 ; LOAD: [[GEP0:%[0-9A-Za-z]+]] = getelementptr <4 x float>, <4 x float>* %p, i64 0, i64 0
177 ; LOAD: [[PGEP0:%[0-9A-Za-z]+]] = ptrtoint float* [[GEP0]] to i64
178 ; LOAD: call void @__asan_load4(i64 [[PGEP0]])
179 ; LOAD: %res = tail call <4 x float> @llvm.masked.load.v4f32.p0v4f32(<4 x float>* %p, i32 4, <4 x i1> , <4 x float> %arg)
180 %res = tail call <4 x float> @llvm.masked.load.v4f32.p0v4f32(<4 x float>* %p, i32 4, <4 x i1> , <4 x float> %arg)
181 ; LOAD: [[GEP3:%[0-9A-Za-z]+]] = getelementptr <4 x float>, <4 x float>* %p, i64 0, i64 3
182 ; LOAD: [[PGEP3:%[0-9A-Za-z]+]] = ptrtoint float* [[GEP3]] to i64
183 ; LOAD: call void @__asan_load4(i64 [[PGEP3]])
184 ; LOAD: tail call <4 x float> @llvm.masked.load.v4f32.p0v4f32(<4 x float>* %p, i32 4, <4 x i1> , <4 x float> %res)
185 %res2 = tail call <4 x float> @llvm.masked.load.v4f32.p0v4f32(<4 x float>* %p, i32 4, <4 x i1> , <4 x float> %res)
186 ret <4 x float> %res2
187 }
188
189 ;; Load using a masked.load after a full load. Shouldn't instrument the second one.
190 define <4 x float> @load.v4f32.1001.after.full.load(<4 x float> %arg) sanitize_address {
191 ; BOTH-LABEL: @load.v4f32.1001.after.full.load
192 %p = load <4 x float>*, <4 x float>** @v4f32, align 8
193 ; LOAD: [[PTRTOINT:%[0-9A-Za-z]+]] = ptrtoint <4 x float>* %p to i64
194 ; LOAD: call void @__asan_load16(i64 [[PTRTOINT]])
195 ; LOAD: %res = load <4 x float>, <4 x float>* %p
196 %res = load <4 x float>, <4 x float>* %p
197 ; LOAD-NOT: call void @__asan_load
198 ; LOAD: tail call <4 x float> @llvm.masked.load.v4f32.p0v4f32(<4 x float>* %p, i32 4, <4 x i1> , <4 x float> %arg)
199 %res2 = tail call <4 x float> @llvm.masked.load.v4f32.p0v4f32(<4 x float>* %p, i32 4, <4 x i1> , <4 x float> %arg)
200 ret <4 x float> %res2
201 }