@@ -147,11 +147,13 @@ static Value *memToShadow(Module &M, IRBuilder<> &IRB, Type *IntptrTy,
147
147
return IRB.CreateAdd (Shadow, ShadowBase);
148
148
}
149
149
150
- void instrumentAddress (Module &M, IRBuilder<> &IRB, Instruction *OrigIns,
151
- Instruction *InsertBefore, Value *Addr,
152
- MaybeAlign Alignment, uint32_t TypeStoreSize,
153
- bool IsWrite, Value *SizeArgument, bool UseCalls,
154
- bool Recover, int AsanScale, int AsanOffset) {
150
+ static void instrumentAddressImpl (Module &M, IRBuilder<> &IRB,
151
+ Instruction *OrigIns,
152
+ Instruction *InsertBefore, Value *Addr,
153
+ Align Alignment, uint32_t TypeStoreSize,
154
+ bool IsWrite, Value *SizeArgument,
155
+ bool UseCalls, bool Recover, int AsanScale,
156
+ int AsanOffset) {
155
157
Type *AddrTy = Addr->getType ();
156
158
Type *IntptrTy = M.getDataLayout ().getIntPtrType (
157
159
M.getContext (), AddrTy->getPointerAddressSpace ());
@@ -164,7 +166,7 @@ void instrumentAddress(Module &M, IRBuilder<> &IRB, Instruction *OrigIns,
164
166
Value *ShadowPtr =
165
167
memToShadow (M, IRB, IntptrTy, AddrLong, AsanScale, AsanOffset);
166
168
const uint64_t ShadowAlign =
167
- std::max<uint64_t >(Alignment.valueOrOne (). value () >> AsanScale, 1 );
169
+ std::max<uint64_t >(Alignment.value () >> AsanScale, 1 );
168
170
Value *ShadowValue = IRB.CreateAlignedLoad (
169
171
ShadowTy, IRB.CreateIntToPtr (ShadowPtr, ShadowPtrTy), Align (ShadowAlign));
170
172
Value *Cmp = IRB.CreateIsNotNull (ShadowValue);
@@ -179,6 +181,43 @@ void instrumentAddress(Module &M, IRBuilder<> &IRB, Instruction *OrigIns,
179
181
return ;
180
182
}
181
183
184
+ void instrumentAddress (Module &M, IRBuilder<> &IRB, Instruction *OrigIns,
185
+ Instruction *InsertBefore, Value *Addr, Align Alignment,
186
+ TypeSize TypeStoreSize, bool IsWrite,
187
+ Value *SizeArgument, bool UseCalls, bool Recover,
188
+ int AsanScale, int AsanOffset) {
189
+ if (!TypeStoreSize.isScalable ()) {
190
+ unsigned Granularity = 1 << AsanScale;
191
+ const auto FixedSize = TypeStoreSize.getFixedValue ();
192
+ switch (FixedSize) {
193
+ case 8 :
194
+ case 16 :
195
+ case 32 :
196
+ case 64 :
197
+ case 128 :
198
+ if (Alignment.value () >= Granularity ||
199
+ Alignment.value () >= FixedSize / 8 )
200
+ return instrumentAddressImpl (
201
+ M, IRB, OrigIns, InsertBefore, Addr, Alignment, FixedSize, IsWrite,
202
+ SizeArgument, UseCalls, Recover, AsanScale, AsanOffset);
203
+ }
204
+ }
205
+ // Instrument unusual size or unusual alignment.
206
+ IRB.SetInsertPoint (InsertBefore);
207
+ Type *AddrTy = Addr->getType ();
208
+ Type *IntptrTy = M.getDataLayout ().getIntPtrType (AddrTy);
209
+ Value *NumBits = IRB.CreateTypeSize (IntptrTy, TypeStoreSize);
210
+ Value *Size = IRB.CreateLShr (NumBits, ConstantInt::get (IntptrTy, 3 ));
211
+ Value *AddrLong = IRB.CreatePtrToInt (Addr, IntptrTy);
212
+ Value *SizeMinusOne = IRB.CreateAdd (Size, ConstantInt::get (IntptrTy, -1 ));
213
+ Value *LastByte =
214
+ IRB.CreateIntToPtr (IRB.CreateAdd (AddrLong, SizeMinusOne), AddrTy);
215
+ instrumentAddressImpl (M, IRB, OrigIns, InsertBefore, Addr, {}, 8 , IsWrite,
216
+ SizeArgument, UseCalls, Recover, AsanScale, AsanOffset);
217
+ instrumentAddressImpl (M, IRB, OrigIns, InsertBefore, LastByte, {}, 8 , IsWrite,
218
+ SizeArgument, UseCalls, Recover, AsanScale, AsanOffset);
219
+ }
220
+
182
221
void getInterestingMemoryOperands (
183
222
Module &M, Instruction *I,
184
223
SmallVectorImpl<InterestingMemoryOperand> &Interesting) {
0 commit comments