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 @@ -662,6 +662,7 @@ 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); @@ -753,6 +754,7 @@ AsanDetectStackUseAfterReturnMode UseAfterReturn; Type *IntptrTy; Type *Int8PtrTy; + Type *Int32Ty; ShadowMapping Mapping; FunctionCallee AsanHandleNoReturnFunc; FunctionCallee AsanPtrCmpFunction, AsanPtrSubFunction; @@ -1772,25 +1774,26 @@ } 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); - Module *M = IRB.GetInsertBlock()->getParent()->getParent(); - IRB.CreateCall( - Intrinsic::getDeclaration(M, Intrinsic::asan_check_memaccess), - {Ptr8, ConstantInt::get(IRB.getInt32Ty(), AccessInfo.Packed)}); - } else { - if (Exp == 0) - IRB.CreateCall(AsanMemoryAccessCallback[IsWrite][0][AccessSizeIndex], - AddrLong); - else - IRB.CreateCall(AsanMemoryAccessCallback[IsWrite][1][AccessSizeIndex], - {AddrLong, ConstantInt::get(IRB.getInt32Ty(), Exp)}); - } + if (Exp == 0) + IRB.CreateCall(AsanMemoryAccessCallback[IsWrite][0][AccessSizeIndex], + AddrLong); + else + IRB.CreateCall(AsanMemoryAccessCallback[IsWrite][1][AccessSizeIndex], + {AddrLong, ConstantInt::get(IRB.getInt32Ty(), Exp)}); return; }