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 @@ -2652,6 +2652,7 @@ // are calls between uses). SmallPtrSet TempsToInstrument; SmallVector ToInstrument; + SmallVector IntrinToInstrument; SmallVector NoReturnCalls; SmallVector AllBlocks; SmallVector PointerComparisonsOrSubtracts; @@ -2688,8 +2689,11 @@ isInterestingPointerSubtraction(&Inst))) { PointerComparisonsOrSubtracts.push_back(&Inst); continue; - } else if (isa(Inst)) { + } else if (MemIntrinsic *MI = dyn_cast(&Inst)) { // ok, take it. + IntrinToInstrument.push_back(MI); + NumInsnsPerBB++; + continue; } else { if (isa(Inst)) NumAllocas++; if (auto *CB = dyn_cast(&Inst)) { @@ -2708,9 +2712,9 @@ } } - bool UseCalls = - (ClInstrumentationWithCallsThreshold >= 0 && - ToInstrument.size() > (unsigned)ClInstrumentationWithCallsThreshold); + bool UseCalls = (ClInstrumentationWithCallsThreshold >= 0 && + ToInstrument.size() + IntrinToInstrument.size() > + (unsigned)ClInstrumentationWithCallsThreshold); const DataLayout &DL = F.getParent()->getDataLayout(); ObjectSizeOpts ObjSizeOpts; ObjSizeOpts.RoundToAlign = true; @@ -2723,9 +2727,11 @@ if (isInterestingMemoryAccess(Inst, &IsWrite, &TypeSize, &Alignment)) instrumentMop(ObjSizeVis, Inst, UseCalls, F.getParent()->getDataLayout()); - else - instrumentMemIntrinsic(cast(Inst)); } + } + for (auto Inst : IntrinToInstrument) { + if (!suppressInstrumentationSiteForDebug(NumInstrumented)) + instrumentMemIntrinsic(Inst); FunctionModified = true; } diff --git a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp --- a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp @@ -720,11 +720,6 @@ uint64_t TypeSize = 0; Value *MaybeMask = nullptr; - if (ClInstrumentMemIntrinsics && isa(I)) { - instrumentMemIntrinsic(cast(I)); - return true; - } - Value *Addr = isInterestingMemoryAccess(I, &IsWrite, &TypeSize, &Alignment, &MaybeMask); @@ -1090,6 +1085,7 @@ LLVM_DEBUG(dbgs() << "Function: " << F.getName() << "\n"); SmallVector ToInstrument; + SmallVector IntrinToInstrument; SmallVector AllocasToInstrument; SmallVector RetVec; SmallVector LandingPadVec; @@ -1121,8 +1117,11 @@ uint64_t TypeSize; Value *Addr = isInterestingMemoryAccess(&Inst, &IsWrite, &TypeSize, &Alignment, &MaybeMask); - if (Addr || isa(Inst)) + if (Addr) ToInstrument.push_back(&Inst); + + if (MemIntrinsic *MI = dyn_cast(&Inst)) + IntrinToInstrument.push_back(MI); } } @@ -1138,7 +1137,8 @@ F.setPersonalityFn(nullptr); } - if (AllocasToInstrument.empty() && ToInstrument.empty()) + if (AllocasToInstrument.empty() && ToInstrument.empty() && + IntrinToInstrument.empty()) return false; assert(!LocalDynamicShadow); @@ -1219,6 +1219,12 @@ for (auto Inst : ToInstrument) Changed |= instrumentMemAccess(Inst); + if (ClInstrumentMemIntrinsics && !IntrinToInstrument.empty()) { + for (auto Inst : IntrinToInstrument) + instrumentMemIntrinsic(cast(Inst)); + Changed = true; + } + LocalDynamicShadow = nullptr; StackBaseTag = nullptr;