================ @@ -1078,22 +1091,65 @@ void ModuleSanitizerCoverage::InjectCoverageAtBlock(Function &F, BasicBlock &BB, Store->setNoSanitizeMetadata(); } if (Options.StackDepth && IsEntryBB && !IsLeafFunc) { - // Check stack depth. If it's the deepest so far, record it. Module *M = F.getParent(); - auto FrameAddrPtr = IRB.CreateIntrinsic( - Intrinsic::frameaddress, - IRB.getPtrTy(M->getDataLayout().getAllocaAddrSpace()), - {Constant::getNullValue(Int32Ty)}); - auto FrameAddrInt = IRB.CreatePtrToInt(FrameAddrPtr, IntptrTy); - auto LowestStack = IRB.CreateLoad(IntptrTy, SanCovLowestStack); - auto IsStackLower = IRB.CreateICmpULT(FrameAddrInt, LowestStack); - auto ThenTerm = SplitBlockAndInsertIfThen( - IsStackLower, &*IP, false, - MDBuilder(IRB.getContext()).createUnlikelyBranchWeights()); - IRBuilder<> ThenIRB(ThenTerm); - auto Store = ThenIRB.CreateStore(FrameAddrInt, SanCovLowestStack); - LowestStack->setNoSanitizeMetadata(); - Store->setNoSanitizeMetadata(); + const DataLayout &DL = M->getDataLayout(); + + if (Options.StackDepthCallbackMin) { + // In callback mode, only add call when stack depth reaches minimum. + uint32_t EstimatedStackSize = 0; + // If dynamic alloca found, always add call. + bool HasDynamicAlloc = false; + // Find an insertion point after last "alloca". + llvm::Instruction *InsertBefore = nullptr; + + // Examine all allocas in the basic block. since we're too early + // to have results from Intrinsic::frameaddress, we have to manually + // estimate the stack size. + for (auto &I : BB) { + if (auto *AI = dyn_cast<AllocaInst>(&I)) { + // Move potential insertion point past the "alloca". + InsertBefore = I.getNextNode(); ---------------- kees wrote:
Ah, yeah, good point. Fixed. https://github.com/llvm/llvm-project/pull/138323 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits