Skip to content

Commit

Permalink
imsi
Browse files Browse the repository at this point in the history
  • Loading branch information
purplepig4657 committed Sep 5, 2024
1 parent 51586b2 commit 104c791
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class PreciseLeakSanVisitor : public InstVisitor<PreciseLeakSanVisitor> {
void visitStoreInst(StoreInst &I);
void visitReturnInst(ReturnInst &I);
void visitCallInst(CallInst &I);
void visitInvokeInst(InvokeInst &I);
void visitMemIntrinsics(MemIntrinsic &I);
void pushNewLocalVarListStack();
void pushNewBuiltinAllocaStack();
Expand Down
26 changes: 26 additions & 0 deletions llvm/lib/Transforms/Instrumentation/PreciseLeakSanitizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/Passes/PassBuilder.h"
#include "llvm/Passes/PassPlugin.h"
Expand Down Expand Up @@ -186,6 +187,31 @@ void PreciseLeakSanVisitor::visitCallInst(CallInst &I) {
IntrinToInstrument.push_back(MI);
}

void PreciseLeakSanVisitor::visitInvokeInst(InvokeInst &I) {
if (I.getType()->isPointerTy()) {
Value *RetAddr = &I;
Instruction *LastInst = InstructionTraceTopDown(&I);
IRBuilder<> Builder(LastInst);
if (StoreInst *Inst = dyn_cast<StoreInst>(LastInst)) {
Value *CompareAddr = Inst->getValueOperand();
Plsan.CreateCallWithMetaData(Builder, Plsan.CheckReturnedOrStoredValueFn,
{RetAddr, CompareAddr});
} else if (ReturnInst *Inst = dyn_cast<ReturnInst>(LastInst)) {
Value *CompareAddr = Inst->getReturnValue();
// if return value is void
if (CompareAddr == NULL)
CompareAddr = ConstantPointerNull::get(Plsan.VoidPtrTy);
Plsan.CreateCallWithMetaData(Builder, Plsan.CheckReturnedOrStoredValueFn,
{RetAddr, CompareAddr});
} else {
Instruction *nextInst = I.getNextNode();
if (nextInst)
Builder.SetInsertPoint(I.getNextNode());
Plsan.CreateCallWithMetaData(Builder, Plsan.CheckMemoryLeakFn, {RetAddr});
}
}
}

void PreciseLeakSanVisitor::visitMemIntrinsics(MemIntrinsic &I) {
IRBuilder<> Builder(&I);
if (MemSetInst *Inst = dyn_cast<MemSetInst>(&I)) {
Expand Down

0 comments on commit 104c791

Please sign in to comment.