Skip to content
Open
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
26 changes: 26 additions & 0 deletions include/Graphs/PAGEdge.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ class StorePE: public PAGEdge
StorePE(); ///< place holder
StorePE(const StorePE &); ///< place holder
void operator=(const StorePE &); ///< place holder

int storeSize = -1; ///< -1 is an unknown store size

public:
/// Methods for support type inquiry through isa, cast, and dyn_cast:
Expand All @@ -322,6 +324,17 @@ class StorePE: public PAGEdge
}
//@}

/// Getter & setter for store size. A (-1) size is an unknown store size
//@{
void setStoreSize(const int size){
storeSize = size;
}

int getStoreSize() const {
return storeSize;
}
//@}

/// constructor
StorePE(PAGNode* s, PAGNode* d, const IntraBlockNode* st) :
PAGEdge(s, d, makeEdgeFlagWithStoreInst(PAGEdge::Store, st))
Expand All @@ -340,6 +353,8 @@ class LoadPE: public PAGEdge
LoadPE(const LoadPE &); ///< place holder
void operator=(const LoadPE &); ///< place holder

int loadSize = -1;

public:
/// Methods for support type inquiry through isa, cast, and dyn_cast:
//@{
Expand All @@ -356,7 +371,18 @@ class LoadPE: public PAGEdge
return edge->getEdgeKind() == PAGEdge::Load;
}
//@}

/// Getter & setter for load size. A (-1) size is an unknown load size
//@{
void setLoadSize(const int size) {
loadSize = size;
}

int getLoadSize() const {
return loadSize;
}
//@}

/// constructor
LoadPE(PAGNode* s, PAGNode* d) : PAGEdge(s,d,PAGEdge::Load)
{
Expand Down
6 changes: 4 additions & 2 deletions include/SVF-FE/PAGBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,21 +291,23 @@ class PAGBuilder: public llvm::InstVisitor<PAGBuilder>
return edge;
}
/// Add Load edge
inline LoadPE* addLoadEdge(NodeID src, NodeID dst)
inline LoadPE* addLoadEdge(NodeID src, NodeID dst, int size = -1)
{
LoadPE *edge = pag->addLoadPE(src, dst);
edge->setLoadSize(size);
setCurrentBBAndValueForPAGEdge(edge);
return edge;
}
/// Add Store edge
inline StorePE* addStoreEdge(NodeID src, NodeID dst)
inline StorePE* addStoreEdge(NodeID src, NodeID dst, int size = -1)
{
IntraBlockNode* node;
if(const Instruction* inst = SVFUtil::dyn_cast<Instruction>(curVal))
node = pag->getICFG()->getIntraBlockNode(inst);
else
node = NULL;
StorePE *edge = pag->addStorePE(src, dst, node);
edge->setStoreSize(size);
setCurrentBBAndValueForPAGEdge(edge);
return edge;
}
Expand Down
69 changes: 48 additions & 21 deletions lib/SVF-FE/PAGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,19 +364,22 @@ void PAGBuilder::InitialGlobal(const GlobalVariable *gvar, Constant *C,
if (SVFUtil::isa<GlobalVariable>(C) || SVFUtil::isa<Function>(C))
{
setCurrentLocation(C, NULL);
addStoreEdge(src, field);
//int storeSize = SymbolTableInfo::Symbolnfo()->getTypeSizeInBytes(C->getType());
addStoreEdge(src, field /*, storeSize */ );
}
else if (SVFUtil::isa<ConstantExpr>(C))
{
// add gep edge of C1 itself is a constant expression
processCE(C);
setCurrentLocation(C, NULL);
addStoreEdge(src, field);
//int storeSize = SymbolTableInfo::Symbolnfo()->getTypeSizeInBytes(C->getType());
addStoreEdge(src, field /*, storeSize */ );
}
else
{
setCurrentLocation(C, NULL);
addStoreEdge(src, field);
//int storeSize = SymbolTableInfo::Symbolnfo()->getTypeSizeInBytes(C->getType());
addStoreEdge(src, field /*, storeSize */ );
/// src should not point to anything yet
if (C->getType()->isPtrOrPtrVectorTy() && src != pag->getNullPtr())
addCopyEdge(pag->getNullPtr(), src);
Expand Down Expand Up @@ -512,7 +515,9 @@ void PAGBuilder::visitLoadInst(LoadInst &inst)

NodeID src = getValueNode(inst.getPointerOperand());

addLoadEdge(src, dst);
int loadSize = SymbolTableInfo::Symbolnfo()->getTypeSizeInBytes(inst.getPointerOperand()->getType());

addLoadEdge(src, dst, loadSize);
}

/*!
Expand All @@ -529,7 +534,8 @@ void PAGBuilder::visitStoreInst(StoreInst &inst)

NodeID src = getValueNode(inst.getValueOperand());

addStoreEdge(src, dst);
int storeSize = SymbolTableInfo::Symbolnfo()->getTypeSizeInBytes(inst.getValueOperand()->getType());
addStoreEdge(src, dst, storeSize);

}

Expand Down Expand Up @@ -832,7 +838,11 @@ void PAGBuilder::addComplexConsForExt(Value *D, Value *S, u32_t sz)
std::vector<LocationSet> srcFields;
std::vector<LocationSet> dstFields;
const Type *stype = getBaseTypeAndFlattenedFields(S, srcFields);
const std::vector<FieldInfo> &sfieldinfo = SymbolTableInfo::Symbolnfo()->getFlattenFieldInfoVec(stype);

const Type *dtype = getBaseTypeAndFlattenedFields(D, dstFields);
const std::vector<FieldInfo> &dfieldinfo = SymbolTableInfo::Symbolnfo()->getFlattenFieldInfoVec(dtype);

if(srcFields.size() > dstFields.size())
fields = dstFields;
else
Expand All @@ -844,14 +854,31 @@ void PAGBuilder::addComplexConsForExt(Value *D, Value *S, u32_t sz)

assert(fields.size() >= sz && "the number of flattened fields is smaller than size");

/// Use stride pair vector to calculate the size of the element.
/// If it is an array, it will multiply element type size by number of
// elements, otherwise it will just multiply by one
auto calcFldSize = [](const FieldInfo::ElemNumStridePairVec &strideVec, u32_t size){
for(auto pair: strideVec)
size*= pair.first;
return size;
};

//For each field (i), add (Ti = *S + i) and (*D + i = Ti).
for (u32_t index = 0; index < sz; index++)
{
NodeID dField = getGepValNode(D,fields[index],dtype,index);
const Type *dtype = dfieldinfo[index].getFlattenElemTy();
int storeSize = calcFldSize(dfieldinfo[index].getElemNumStridePairVect(),
SymbolTableInfo::Symbolnfo()->getTypeSizeInBytes(dtype));

NodeID sField = getGepValNode(S,fields[index],stype,index);
const Type *stype = sfieldinfo[index].getFlattenElemTy();
int loadSize = calcFldSize(sfieldinfo[index].getElemNumStridePairVect(),
SymbolTableInfo::Symbolnfo()->getTypeSizeInBytes(stype));

NodeID dummy = pag->addDummyValNode();
addLoadEdge(sField,dummy);
addStoreEdge(dummy,dField);
addLoadEdge(sField,dummy, loadSize);
addStoreEdge(dummy,dField, storeSize);
}
}

Expand Down Expand Up @@ -885,7 +912,7 @@ void PAGBuilder::handleExtCall(CallSite cs, const SVFFunction *callee)
if (vnArg && dummy && obj)
{
addAddrEdge(obj, dummy);
addStoreEdge(dummy, vnArg);
addStoreEdge(dummy, vnArg /*, storeSize */ );
}
}
else
Expand Down Expand Up @@ -973,23 +1000,23 @@ void PAGBuilder::handleExtCall(CallSite cs, const SVFFunction *callee)
NodeID vnD= getValueNode(cs.getArgument(1));
NodeID vnS= getValueNode(cs.getArgument(0));
if(vnD && vnS)
addStoreEdge(vnS,vnD);
addStoreEdge(vnS,vnD /*, storeSize */ );
break;
}
case ExtAPI::EFT_A2R_A1:
{
NodeID vnD= getValueNode(cs.getArgument(2));
NodeID vnS= getValueNode(cs.getArgument(1));
if(vnD && vnS)
addStoreEdge(vnS,vnD);
addStoreEdge(vnS,vnD /*, storeSize */ );
break;
}
case ExtAPI::EFT_A4R_A1:
{
NodeID vnD= getValueNode(cs.getArgument(4));
NodeID vnS= getValueNode(cs.getArgument(1));
if(vnD && vnS)
addStoreEdge(vnS,vnD);
addStoreEdge(vnS,vnD /*, storeSize */ );
break;
}
case ExtAPI::EFT_L_A0__A1_A0:
Expand All @@ -999,9 +1026,9 @@ void PAGBuilder::handleExtCall(CallSite cs, const SVFFunction *callee)
/// dst = load base
/// store src base
if (const LoadInst *load = SVFUtil::dyn_cast<LoadInst>(cs.getArgument(0))) {
addStoreEdge(getValueNode(cs.getArgument(1)), getValueNode(load->getPointerOperand()));
addStoreEdge(getValueNode(cs.getArgument(1)), getValueNode(load->getPointerOperand()) /*, storeSize */);
if (SVFUtil::isa<PointerType>(inst->getType()))
addLoadEdge(getValueNode(load->getPointerOperand()), getValueNode(inst));
addLoadEdge(getValueNode(load->getPointerOperand()), getValueNode(inst) /*, loadSize */);
}
// else if (const GetElementPtrInst *gep = SVFUtil::dyn_cast<GetElementPtrInst>(cs.getArgument(0))) {
// addStoreEdge(getValueNode(cs.getArgument(1)), getValueNode(cs.getArgument(0)));
Expand Down Expand Up @@ -1030,7 +1057,7 @@ void PAGBuilder::handleExtCall(CallSite cs, const SVFFunction *callee)
NodeID vnD= getValueNode(cs.getArgument(2));
NodeID vnS= getValueNode(cs.getArgument(0));
if(vnD && vnS)
addStoreEdge(vnS,vnD);
addStoreEdge(vnS,vnD /*, storeSize */ );
break;
}
case ExtAPI::EFT_A0R_NEW:
Expand Down Expand Up @@ -1079,7 +1106,7 @@ void PAGBuilder::handleExtCall(CallSite cs, const SVFFunction *callee)
NodeID vnD = getGepValNode(vArg3, fields[i], type, i);
NodeID vnS = getValueNode(vArg1);
if(vnD && vnS)
addStoreEdge(vnS,vnD);
addStoreEdge(vnS,vnD /*, storeSize */ );
}
break;
}
Expand All @@ -1102,7 +1129,7 @@ void PAGBuilder::handleExtCall(CallSite cs, const SVFFunction *callee)
{
NodeID vnS = getGepValNode(vArg, fields[i], type, i);
if(vnD && vnS)
addStoreEdge(vnS,vnD);
addStoreEdge(vnS,vnD /*, storeSize */ );
}
break;
}
Expand All @@ -1112,7 +1139,7 @@ void PAGBuilder::handleExtCall(CallSite cs, const SVFFunction *callee)
Value *vDst = cs.getArgument(1);
NodeID src = pag->getValueNode(vSrc);
NodeID dst = pag->getValueNode(vDst);
addStoreEdge(src, dst);
addStoreEdge(src, dst /*, storeSize */ );
break;
}
case ExtAPI::CPP_EFT_A0R_A1:
Expand All @@ -1122,7 +1149,7 @@ void PAGBuilder::handleExtCall(CallSite cs, const SVFFunction *callee)
{
NodeID vnD = pag->getValueNode(cs.getArgument(0));
NodeID vnS = pag->getValueNode(cs.getArgument(1));
addStoreEdge(vnS, vnD);
addStoreEdge(vnS, vnD /*, storeSize */ );
}
break;
}
Expand All @@ -1135,8 +1162,8 @@ void PAGBuilder::handleExtCall(CallSite cs, const SVFFunction *callee)
NodeID vnS = getValueNode(cs.getArgument(1));
assert(vnD && vnS && "dst or src not exist?");
NodeID dummy = pag->addDummyValNode();
addLoadEdge(vnS,dummy);
addStoreEdge(dummy,vnD);
addLoadEdge(vnS,dummy /*, loadSize */ );
addStoreEdge(dummy,vnD /*, storeSize */ );
}
break;
}
Expand All @@ -1148,7 +1175,7 @@ void PAGBuilder::handleExtCall(CallSite cs, const SVFFunction *callee)
NodeID vnS = getValueNode(cs.getArgument(1));
assert(vnS && "src not exist?");
NodeID dummy = pag->addDummyValNode();
addLoadEdge(vnS,dummy);
addLoadEdge(vnS,dummy /*, loadSize */ );
}
break;
}
Expand Down