Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add race checker #1419

Merged
merged 2 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 3 additions & 21 deletions svf-llvm/tools/SABER/saber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,6 @@
using namespace llvm;
using namespace SVF;

static Option<bool> LEAKCHECKER(
"leak",
"Memory Leak Detection",
false
);

static Option<bool> FILECHECKER(
"fileck",
"File Open/Close Detection",
false
);

static Option<bool> DFREECHECKER(
"dfree",
"Double Free Detection",
false
);

int main(int argc, char ** argv)
{

Expand All @@ -77,11 +59,11 @@ int main(int argc, char ** argv)

std::unique_ptr<LeakChecker> saber;

if(LEAKCHECKER())
if(Options::MemoryLeakCheck())
saber = std::make_unique<LeakChecker>();
else if(FILECHECKER())
else if(Options::FileCheck())
saber = std::make_unique<FileChecker>();
else if(DFREECHECKER())
else if(Options::DFreeCheck())
saber = std::make_unique<DoubleFreeChecker>();
else
saber = std::make_unique<LeakChecker>(); // if no checker is specified, we use leak checker as the default one.
Expand Down
10 changes: 9 additions & 1 deletion svf/include/Util/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,16 @@ class Options
static const Option<u32_t> Timeout;
/// bug info output file, Default: output.db
static const Option<std::string> OutputName;
/// open buffer overflow checker, Default: false
/// buffer overflow checker, Default: false
static const Option<bool> BufferOverflowCheck;
/// memory leak check, Default: false
static const Option<bool> MemoryLeakCheck;
/// file open close checker, Default: false
static const Option<bool> FileCheck;
/// double free checker, Default: false
static const Option<bool> DFreeCheck;
/// data race checker, Default: false
static const Option<bool> RaceCheck;
/// if the access index of gepstmt is unknown, skip it, Default: false
static const Option<bool> GepUnknownIdx;
static const Option<bool> RunUncallFuncs;
Expand Down
45 changes: 21 additions & 24 deletions svf/lib/MTA/MTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@
mhp = computeMHP(pag->getModule());
lsa = computeLocksets(mhp->getTCT());



if(Options::RaceCheck())
detect(pag->getModule());

Check warning on line 68 in svf/lib/MTA/MTA.cpp

View check run for this annotation

Codecov / codecov/patch

svf/lib/MTA/MTA.cpp#L68

Added line #L68 was not covered by tests
/*
if (Options::AndersenAnno()) {
pta = mhp->getTCT()->getPTA();
Expand Down Expand Up @@ -157,9 +157,9 @@
}

///*!
// * Check (1) write-write race
// * (2) write-read race
// * (3) read-read race
// * Check (1) write-read race
// * (2) write-write race (optional)
// * (3) read-read race (optional)
// * when two memory access may-happen in parallel and are not protected by the same lock
// * (excluding global constraints because they are initialized before running the main function)
// */
Expand All @@ -168,9 +168,10 @@

DBOUT(DGENERAL, outs() << pasMsg("Starting Race Detection\n"));

LoadSet loads;
StoreSet stores;
Set<const LoadStmt*> loads;
Set<const StoreStmt*> stores;
SVFIR* pag = SVFIR::getPAG();
PointerAnalysis* pta = AndersenWaveDiff::createAndersenWaveDiff(pag);

Check warning on line 174 in svf/lib/MTA/MTA.cpp

View check run for this annotation

Codecov / codecov/patch

svf/lib/MTA/MTA.cpp#L174

Added line #L174 was not covered by tests

Set<const SVFInstruction*> needcheckinst;
// Add symbols for all of the functions and the instructions in them.
Expand All @@ -181,37 +182,33 @@
{
for (const SVFInstruction* svfInst : svfbb->getInstructionList())
{

for(const SVFStmt* stmt : pag->getSVFStmtList(pag->getICFG()->getICFGNode(svfInst)))
{
if (SVFUtil::isa<LoadStmt>(stmt))
if (const LoadStmt* l = SVFUtil::dyn_cast<LoadStmt>(stmt))

Check warning on line 187 in svf/lib/MTA/MTA.cpp

View check run for this annotation

Codecov / codecov/patch

svf/lib/MTA/MTA.cpp#L187

Added line #L187 was not covered by tests
{
loads.insert(svfInst);
loads.insert(l);
}
else if (SVFUtil::isa<StoreStmt>(stmt))
else if (const StoreStmt* s = SVFUtil::dyn_cast<StoreStmt>(stmt))

Check warning on line 191 in svf/lib/MTA/MTA.cpp

View check run for this annotation

Codecov / codecov/patch

svf/lib/MTA/MTA.cpp#L191

Added line #L191 was not covered by tests
{
stores.insert(svfInst);
stores.insert(s);
}
}
}
}
}

for (LoadSet::const_iterator lit = loads.begin(), elit = loads.end(); lit != elit; ++lit)
for (Set<const LoadStmt*>::const_iterator lit = loads.begin(), elit = loads.end(); lit != elit; ++lit)

Check warning on line 200 in svf/lib/MTA/MTA.cpp

View check run for this annotation

Codecov / codecov/patch

svf/lib/MTA/MTA.cpp#L200

Added line #L200 was not covered by tests
{
const SVFInstruction* load = *lit;
bool loadneedcheck = false;
for (StoreSet::const_iterator sit = stores.begin(), esit = stores.end(); sit != esit; ++sit)
const LoadStmt* load = *lit;
for (Set<const StoreStmt*>::const_iterator sit = stores.begin(), esit = stores.end(); sit != esit; ++sit)

Check warning on line 203 in svf/lib/MTA/MTA.cpp

View check run for this annotation

Codecov / codecov/patch

svf/lib/MTA/MTA.cpp#L202-L203

Added lines #L202 - L203 were not covered by tests
{
const SVFInstruction* store = *sit;

loadneedcheck = true;
needcheckinst.insert(store);
const StoreStmt* store = *sit;
if(load->getInst()==nullptr || store->getInst()==nullptr)
continue;
if(mhp->mayHappenInParallelInst(load->getInst(),store->getInst()) && pta->alias(load->getRHSVarID(),store->getLHSVarID()))
if(lsa->isProtectedByCommonLock(load->getInst(),store->getInst()) == false)
outs() << SVFUtil::bugMsg1("race pair(") << " store: " << store->toString() << ", load: " << load->toString() << SVFUtil::bugMsg1(")") << "\n";

Check warning on line 210 in svf/lib/MTA/MTA.cpp

View check run for this annotation

Codecov / codecov/patch

svf/lib/MTA/MTA.cpp#L205-L210

Added lines #L205 - L210 were not covered by tests
}
if (loadneedcheck)
needcheckinst.insert(load);
}

outs() << "HP needcheck: " << needcheckinst.size() << "\n";
}

8 changes: 8 additions & 0 deletions svf/lib/Util/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,14 @@ const Option<std::string> Options::OutputName(
"output","output db file","output.db");
const Option<bool> Options::BufferOverflowCheck(
"overflow","Buffer Overflow Detection",false);
const Option<bool> Options::MemoryLeakCheck(
"leak", "Memory Leak Detection",false);
const Option<bool> Options::FileCheck(
"fileck", "File Open/Close Detection",false);
const Option<bool> Options::DFreeCheck(
"dfree", "Double Free Detection",false);
const Option<bool> Options::RaceCheck(
"race", "Data race Detection",false);
const Option<bool> Options::GepUnknownIdx(
"gep-unknown-idx","Skip Gep Unknown Index",false);
const Option<bool> Options::RunUncallFuncs(
Expand Down
Loading