Skip to content

Commit

Permalink
crits: fix matching variables without information
Browse files Browse the repository at this point in the history
If we do not found a name of variable to an alloca, we must take it
as if it could have an arbitrary name.

Fixes #427.
  • Loading branch information
mchalupa committed May 9, 2022
1 parent c5e0aa0 commit b2801c2
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions tools/llvm-slicer-crit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,21 @@ static inline bool isNumber(const std::string &s) {
return true;
}

static inline bool isTheVar(const llvm::Value *val, const std::string &var) {
static inline bool mayBeTheVar(const llvm::Value *val, const std::string &var) {
auto name = valuesToVariables.find(val);
if (name != valuesToVariables.end()) {
if (name->second == var) {
return true;
}
if (name != valuesToVariables.end() &&
name->second != var) {
return false;
}
return false;
// either the var matches or we do not know the var,
// which we must take as a match
return true;
}

static bool usesTheVariable(const llvm::Instruction &I, const std::string &var,
bool isglobal = false,
LLVMPointerAnalysis *pta = nullptr) {

if (!I.mayReadOrWriteMemory())
return false;

Expand All @@ -58,12 +60,12 @@ static bool usesTheVariable(const llvm::Instruction &I, const std::string &var,
using namespace llvm;
if (auto *S = dyn_cast<StoreInst>(&I)) {
auto *A = S->getPointerOperand()->stripPointerCasts();
if (isa<AllocaInst>(A) && !isTheVar(A, var)) {
if (isa<AllocaInst>(A) && !mayBeTheVar(A, var)) {
return false;
}
} else if (auto *L = dyn_cast<LoadInst>(&I)) {
auto *A = L->getPointerOperand()->stripPointerCasts();
if (isa<AllocaInst>(A) && !isTheVar(A, var)) {
if (isa<AllocaInst>(A) && !mayBeTheVar(A, var)) {
return false;
}
}
Expand All @@ -84,7 +86,7 @@ static bool usesTheVariable(const llvm::Instruction &I, const std::string &var,
!llvm::isa<llvm::GlobalVariable>(region.pointer.value)) {
continue;
}
if (isTheVar(region.pointer.value, var)) {
if (mayBeTheVar(region.pointer.value, var)) {
return true;
}
}
Expand Down

0 comments on commit b2801c2

Please sign in to comment.