Skip to content

Commit

Permalink
SVF code formatter
Browse files Browse the repository at this point in the history
update code

update changes

update

upate
  • Loading branch information
yuleisui authored and JasonZhongZexin committed Sep 13, 2023
1 parent ae326b2 commit fb24d39
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 101 deletions.
5 changes: 3 additions & 2 deletions svf/include/MemoryModel/PointerAnalysisImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,12 @@ class BVDataPTAImpl : public PointerAnalysis
//@{
virtual void writeToFile(const std::string& filename);
virtual void writeObjVarToFile(const std::string& filename);
virtual void writePtsResultToFile(std::fstream& f);
virtual void writeGepObjVarMapToFile(std::fstream& f);
virtual bool readFromFile(const std::string& filename);
virtual void readObjVarFromFile(std::ifstream& f);
virtual void readPtsResultFromFile(std::ifstream& f);
virtual void readGepObjVarMapFromFile(std::ifstream& f);
virtual void updateObjVarStatusFromFile(std::ifstream& f);
virtual void readAndSetObjFieldSensitivity(std::ifstream& f, const std::string& delimiterStr);
//@}

protected:
Expand Down
5 changes: 2 additions & 3 deletions svf/include/SVFIR/SVFIR.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class SVFIR : public IRGraph
friend class TypeBasedHeapCloning;
friend class SVFIRWriter;
friend class SVFIRReader;
friend class BVDataPTAImpl;

public:
typedef Set<const CallICFGNode*> CallSiteSet;
Expand Down Expand Up @@ -391,8 +392,6 @@ class SVFIR : public IRGraph
return node->getMemObj();
}
//@}

void readGepObjNodeFromFile(const NodeID& base, const APOffset& apOffset, const NodeID id);

/// Get a field SVFIR Object node according to base mem obj and offset
NodeID getGepObjVar(const MemObj* obj, const APOffset& ap);
Expand Down Expand Up @@ -562,7 +561,7 @@ class SVFIR : public IRGraph
/// Add a temp field value node, this method can only invoked by getGepValVar
NodeID addGepValNode(const SVFValue* curInst,const SVFValue* val, const AccessPath& ap, NodeID i, const SVFType* type);
/// Add a field obj node, this method can only invoked by getGepObjVar
NodeID addGepObjNode(const MemObj* obj, const APOffset& apOffset);
NodeID addGepObjNode(const MemObj* obj, const APOffset& apOffset, const NodeID gepId);
/// Add a field-insensitive node, this method can only invoked by getFIGepObjNode
NodeID addFIObjNode(const MemObj* obj);
//@}
Expand Down
72 changes: 48 additions & 24 deletions svf/lib/AbstractExecution/SVFIR2ItvExeState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ SVFIR2ItvExeState::VAddrs SVFIR2ItvExeState::getGepObjAddress(u32_t pointer, APO
return ret;
}

std::pair<APOffset, APOffset> SVFIR2ItvExeState::getBytefromGepTypePair(const AccessPath::VarAndGepTypePair& gep_pair, const GepStmt *gep, APOffset elemBytesize) {
std::pair<APOffset, APOffset> SVFIR2ItvExeState::getBytefromGepTypePair(const AccessPath::VarAndGepTypePair& gep_pair, const GepStmt *gep, APOffset elemBytesize)
{
const SVFValue *value = gep_pair.first->getValue();
const SVFType *type = gep_pair.second;
const SVFConstantInt *op = SVFUtil::dyn_cast<SVFConstantInt>(value);
Expand All @@ -182,22 +183,30 @@ std::pair<APOffset, APOffset> SVFIR2ItvExeState::getBytefromGepTypePair(const Ac
/// set largest byte offset is 0xFFFFFF in case of int32 overflow
APOffset maxByteLimit = 99999;
APOffset minByteLimit = -99999;
auto valueReshape = [&](s64_t offset) {
if (offset < (s64_t)minByteLimit) {
auto valueReshape = [&](s64_t offset)
{
if (offset < (s64_t)minByteLimit)
{
return minByteLimit;
} else if (offset > (s64_t)maxByteLimit) {
}
else if (offset > (s64_t)maxByteLimit)
{
return maxByteLimit;
} else {
}
else
{
return offset;
}
};
/// offset is constant but stored in variable
if (op)
{
offsetLb = offsetUb = op->getSExtValue() > maxByteLimit
? maxByteLimit
: op->getSExtValue();
} else {
? maxByteLimit
: op->getSExtValue();
}
else
{
u32_t idx = _svfir->getValueNode(value);
IntervalValue &idxVal = _es[idx];
if (idxVal.isBottom() || idxVal.isTop())
Expand All @@ -206,7 +215,9 @@ std::pair<APOffset, APOffset> SVFIR2ItvExeState::getBytefromGepTypePair(const Ac
if (idxVal.is_numeral())
{
offsetLb = offsetUb = valueReshape(idxVal.lb().getNumeral());
} else {
}
else
{
offsetLb = valueReshape(idxVal.lb().getNumeral());
offsetUb = valueReshape(idxVal.ub().getNumeral());
}
Expand All @@ -229,28 +240,37 @@ std::pair<APOffset, APOffset> SVFIR2ItvExeState::getBytefromGepTypePair(const Ac
}


std::pair<APOffset, APOffset> SVFIR2ItvExeState::getIndexfromGepTypePair(const AccessPath::VarAndGepTypePair& gep_pair, const GepStmt *gep) {
std::pair<APOffset, APOffset> SVFIR2ItvExeState::getIndexfromGepTypePair(const AccessPath::VarAndGepTypePair& gep_pair, const GepStmt *gep)
{
const SVFValue *value = gep_pair.first->getValue();
const SVFType *type = gep_pair.second;
const SVFConstantInt *op = SVFUtil::dyn_cast<SVFConstantInt>(value);
APOffset offsetLb = 0;
APOffset offsetUb = 0;
APOffset maxFieldLimit = (APOffset)Options::MaxFieldLimit();
APOffset minFieldLimit = 0;
auto valueReshape = [&](s64_t offset) {
if (offset < minFieldLimit) {
auto valueReshape = [&](s64_t offset)
{
if (offset < minFieldLimit)
{
return minFieldLimit;
} else if (offset > maxFieldLimit) {
}
else if (offset > maxFieldLimit)
{
return maxFieldLimit;
} else {
}
else
{
return offset;
}
};
/// offset is constant but stored in variable
/// offset is constant but stored in variable
if (op)
{
offsetLb = offsetUb = valueReshape(op->getSExtValue());
} else {
}
else
{
u32_t idx = _svfir->getValueNode(value);
//if (!inVarToIValTable(idx)) return std::make_pair(-1, -1);
IntervalValue &idxVal = _es[idx];
Expand All @@ -260,7 +280,9 @@ std::pair<APOffset, APOffset> SVFIR2ItvExeState::getIndexfromGepTypePair(const A
if (idxVal.is_numeral())
{
offsetLb = offsetUb = valueReshape(idxVal.lb().getNumeral());
} else {
}
else
{
offsetLb = valueReshape(idxVal.lb().getNumeral());
offsetUb = valueReshape(idxVal.ub().getNumeral());
}
Expand All @@ -276,10 +298,10 @@ std::pair<APOffset, APOffset> SVFIR2ItvExeState::getIndexfromGepTypePair(const A
else
{
const std::vector<u32_t>& so = SymbolTableInfo::SymbolInfo()
->getTypeInfo(type)
->getFlattenedElemIdxVec();
->getTypeInfo(type)
->getFlattenedElemIdxVec();
if (so.empty() || offsetUb >= (APOffset)so.size() ||
offsetLb >= (APOffset)so.size())
offsetLb >= (APOffset)so.size())
{
offsetLb = 0;
offsetUb = maxFieldLimit;
Expand All @@ -299,7 +321,8 @@ std::pair<APOffset, APOffset> SVFIR2ItvExeState::getIndexfromGepTypePair(const A
}


std::pair<APOffset, APOffset> SVFIR2ItvExeState::getGepByteOffset(const GepStmt *gep, APOffset elemBytesize) {
std::pair<APOffset, APOffset> SVFIR2ItvExeState::getGepByteOffset(const GepStmt *gep, APOffset elemBytesize)
{
/// for instant constant index, e.g. gep arr, 1
if (gep->getOffsetVarAndGepTypePairVec().empty())
return std::make_pair(gep->getConstantFieldIdx(), gep->getConstantFieldIdx());
Expand All @@ -310,7 +333,7 @@ std::pair<APOffset, APOffset> SVFIR2ItvExeState::getGepByteOffset(const GepStmt
for (int i = gep->getOffsetVarAndGepTypePairVec().size() - 1; i >= 0; i--)
{
std::pair<APOffset, APOffset> offsetIdx = getBytefromGepTypePair(
gep->getOffsetVarAndGepTypePairVec()[i], gep, elemBytesize);
gep->getOffsetVarAndGepTypePairVec()[i], gep, elemBytesize);
APOffset offsetLb = offsetIdx.first;
APOffset offsetUb = offsetIdx.second;
if (totalOffsetLb + offsetLb > maxFieldLimit)
Expand All @@ -326,7 +349,8 @@ std::pair<APOffset, APOffset> SVFIR2ItvExeState::getGepByteOffset(const GepStmt
}


std::pair<APOffset , APOffset> SVFIR2ItvExeState::getGepOffset(const GepStmt *gep) {
std::pair<APOffset, APOffset> SVFIR2ItvExeState::getGepOffset(const GepStmt *gep)
{
/// for instant constant index, e.g. gep arr, 1
if (gep->getOffsetVarAndGepTypePairVec().empty())
return std::make_pair(gep->getConstantFieldIdx(), gep->getConstantFieldIdx());
Expand All @@ -337,7 +361,7 @@ std::pair<APOffset , APOffset> SVFIR2ItvExeState::getGepOffset(const GepStmt *ge
for (int i = gep->getOffsetVarAndGepTypePairVec().size() - 1; i >= 0; i--)
{
std::pair<APOffset, APOffset> offsetIdx = getIndexfromGepTypePair(
gep->getOffsetVarAndGepTypePairVec()[i], gep);
gep->getOffsetVarAndGepTypePairVec()[i], gep);
APOffset offsetLb = offsetIdx.first;
APOffset offsetUb = offsetIdx.second;
if ((long long) (totalOffsetLb + offsetLb) > maxFieldLimit)
Expand Down
92 changes: 49 additions & 43 deletions svf/lib/MemoryModel/PointerAnalysisImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,24 +195,8 @@ void BVDataPTAImpl::writeObjVarToFile(const string& filename)

}

/*!
* Store pointer analysis result into a file.
* It includes the points-to relations, and all SVFIR nodes including those
* created when solving Andersen's constraints.
*/
void BVDataPTAImpl::writeToFile(const string& filename)
void BVDataPTAImpl::writePtsResultToFile(std::fstream& f)
{

outs() << "Storing pointer analysis results to '" << filename << "'...";

error_code err;
std::fstream f(filename.c_str(), std::ios_base::app);
if (!f.good())
{
outs() << " error opening file for writing!\n";
return;
}

// Write analysis results to file
for (auto it = pag->begin(), ie = pag->end(); it != ie; ++it)
{
Expand All @@ -235,8 +219,10 @@ void BVDataPTAImpl::writeToFile(const string& filename)
f << "}\n";
}

f << "------\n";
}

void BVDataPTAImpl::writeGepObjVarMapToFile(std::fstream& f)
{
//write gepObjVarMap to file(in form of: baseID offset gepObjNodeId)
SVFIR::NodeOffsetMap &gepObjVarMap = pag->getGepObjNodeMap();
for(SVFIR::NodeOffsetMap::const_iterator it = gepObjVarMap.begin(), eit = gepObjVarMap.end(); it != eit; it++)
Expand All @@ -250,6 +236,32 @@ void BVDataPTAImpl::writeToFile(const string& filename)
f << it->second << "\n";
}

}

/*!
* Store pointer analysis result into a file.
* It includes the points-to relations, and all SVFIR nodes including those
* created when solving Andersen's constraints.
*/
void BVDataPTAImpl::writeToFile(const string& filename)
{

outs() << "Storing pointer analysis results to '" << filename << "'...";

error_code err;
std::fstream f(filename.c_str(), std::ios_base::app);
if (!f.good())
{
outs() << " error opening file for writing!\n";
return;
}

writePtsResultToFile(f);

f << "------\n";

writeGepObjVarMapToFile(f);

f << "------\n";

// Write BaseNodes insensitivity to file
Expand All @@ -274,25 +286,6 @@ void BVDataPTAImpl::writeToFile(const string& filename)
}
}

void BVDataPTAImpl::readObjVarFromFile(std::ifstream& F)
{
// Read ObjVar
string line;
while (F.good())
{
getline(F, line);
if (line == "------") break;
// Parse a single line in the form of "baseNodeID insensitive"
istringstream ss(line);
NodeID base;
bool insensitive;
ss >> base >> insensitive;

if (insensitive)
setObjFieldInsensitive(base);
}
}

void BVDataPTAImpl::readPtsResultFromFile(std::ifstream& F)
{
string line;
Expand Down Expand Up @@ -352,7 +345,7 @@ void BVDataPTAImpl::readGepObjVarMapFromFile(std::ifstream& F)
string line;
//read GepObjVarMap from file
SVFIR::NodeOffsetMap gepObjVarMap = pag->getGepObjNodeMap();
while (F.good())
while (F.good())
{
getline(F, line);
if (line == "------") break;
Expand All @@ -364,20 +357,33 @@ void BVDataPTAImpl::readGepObjVarMapFromFile(std::ifstream& F)
ss >> base >> offset >>id;
SVFIR::NodeOffsetMap::const_iterator iter = gepObjVarMap.find(std::make_pair(base, offset));
if (iter == gepObjVarMap.end())
pag->readGepObjNodeFromFile(base, offset, id);
{
SVFVar* node = pag->getGNode(base);
const MemObj* obj = nullptr;
if (GepObjVar* gepObjVar = SVFUtil::dyn_cast<GepObjVar>(node))
obj = gepObjVar->getMemObj();
else if (FIObjVar* baseNode = SVFUtil::dyn_cast<FIObjVar>(node))
obj = baseNode->getMemObj();
else if (DummyObjVar* baseNode = SVFUtil::dyn_cast<DummyObjVar>(node))
obj = baseNode->getMemObj();
else
assert(false && "new gep obj node kind?");
pag->addGepObjNode(obj, offset, id);
NodeIDAllocator::get()->increaseNumOfObjAndNodes();
}


}
}

void BVDataPTAImpl::updateObjVarStatusFromFile(std::ifstream& F)
void BVDataPTAImpl::readAndSetObjFieldSensitivity(std::ifstream& F, const std::string& delimiterStr)
{
string line;
// //update ObjVar status
while (F.good())
{
getline(F, line);
if (line.empty())
if (line.empty() || line == delimiterStr)
break;
// Parse a single line in the form of "baseNodeID insensitive"
istringstream ss(line);
Expand Down Expand Up @@ -408,13 +414,13 @@ bool BVDataPTAImpl::readFromFile(const string& filename)
return false;
}

readObjVarFromFile(F);
readAndSetObjFieldSensitivity(F,"------");

readPtsResultFromFile(F);

readGepObjVarMapFromFile(F);

updateObjVarStatusFromFile(F);
readAndSetObjFieldSensitivity(F,"");

// Update callgraph
updateCallGraph(pag->getIndirectCallsites());
Expand Down
Loading

0 comments on commit fb24d39

Please sign in to comment.