Skip to content

Commit

Permalink
fix AE + Const AccessPath
Browse files Browse the repository at this point in the history
  • Loading branch information
bjjwwang committed Dec 11, 2024
1 parent 251156d commit a3365f2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
11 changes: 9 additions & 2 deletions svf/include/SVFIR/SVFVariables.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ class GepValVar: public ValVar

private:
AccessPath ap; // AccessPath
NodeID base; // base node id
const SVFType* gepValType;

/// Constructor to create empty GeValVar (for SVFIRReader/deserialization)
Expand Down Expand Up @@ -347,9 +348,9 @@ class GepValVar: public ValVar
//@}

/// Constructor
GepValVar(const SVFValue* val, NodeID i, const AccessPath& ap,
GepValVar(NodeID baseID, const SVFValue* val, NodeID i, const AccessPath& ap,
const SVFType* ty)
: ValVar(val, i, GepValNode), ap(ap), gepValType(ty)
: ValVar(val, i, GepValNode), ap(ap), base(baseID), gepValType(ty)
{
}

Expand All @@ -359,6 +360,12 @@ class GepValVar: public ValVar
return ap.getConstantStructFldIdx();
}

/// Return the base object from which this GEP node came from.
inline NodeID getBaseNode(void) const
{
return base;
}

/// Return name of a LLVM value
inline const std::string getValueName() const
{
Expand Down
11 changes: 5 additions & 6 deletions svf/lib/AE/Core/AbstractState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,19 +233,19 @@ IntervalValue AbstractState::getElementIndex(const GepStmt* gep)
for (int i = gep->getOffsetVarAndGepTypePairVec().size() - 1; i >= 0; i--)
{
AccessPath::IdxOperandPair IdxVarAndType = gep->getOffsetVarAndGepTypePairVec()[i];
const SVFValue* value = gep->getOffsetVarAndGepTypePairVec()[i].first->getValue();
const SVFVar* var = gep->getOffsetVarAndGepTypePairVec()[i].first;
const SVFType* type = IdxVarAndType.second;

// Variables to store the lower and upper bounds of the index value
s64_t idxLb;
s64_t idxUb;

// Determine the lower and upper bounds based on whether the value is a constant
if (const SVFConstantInt* constInt = SVFUtil::dyn_cast<SVFConstantInt>(value))
if (const ConstantIntValVar* constInt = SVFUtil::dyn_cast<ConstantIntValVar>(var))
idxLb = idxUb = constInt->getSExtValue();
else
{
IntervalValue idxItv = (*this)[PAG::getPAG()->getValueNode(value)].getInterval();
IntervalValue idxItv = (*this)[var->getId()].getInterval();
if (idxItv.isBottom())
idxLb = idxUb = 0;
else
Expand Down Expand Up @@ -320,7 +320,7 @@ IntervalValue AbstractState::getByteOffset(const GepStmt* gep)
else
assert(false && "idxOperandType must be ArrType or PtrType");

if (const SVFConstantInt* op = SVFUtil::dyn_cast<SVFConstantInt>(idxOperandVar->getValue()))
if (const ConstantIntValVar* op = SVFUtil::dyn_cast<ConstantIntValVar>(idxOperandVar))
{
// Calculate the lower bound (lb) of the interval value
s64_t lb = (double)Options::MaxFieldLimit() / elemByteSize >= op->getSExtValue()
Expand All @@ -330,8 +330,7 @@ IntervalValue AbstractState::getByteOffset(const GepStmt* gep)
}
else
{
u32_t idx = PAG::getPAG()->getValueNode(idxOperandVar->getValue());
IntervalValue idxVal = (*this)[idx].getInterval();
IntervalValue idxVal = (*this)[idxOperandVar->getId()].getInterval();

if (idxVal.isBottom())
res = res + IntervalValue(0, 0);
Expand Down
9 changes: 4 additions & 5 deletions svf/lib/MemoryModel/AccessPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ bool AccessPath::isConstantOffset() const
{
for(auto it : idxOperandPairs)
{
if(SVFUtil::isa<SVFConstantInt>(it.first->getValue()) == false)
if(SVFUtil::isa<ConstantIntValVar>(it.first) == false)
return false;
}
return true;
Expand Down Expand Up @@ -97,9 +97,8 @@ u32_t AccessPath::getElementNum(const SVFType* type) const
// then the return byte offset is 16 Bytes.
u32_t AccessPath::getStructFieldOffset(const SVFVar* idxOperandVar, const SVFStructType* idxOperandType) const
{
const SVFValue* idxValue = idxOperandVar->getValue();
u32_t structByteOffset = 0;
if (const SVFConstantInt *op = SVFUtil::dyn_cast<SVFConstantInt>(idxValue))
if (const ConstantIntValVar *op = SVFUtil::dyn_cast<ConstantIntValVar>(idxOperandVar))
{
for (u32_t structField = 0; structField < (u32_t) op->getSExtValue(); ++structField)
{
Expand Down Expand Up @@ -132,7 +131,7 @@ APOffset AccessPath::computeConstantByteOffset() const
/// For example, there is struct DEST{int a, char b[10], int c[5]}
/// (1) %c = getelementptr inbounds %struct.DEST, %struct.DEST* %arr, i32 0, i32 2
// (2) %arrayidx = getelementptr inbounds [10 x i8], [10 x i8]* %b, i64 0, i64 8
const SVFValue* value = idxOperandPairs[i].first->getValue();
const SVFVar* var = idxOperandPairs[i].first;
/// for (1) offsetVarAndGepTypePairs.size() = 2
/// i = 0, type: %struct.DEST*, PtrType, op = 0
/// i = 1, type: %struct.DEST, StructType, op = 2
Expand All @@ -157,7 +156,7 @@ APOffset AccessPath::computeConstantByteOffset() const
type2 = gepSrcPointeeType();
}

const SVFConstantInt* op = SVFUtil::dyn_cast<SVFConstantInt>(value);
const ConstantIntValVar* op = SVFUtil::dyn_cast<ConstantIntValVar>(var);
if (const SVFStructType* structType = SVFUtil::dyn_cast<SVFStructType>(type))
{
/// for (1) structType: %struct.DEST
Expand Down
2 changes: 1 addition & 1 deletion svf/lib/SVFIR/SVFIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ NodeID SVFIR::addGepValNode(const SVFValue* curInst,const SVFValue* gepVal, cons
assert(0==GepValObjMap[curInst].count(std::make_pair(base, ap))
&& "this node should not be created before");
GepValObjMap[curInst][std::make_pair(base, ap)] = i;
GepValVar *node = new GepValVar(gepVal, i, ap, type);
GepValVar *node = new GepValVar(base, gepVal, i, ap, type);
return addValNode(gepVal, node, i);
}

Expand Down

0 comments on commit a3365f2

Please sign in to comment.