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

first commit of ConstantVal/Obj #1602

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
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
3 changes: 2 additions & 1 deletion svf-llvm/include/SVF-LLVM/SVFIRBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@ class SVFIRBuilder: public llvm::InstVisitor<SVFIRBuilder>
{
LLVMContext& cxt = llvmModuleSet()->getContext();
ConstantPointerNull* constNull = ConstantPointerNull::get(PointerType::getUnqual(cxt));
NodeID nullPtr = pag->addValNode(llvmModuleSet()->getSVFValue(constNull),pag->getNullPtr(), nullptr);
NodeID nullPtr = pag->addConstantNullPtrValNode(llvmModuleSet()->getSVFValue(constNull),pag->getNullPtr(), nullptr);
llvmModuleSet()->setValueAttr(constNull, pag->getGNode(nullPtr));
setCurrentLocation(constNull, nullptr);
addBlackHoleAddrEdge(pag->getBlkPtr());
return nullPtr;
Expand Down
77 changes: 67 additions & 10 deletions svf-llvm/lib/SVFIRBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ SVFIR* SVFIRBuilder::build()
{
if(llvmModuleSet()->hasICFGNode(inst))
it.second->gNode = llvmModuleSet()->getICFGNode(inst);
}
else if (const Function* func = SVFUtil::dyn_cast<Function>(llvmModuleSet()->getLLVMValue(
it.second->getValue())))
} else if (const Function* func = SVFUtil::dyn_cast<Function>(llvmModuleSet()->getLLVMValue(
it.second->getValue())))
{
it.second->gNode = llvmModuleSet()->getCallGraphNode(func);
}
Expand Down Expand Up @@ -219,12 +218,16 @@ void SVFIRBuilder::initialiseNodes()
++iter)
{
DBOUT(DPAGBuild, outs() << "add val node " << iter->second << "\n");
if(iter->second == symTable->blkPtrSymID() || iter->second == symTable->nullPtrSymID())
if(iter->second == symTable->blkPtrSymID())
continue;
if (iter->second == symTable->nullPtrSymID()) {
pag->addConstantNullPtrValNode(iter->first, iter->second, nullptr);
}

const ICFGNode* icfgNode = nullptr;
auto llvmValue = llvmModuleSet()->getLLVMValue(iter->first);
if (const Instruction* inst =
SVFUtil::dyn_cast<Instruction>(llvmModuleSet()->getLLVMValue(iter->first)))
SVFUtil::dyn_cast<Instruction>(llvmValue))
{
if (llvmModuleSet()->hasICFGNode(inst))
{
Expand All @@ -233,11 +236,36 @@ void SVFIRBuilder::initialiseNodes()
}

if (const Function* func =
SVFUtil::dyn_cast<Function>(llvmModuleSet()->getLLVMValue(iter->first)))
SVFUtil::dyn_cast<Function>(llvmValue))
{
const CallGraphNode* cgn = llvmModuleSet()->getCallGraphNode(func);
pag->addFunValNode(cgn, iter->second, icfgNode);
}
else if (auto fpValue = SVFUtil::dyn_cast<ConstantFP>(llvmValue))
{
pag->addConstantFPValNode(iter->first, fpValue->getValueAPF().convertToDouble(), iter->second, icfgNode);
llvmModuleSet()->setValueAttr(fpValue, pag->getGNode(iter->second));
}
else if (auto intValue = SVFUtil::dyn_cast<ConstantInt>(llvmValue))
{
pag->addConstantIntValNode(iter->first, intValue->getSExtValue(), intValue->getZExtValue(), iter->second, icfgNode);
llvmModuleSet()->setValueAttr(intValue, pag->getGNode(iter->second));
}
else if (auto nullValue = SVFUtil::dyn_cast<ConstantPointerNull>(llvmValue))
{
pag->addConstantNullPtrValNode(iter->first, iter->second, icfgNode);
llvmModuleSet()->setValueAttr(nullValue, pag->getGNode(iter->second));
}
else if (auto globalValue = SVFUtil::dyn_cast<GlobalVariable>(llvmValue))
{
pag->addGlobalValueValNode(iter->first, iter->second, icfgNode);
llvmModuleSet()->setValueAttr(globalValue, pag->getGNode(iter->second));
}
else if (auto dataValue = SVFUtil::dyn_cast<ConstantData>(llvmValue))
{
pag->addGlobalValueValNode(iter->first, iter->second, icfgNode);
llvmModuleSet()->setValueAttr(dataValue, pag->getGNode(iter->second));
}
else
{
pag->addValNode(iter->first, iter->second, icfgNode);
Expand All @@ -251,14 +279,43 @@ void SVFIRBuilder::initialiseNodes()
DBOUT(DPAGBuild, outs() << "add obj node " << iter->second << "\n");
if(iter->second == symTable->blackholeSymID() || iter->second == symTable->constantSymID())
continue;
auto llvmValue = llvmModuleSet()->getLLVMValue(iter->first);

if (const Function* func = SVFUtil::dyn_cast<Function>(
llvmModuleSet()->getLLVMValue(iter->first)))
llvmValue))
{
pag->addFunObjNode(llvmModuleSet()->getCallGraphNode(func), iter->second);
}
else
{
pag->addObjNode(iter->first, iter->second);
else {
if (auto fpValue = SVFUtil::dyn_cast<ConstantFP>(llvmValue))
{
pag->addConstantFPObjNode(iter->first, fpValue->getValueAPF().convertToDouble(), iter->second);
llvmModuleSet()->setValueAttr(fpValue, pag->getGNode(iter->second));
}
else if (auto intValue = SVFUtil::dyn_cast<ConstantInt>(llvmValue))
{
pag->addConstantIntObjNode(iter->first, intValue->getSExtValue(), intValue->getZExtValue(), iter->second);
llvmModuleSet()->setValueAttr(intValue, pag->getGNode(iter->second));
}
else if (auto nullValue = SVFUtil::dyn_cast<ConstantPointerNull>(llvmValue))
{
pag->addConstantNullPtrObjNode(iter->first, iter->second);
llvmModuleSet()->setValueAttr(nullValue, pag->getGNode(iter->second));
}
else if (auto globalValue = SVFUtil::dyn_cast<GlobalVariable>(llvmValue))
{
pag->addGlobalValueObjNode(iter->first, iter->second);
llvmModuleSet()->setValueAttr(globalValue, pag->getGNode(iter->second));
}
else if (auto dataValue = SVFUtil::dyn_cast<ConstantData>(llvmValue))
{
pag->addGlobalValueObjNode(iter->first, iter->second);
llvmModuleSet()->setValueAttr(dataValue, pag->getGNode(iter->second));
}
else
{
pag->addObjNode(iter->first, iter->second);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion svf-llvm/lib/SVFIRExtAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const Type* SVFIRBuilder::getBaseTypeAndFlattenedFields(const Value* V, std::vec
{
SymbolTableBuilder builder(pag->getSymbolInfo());
builder.collectSym(offset);
pag->addValNode(svfOffset, pag->getSymbolInfo()->getValSym(svfOffset), nullptr);
pag->addConstantIntValNode(svfOffset, offset->getSExtValue(), offset->getZExtValue(), pag->getSymbolInfo()->getValSym(svfOffset), nullptr);
}
ls.addOffsetVarAndGepTypePair(getPAG()->getGNode(getPAG()->getValueNode(svfOffset)), nullptr);
fields.push_back(ls);
Expand Down
61 changes: 53 additions & 8 deletions svf/include/Graphs/GenericGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,21 +169,48 @@ class SVFBaseNode
RetNode,
// │ │ ├── Represents a variadic argument node
VarargNode,
// │ │ └── Dummy node for uninitialized values
// │ │ ├── Represents a global value node
GlobalValNode,
// │ │ ├── Represents a constant data value node
ConstantDataValNode,
// │ │ ├── Represents a black hole node
BlackHoleNode,
// │ │ ├── Represents a constant float-point value node
ConstantFPValNode,
// │ │ ├── Represents a constant integer value node
ConstantIntValNode,
// │ │ ├── Represents a constant nullptr value node
ConstantNullptrValNode,
// │ └── Dummy node for uninitialized values
DummyValNode,
// │ └── ObjVarKinds: Types of object variable nodes
// └────────



// │ ├── Represents an object variable
ObjNode,
// │ ├── GepObjNode: Represents a GEP object variable
GepObjNode,
// │ └── FIObjNode: Represents a flow-insensitive object node
FIObjNode,
// │ ├──FunObjNode: Types of function object
// │ ├── FunObjNode: Types of function object
FunObjNode,
// │ ├── GlobalValueObjNode: Types of global value object
GlobalObjNode,
// │ ├── ConstantDataObjNode: Types of constant data object
ConstantDataObjNode,
// │ ├── ConstantFPObjNode: Types of constant float-point object
ConstantFPObjNode,
// │ ├── ConstantIntObjNode: Types of constant integer object
ConstantIntObjNode,
// │ ├── ConstantNullptrObjNode: Types of constant nullptr object
ConstantNullptrObjNode,
// │ └── DummyObjNode: Dummy node for uninitialized objects
DummyObjNode,
// └────────



// ┌── VFGNodeKinds: Various Value Flow Graph (VFG) node kinds with operations
// │ ├── Represents a comparison operation
Cmp,
Expand Down Expand Up @@ -317,7 +344,7 @@ class SVFBaseNode

static inline bool isSVFVarKind(GNodeK n)
{
static_assert(DummyObjNode - ValNode == 10,
static_assert(DummyObjNode - ValNode == 21,
"The number of SVFVarKinds has changed, make sure the "
"range is correct");

Expand All @@ -326,26 +353,44 @@ class SVFBaseNode

static inline bool isValVarKinds(GNodeK n)
{
static_assert(DummyValNode - ValNode == 5,
static_assert(DummyValNode - ValNode == 11,
"The number of ValVarKinds has changed, make sure the "
"range is correct");
return n <= DummyValNode && n >= ValNode;
}


static inline bool isConstantDataValVar(GNodeK n)
{
static_assert(ConstantNullptrValNode - ConstantDataValNode == 4,
"The number of ConstantDataValVarKinds has changed, make "
"sure the range is correct");
return n <= ConstantIntValNode && n >= ConstantDataValNode;
}

static inline bool isObjVarKinds(GNodeK n)
{
static_assert(DummyObjNode - ObjNode == 4,
static_assert(DummyObjNode - ObjNode == 9,
"The number of ObjVarKinds has changed, make sure the "
"range is correct");
return n <= DummyObjNode && n >= ObjNode;
}

static inline bool isFIObjVarKinds(GNodeK n)
{
static_assert(FunObjNode - FIObjNode == 1,
static_assert(ConstantNullptrObjNode - FIObjNode == 6,
"The number of FIObjVarKinds has changed, make sure the "
"range is correct");
return n <= FunObjNode && n >= FIObjNode;
return n <= ConstantNullptrObjNode && n >= FIObjNode;
}


static inline bool isConstantDataObjVarKinds(GNodeK n)
{
static_assert(ConstantNullptrObjNode - ConstantDataObjNode == 3,
"The number of ConstantDataObjVarKinds has changed, make "
"sure the range is correct");
return n <= ConstantNullptrObjNode && n >= ConstantDataObjNode;
}

static inline bool isVFGNodeKinds(GNodeK n)
Expand Down
73 changes: 72 additions & 1 deletion svf/include/SVFIR/SVFIR.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ class SVFIR : public IRGraph
assert(icfg->totalICFGNode>0 && "empty ICFG! Build SVF IR first!");
return icfg;
}


/// Set/Get CHG
inline void setCHG(CommonCHGraph* c)
{
Expand Down Expand Up @@ -547,7 +549,7 @@ class SVFIR : public IRGraph
/// Add a value (pointer) node
inline NodeID addValNode(const SVFValue* val, NodeID i, const ICFGNode* icfgNode)
{
SVFVar *node = new ValVar(val,i, ValVar::ValNode, icfgNode);
SVFVar* node = new ValVar(val, i, ValVar::ValNode, icfgNode);
return addValNode(val, node, i);
}

Expand Down Expand Up @@ -579,6 +581,75 @@ class SVFIR : public IRGraph
return addNode(node,i);
}

inline NodeID addConstantFPValNode(const SVFValue* curInst, double dval, const NodeID i,
const ICFGNode* icfgNode)
{
SVFVar* node = new ConstantFPValVar(curInst, dval, i, icfgNode);
return addNode(node, i);
}

inline NodeID addConstantIntValNode(const SVFValue* curInst, s64_t sval, u64_t zval, const NodeID i,
const ICFGNode* icfgNode)
{
SVFVar* node = new ConstantIntValVar(curInst, sval, zval, i, icfgNode);
return addNode(node, i);
}

inline NodeID addConstantNullPtrValNode(const SVFValue* curInst, const NodeID i, const ICFGNode* icfgNode)
{
SVFVar* node = new ConstantNullPtrValVar(curInst, i, icfgNode);
return addNode(node, i);
}

inline NodeID addGlobalValueValNode(const SVFValue* curInst, const NodeID i, const ICFGNode* icfgNode)
{
SVFVar* node = new GlobalValVar(curInst, i, icfgNode);
return addNode(node, i);
}

inline NodeID addConstantDataValNode(const SVFValue* curInst, const NodeID i, const ICFGNode* icfgNode)
{
SVFVar* node = new ConstantDataValVar(curInst, i, icfgNode);
return addNode(node, i);
}

inline NodeID addConstantFPObjNode(const SVFValue* curInst, double dval, const NodeID i)
{
const MemObj* mem = getMemObj(curInst);
ConstantFPObjVar* node = new ConstantFPObjVar(curInst, dval, mem->getId(), mem);
return addObjNode(curInst, node, mem->getId());
}


inline NodeID addConstantIntObjNode(const SVFValue* curInst, s64_t sval, u64_t zval, const NodeID i) {
const MemObj* mem = getMemObj(curInst);
ConstantIntObjVar* node =
new ConstantIntObjVar(curInst, sval, zval, mem->getId(), mem);
return addObjNode(curInst, node, mem->getId());
}


inline NodeID addConstantNullPtrObjNode(const SVFValue* curInst, const NodeID i) {
const MemObj* mem = getMemObj(curInst);
ConstantNullPtrObjVar* node = new ConstantNullPtrObjVar(curInst, mem->getId(), mem);
return addObjNode(mem->getValue(), node, mem->getId());
}

inline NodeID addGlobalValueObjNode(const SVFValue* curInst, const NodeID i)
{
const MemObj* mem = getMemObj(curInst);
GlobalObjVar* node = new GlobalObjVar(curInst, mem->getId(), mem);
return addObjNode(mem->getValue(), node, mem->getId());
}

inline NodeID addConstantDataObjNode(const SVFValue* curInst, const NodeID i)
{
const MemObj* mem = getMemObj(curInst);
ConstantDataObjVar* node = new ConstantDataObjVar(curInst, mem->getId(), mem);
return addObjNode(mem->getValue(), node, mem->getId());
}


/// 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
Expand Down
Loading