Skip to content

Commit

Permalink
SVF code formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
yuleisui committed Sep 6, 2023
1 parent 324794b commit dab4f64
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 36 deletions.
10 changes: 7 additions & 3 deletions svf-llvm/include/SVF-LLVM/LLVMUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -377,14 +377,18 @@ std::vector<const Function *> getCalledFunctions(const Function *F);
std::vector<std::string> getFunAnnotations(const Function* fun);
void removeFunAnnotations(std::vector<Function*>& removedFuncList);

inline u32_t SVFType2ByteSize(const SVFType* type) {
inline u32_t SVFType2ByteSize(const SVFType* type)
{
const llvm::Type* llvm_rhs = LLVMModuleSet::getLLVMModuleSet()->getLLVMType(type);
u32_t llvm_rhs_size = LLVMUtil::getTypeSizeInBytes(llvm_rhs->getPointerElementType());
u32_t llvm_elem_size = -1;
if (llvm_rhs->getPointerElementType()->isArrayTy() && llvm_rhs_size > 0) {
if (llvm_rhs->getPointerElementType()->isArrayTy() && llvm_rhs_size > 0)
{
size_t array_len = llvm_rhs->getPointerElementType()->getArrayNumElements();
llvm_elem_size = llvm_rhs_size / array_len;
} else {
}
else
{
llvm_elem_size =llvm_rhs_size;
}
return llvm_elem_size;
Expand Down
86 changes: 53 additions & 33 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, s32
return ret;
}

std::pair<s32_t, s32_t> SVFIR2ItvExeState::getBytefromGepTypePair(const AccessPath::VarAndGepTypePair& gep_pair, const GepStmt *gep, s32_t elemBytesize) {
std::pair<s32_t, s32_t> SVFIR2ItvExeState::getBytefromGepTypePair(const AccessPath::VarAndGepTypePair& gep_pair, const GepStmt *gep, s32_t elemBytesize)
{
const SVFValue *value = gep_pair.first->getValue();
const SVFType *type = gep_pair.second;
const SVFConstantInt *op = SVFUtil::dyn_cast<SVFConstantInt>(value);
Expand All @@ -185,8 +186,10 @@ std::pair<s32_t, s32_t> SVFIR2ItvExeState::getBytefromGepTypePair(const AccessPa
if (op)
{
offsetLb = offsetUb = op->getSExtValue() >
maxFieldLimit? maxFieldLimit: op->getSExtValue();
} else {
maxFieldLimit? maxFieldLimit: op->getSExtValue();
}
else
{
u32_t idx = _svfir->getValueNode(value);
IntervalValue &idxVal = _es[idx];
if (idxVal.isBottom() || idxVal.isTop())
Expand All @@ -195,19 +198,24 @@ std::pair<s32_t, s32_t> SVFIR2ItvExeState::getBytefromGepTypePair(const AccessPa
if (idxVal.is_numeral())
{
offsetLb = offsetUb = idxVal.lb().getNumeral()>
maxFieldLimit? maxFieldLimit: idxVal.lb().getNumeral();
} else {
maxFieldLimit? maxFieldLimit: idxVal.lb().getNumeral();
}
else
{
offsetLb = idxVal.lb().getNumeral()> maxFieldLimit? maxFieldLimit:idxVal.lb().getNumeral() * elemBytesize ;
offsetUb = idxVal.ub().getNumeral() > maxFieldLimit? maxFieldLimit:idxVal.ub().getNumeral() * elemBytesize;
}
}

if (type) {
if (const SVFPointerType *pty = SVFUtil::dyn_cast<SVFPointerType>(type)) {
if (type)
{
if (const SVFPointerType *pty = SVFUtil::dyn_cast<SVFPointerType>(type))
{
offsetLb = offsetLb * gep->getAccessPath().getElementNum(pty->getPtrElementType())* elemBytesize;
offsetUb = offsetUb * gep->getAccessPath().getElementNum(pty->getPtrElementType())* elemBytesize;
}
else {
else
{
offsetLb = offsetLb * elemBytesize;
offsetUb = offsetUb * elemBytesize;
}
Expand All @@ -216,19 +224,22 @@ std::pair<s32_t, s32_t> SVFIR2ItvExeState::getBytefromGepTypePair(const AccessPa
}


std::pair<s32_t, s32_t> SVFIR2ItvExeState::getIndexfromGepTypePair(const AccessPath::VarAndGepTypePair& gep_pair, const GepStmt *gep) {
std::pair<s32_t, s32_t> 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);
s32_t offsetLb = 0;
s32_t offsetUb = 0;
s32_t maxFieldLimit = (s32_t)Options::MaxFieldLimit();
/// offset is constant but stored in variable
/// offset is constant but stored in variable
if (op)
{
offsetLb = offsetUb = op->getSExtValue() >
maxFieldLimit? maxFieldLimit: op->getSExtValue();
} else {
maxFieldLimit? maxFieldLimit: op->getSExtValue();
}
else
{
u32_t idx = _svfir->getValueNode(value);
//if (!inVarToIValTable(idx)) return std::make_pair(-1, -1);
IntervalValue &idxVal = _es[idx];
Expand All @@ -238,38 +249,45 @@ std::pair<s32_t, s32_t> SVFIR2ItvExeState::getIndexfromGepTypePair(const AccessP
if (idxVal.is_numeral())
{
offsetLb = offsetUb = idxVal.lb().getNumeral()>
maxFieldLimit? maxFieldLimit: idxVal.lb().getNumeral();
} else {
maxFieldLimit? maxFieldLimit: idxVal.lb().getNumeral();
}
else
{
offsetLb = idxVal.lb().getNumeral() < 0
? 0
: idxVal.lb().getNumeral();
? 0
: idxVal.lb().getNumeral();
offsetLb = idxVal.lb().getNumeral() > maxFieldLimit
? maxFieldLimit
: offsetLb;
? maxFieldLimit
: offsetLb;
offsetUb = idxVal.ub().getNumeral() < 0
? 0
: idxVal.ub().getNumeral();
? 0
: idxVal.ub().getNumeral();
offsetUb = idxVal.ub().getNumeral() > maxFieldLimit
? maxFieldLimit
: offsetUb;
? maxFieldLimit
: offsetUb;
}
}

if (type) {
if (const SVFPointerType *pty = SVFUtil::dyn_cast<SVFPointerType>(type)) {
if (type)
{
if (const SVFPointerType *pty = SVFUtil::dyn_cast<SVFPointerType>(type))
{
offsetLb = offsetLb * gep->getAccessPath().getElementNum(pty->getPtrElementType());
offsetUb = offsetUb * gep->getAccessPath().getElementNum(pty->getPtrElementType());
}
else {
else
{
const std::vector<u32_t>& so = SymbolTableInfo::SymbolInfo()
->getTypeInfo(type)
->getFlattenedElemIdxVec();
->getTypeInfo(type)
->getFlattenedElemIdxVec();
if (so.empty() || (u32_t)offsetUb >= so.size() ||
(u32_t)offsetLb >= so.size())
(u32_t)offsetLb >= so.size())
{
offsetLb = 0;
offsetUb = maxFieldLimit;
} else {
}
else
{
offsetLb =
SymbolTableInfo::SymbolInfo()->getFlattenedElemIdx(
type, offsetLb);
Expand All @@ -283,7 +301,8 @@ std::pair<s32_t, s32_t> SVFIR2ItvExeState::getIndexfromGepTypePair(const AccessP
}


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


std::pair<s32_t, s32_t> SVFIR2ItvExeState::getGepOffset(const GepStmt *gep) {
std::pair<s32_t, s32_t> 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 @@ -321,7 +341,7 @@ std::pair<s32_t, s32_t> SVFIR2ItvExeState::getGepOffset(const GepStmt *gep) {
for (int i = gep->getOffsetVarAndGepTypePairVec().size() - 1; i >= 0; i--)
{
std::pair<s32_t, s32_t> offsetIdx = getIndexfromGepTypePair(
gep->getOffsetVarAndGepTypePairVec()[i], gep);
gep->getOffsetVarAndGepTypePairVec()[i], gep);
s32_t offsetLb = offsetIdx.first;
s32_t offsetUb = offsetIdx.second;
if ((long long) (totalOffsetLb + offsetLb) > maxFieldLimit)
Expand Down

0 comments on commit dab4f64

Please sign in to comment.