Skip to content

Commit

Permalink
Merge pull request #1246 from bjjwwang/1107
Browse files Browse the repository at this point in the history
fix 2 bug
  • Loading branch information
yuleisui authored Nov 17, 2023
2 parents 84d5117 + e4faa11 commit fd80c14
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
11 changes: 9 additions & 2 deletions svf-llvm/lib/LLVMModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1253,8 +1253,9 @@ SVFType* LLVMModuleSet::addSVFTypeInfo(const Type* T)
"SVFType has been added before");

SVFType* svftype;
if (const PointerType* pt = SVFUtil::dyn_cast<PointerType>(T))
svftype = new SVFPointerType(getSVFType(LLVMUtil::getPtrElementType(pt)));
if (SVFUtil::isa<PointerType>(T)) {
svftype = new SVFPointerType();
}
else if (const IntegerType* intT = SVFUtil::dyn_cast<IntegerType>(T))
{
auto svfIntT = new SVFIntegerType();
Expand Down Expand Up @@ -1290,6 +1291,12 @@ SVFType* LLVMModuleSet::addSVFTypeInfo(const Type* T)

symInfo->addTypeInfo(svftype);
LLVMType2SVFType[T] = svftype;
if (const PointerType* pt = SVFUtil::dyn_cast<PointerType>(T)) {
//cast svftype to SVFPointerType
SVFPointerType* svfPtrType = SVFUtil::dyn_cast<SVFPointerType>(svftype);
assert(svfPtrType && "this is not SVFPointerType");
svfPtrType->setPtrElementType(getSVFType(LLVMUtil::getPtrElementType(pt)));
}
return svftype;
}

Expand Down
10 changes: 8 additions & 2 deletions svf/include/SVFIR/SVFType.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,19 +350,25 @@ class SVFPointerType : public SVFType
const SVFType* ptrElementType;

public:
SVFPointerType(const SVFType* pty)
: SVFType(true, SVFPointerTy), ptrElementType(pty)
SVFPointerType()
: SVFType(true, SVFPointerTy), ptrElementType(nullptr)
{
}

static inline bool classof(const SVFType* node)
{
return node->getKind() == SVFPointerTy;
}
inline const SVFType* getPtrElementType() const
{
assert(ptrElementType && "ptrElementType is nullptr");
return ptrElementType;
}

inline void setPtrElementType(SVFType* _ptrElementType) {
ptrElementType = _ptrElementType;
}

void print(std::ostream& os) const override;
};

Expand Down
12 changes: 6 additions & 6 deletions svf/lib/MemoryModel/AccessPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ APOffset AccessPath::computeConstantByteOffset() const
if (const SVFStructType* structType = SVFUtil::dyn_cast<SVFStructType>(type))
{
/// for (1) structType: %struct.DEST
/// structField = 0, type2: int
/// structField = 1, type2: char[10]
/// structField = 2, type2: int[5]
for (u32_t structField = 0; structField < (u32_t)op->getSExtValue(); ++structField)
{
type2 = structType->getTypeInfo()->getOriginalElemType(structField);
/// structField = 0, flattenIdx = 0, type2: int
/// structField = 1, flattenIdx = 1, type2: char[10]
/// structField = 2, flattenIdx = 11, type2: int[5]
for (u32_t structField = 0; structField < (u32_t)op->getSExtValue(); ++structField) {
u32_t flattenIdx = structType->getTypeInfo()->getFlattenedFieldIdxVec()[structField];
type2 = structType->getTypeInfo()->getOriginalElemType(flattenIdx);
totalConstOffset += type2->getLLVMByteSize();
}
}
Expand Down
2 changes: 1 addition & 1 deletion svf/lib/SVFIR/SVFFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ SVFType* createSVFType(SVFType::GNodeK kind, bool isSingleValTy)
ABORT_MSG("Creation of RAW SVFType isn't allowed");
case SVFType::SVFPointerTy:
ABORT_IFNOT(isSingleValTy, "Pointer type must be single-valued");
return new SVFPointerType(nullptr);
return new SVFPointerType();
case SVFType::SVFIntegerTy:
ABORT_IFNOT(isSingleValTy, "Integer type must be single-valued");
return new SVFIntegerType();
Expand Down

0 comments on commit fd80c14

Please sign in to comment.