diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp --- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -661,6 +661,8 @@ C = &(M.getContext()); LongSize = M.getDataLayout().getPointerSizeInBits(); IntptrTy = Type::getIntNTy(*C, LongSize); + Int8PtrTy = Type::getInt8PtrTy(*C); + Int32Ty = Type::getInt32Ty(*C); TargetTriple = Triple(M.getTargetTriple()); Mapping = getShadowMapping(TargetTriple, LongSize, this->CompileKernel); @@ -751,6 +753,8 @@ bool UseAfterScope; AsanDetectStackUseAfterReturnMode UseAfterReturn; Type *IntptrTy; + Type *Int8PtrTy; + Type *Int32Ty; ShadowMapping Mapping; FunctionCallee AsanHandleNoReturnFunc; FunctionCallee AsanPtrCmpFunction, AsanPtrSubFunction; @@ -1770,10 +1774,20 @@ } IRBuilder<> IRB(InsertBefore); - Value *AddrLong = IRB.CreatePointerCast(Addr, IntptrTy); size_t AccessSizeIndex = TypeSizeToSizeIndex(TypeSize); const ASanAccessInfo AccessInfo(IsWrite, CompileKernel, AccessSizeIndex); + if (UseCalls && ClOptimizeCallbacks) { + const ASanAccessInfo AccessInfo(IsWrite, CompileKernel, AccessSizeIndex); + Module *M = IRB.GetInsertBlock()->getParent()->getParent(); + IRB.CreateCall( + Intrinsic::getDeclaration(M, Intrinsic::asan_check_memaccess), + {IRB.CreatePointerCast(Addr, Int8PtrTy), + ConstantInt::get(Int32Ty, AccessInfo.Packed)}); + return; + } + + Value *AddrLong = IRB.CreatePointerCast(Addr, IntptrTy); if (UseCalls) { if (ClOptimizeCallbacks) { Value *Ptr8 = IRB.CreatePointerCast(Addr, Int8PtrTy);