15 using namespace SVFUtil;
31 return lsa->isProtectedByCommonLock(inst1, inst2);
43 assert((arg_num < cs->arg_size()) &&
"Does not has this argument");
44 const GetElementPtrInst* gepinst = SVFUtil::dyn_cast<GetElementPtrInst>(cs->getArgOperand(arg_num));
45 const Constant* arrayinst = SVFUtil::dyn_cast<Constant>(gepinst->getOperand(0));
46 const ConstantDataArray* cxtarray = SVFUtil::dyn_cast<ConstantDataArray>(arrayinst->getOperand(0));
52 const std::string vthdcxtstring = cxtarray->getAsCString().str();
53 return split(vthdcxtstring,
',');
58 std::stringstream ss(s);
60 while (std::getline(ss,
item, delim))
70 split(s, delim, elems);
100 for(
auto it = M.begin(); it != M.end(); it++)
103 if(fName.find(LOCK) != std::string::npos)
112 for(Value::const_use_iterator it =
F->use_begin(), ie =
F->use_end(); it!=ie; it++)
115 const Value* user = u->getUser();
116 const Instruction* inst = SVFUtil::dyn_cast<Instruction>(user);
118 const Instruction* memInst = getPreviousMemoryAccessInst(inst);
121 instToCxtLockSet[svfMemInst] = y;
122 if(
const StoreInst* store = SVFUtil::dyn_cast<StoreInst> (memInst))
124 if(
const BinaryOperator* bop = SVFUtil::dyn_cast<BinaryOperator> (store->getValueOperand()))
126 const Value* v = bop->getOperand(0);
127 const Instruction* prevInst = SVFUtil::dyn_cast<LoadInst> (v);
129 instToCxtLockSet[svfPrevInst] = y;
141 for(LockAnalysis::CxtStmtToCxtLockSet::iterator it = analyedLS.begin(),
142 eit = analyedLS.end(); it!=eit; it++)
145 bool interestedInst =
true;
148 if(!SVFUtil::isa<LoadStmt>(stmt) && !SVFUtil::isa<StoreStmt>(stmt))
149 interestedInst =
false;
151 if(interestedInst==
false)
154 if(inFilter(
F->getName()))
157 if(LS.size() != (*it).second.size())
162 outs() <<
"Reason: The number of lock on current stmt is wrong\n";
163 outs() <<
"\n----Given locks:\n";
164 for (CxtLockSetStr::iterator it1 = LS.begin(),eit1 = LS.end(); it1 != eit1; it++)
166 outs() <<
"Lock " << *it1 <<
" ";
168 outs() <<
"\n----Analysis locks:\n";
169 for (LockAnalysis::CxtLockSet::iterator it2 = (*it).second.begin(),
170 eit2 = (*it).second.end(); it2 != eit2; ++it)
181 for(LockAnalysis::CxtLockSet::iterator it3 = LSA.begin(), eit3=LSA.end(); it3!=eit3; it3++)
187 if(!match(lockName, LS))
191 outs() <<
"\nValidate Stmt's Lock : Wrong at (" << inst->
toString() <<
")\n";
192 outs() <<
"Reason: The number of lock on current stmt is wrong\n";
193 outs() <<
"\n Lock " << lockName <<
" should not protect current instruction\n";
205 if(!collectLockTargets())
208 errstring = getOutput(
"Validate Lock Analysis :", validateStmtInLock());
209 outs() <<
"======" << errstring <<
"======\n";
212 validator.
init(_la->getTCT()->getSVFModule());
218 I = I->getPrevNode();
221 if (SVFUtil::isa<LoadInst>(I) || SVFUtil::isa<StoreInst>(I))
229 _la->getTCT()->getThreadCallGraph()->getCallees(getCBN(svfInst), callees);
231 for(PTACallGraph::FunctionSet::const_iterator cit = callees.begin(),
232 ecit = callees.end(); cit!=ecit; cit++)
245 if (callee->
getName().find(
"llvm.memset") != std::string::npos)
248 I = I->getPrevNode();
const SVFValue * getArgOperand(u32_t i) const
ICFGNode * getICFGNode(NodeID id) const
Get a ICFG node.
static LLVMModuleSet * getLLVMModuleSet()
SVFInstruction * getSVFInstruction(const Instruction *inst) const
Set< CxtLock > CxtLockSet
Map< CxtStmt, CxtLockSet > CxtStmtToCxtLockSet
static const LOCK_FLAG LOCK_TRUE
static const LOCK_FLAG LOCK_UNSOUND
Set< std::string > getStringArg(const Instruction *inst, unsigned int arg_num)
static const LOCK_FLAG LOCK_IMPRECISE
const Instruction * getPreviousMemoryAccessInst(const Instruction *I)
std::string getOutput(const char *scenario, LOCK_FLAG analysisRes)
Set< std::string > & split(const std::string &s, char delim, Set< std::string > &elems)
LOCK_FLAG validateStmtInLock()
bool collectLockTargets()
Set< std::string > CxtLockSetStr
static const Option< bool > PrintValidRes
Set< const SVFFunction * > FunctionSet
Validate the result of concurrent analysis.
void init(SVFModule *M)
Initialization.
RaceValidator(LockAnalysis *lockAnalysis)
bool protectedByCommonLocks(const Instruction *I1, const Instruction *I2)
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
SVFStmtList & getSVFStmtList(const ICFGNode *inst)
Given an instruction, get all its PAGEdges.
const SVFFunction * getFunction() const
const std::string & getName() const
std::string toString() const
Needs to be implemented by a SVF front end.
const CallBase * getLLVMCallSite(const Value *value)
Return LLVM callsite given a value.
bool isCallSite(const Instruction *inst)
Whether an instruction is a call or invoke instruction.
std::string sucMsg(const std::string &msg)
Returns successful message by converting a string into green string output.
std::string bugMsg1(const std::string &msg)
std::string pasMsg(const std::string &msg)
Print each pass/phase message by converting a string into blue string output.
std::string errMsg(const std::string &msg)
Print error message by converting a string into red string output.
CallSite getSVFCallSite(const SVFInstruction *inst)
Return LLVM callsite given an instruction.
std::string bugMsg2(const std::string &msg)
std::vector< std::string > split(const std::string &s, char separator)
Split into two substrings around the first occurrence of a separator string.
std::ostream & outs()
Overwrite llvm::outs()
bool isCallSite(const SVFInstruction *inst)
Whether an instruction is a call or invoke instruction.
llvm::Instruction Instruction
llvm::Value Value
LLVM Basic classes.
llvm::BinaryOperator BinaryOperator
llvm::StoreInst StoreInst
llvm::GetElementPtrInst GetElementPtrInst
llvm::ConstantDataArray ConstantDataArray
std::unordered_set< Key, Hash, KeyEqual, Allocator > Set