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

opaque pointer support (type inference) for c #1323

Merged
merged 77 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
f3761ea
find type assert
jumormt Jan 6, 2024
18970cb
add assertion checking num field
jumormt Jan 6, 2024
40b8def
fix indirect call does not have called func
jumormt Jan 6, 2024
19fc337
add type check option
jumormt Jan 8, 2024
f57fc37
add type check option && first version of collect types
jumormt Jan 8, 2024
f38e36a
add "store (value operand) <- gep" rule
jumormt Jan 8, 2024
9c8d789
add inter-procedural rule
jumormt Jan 8, 2024
8e13066
add some comments
jumormt Jan 8, 2024
5144f86
fix call base bug
jumormt Jan 8, 2024
fae7e57
add callsite to callee inference
jumormt Jan 8, 2024
8934f21
do not propagate to declare func
jumormt Jan 8, 2024
4fcfafe
fix vararg
jumormt Jan 8, 2024
14efeb5
refactor
jumormt Jan 9, 2024
27fb0ea
use hash map to cache results
jumormt Jan 9, 2024
2e6d12d
refine
jumormt Jan 9, 2024
6f62afb
iterative memorizing dfs
jumormt Jan 9, 2024
7279bee
iterative memorizing dfs
jumormt Jan 9, 2024
5edb5f2
fix bug
jumormt Jan 9, 2024
3138be2
add comments and fix bug for c++20
jumormt Jan 9, 2024
7cad38a
fix deadloop
jumormt Jan 9, 2024
cc5f2aa
fix deadloop
jumormt Jan 9, 2024
28b941e
refine coding
jumormt Jan 9, 2024
f1cab1a
refactor inferTypeOfHeapObjOrStaticObj
jumormt Jan 9, 2024
8c838bf
refactor inferTypeOfHeapObjOrStaticObj
jumormt Jan 9, 2024
87b671c
add a new typeinference class
jumormt Jan 10, 2024
d38f373
refactor
jumormt Jan 10, 2024
076ca38
fix bug
jumormt Jan 10, 2024
8d15f3f
add debug support
jumormt Jan 10, 2024
cf89135
add default type
jumormt Jan 10, 2024
4712b6b
move getptrelementtype to test
jumormt Jan 10, 2024
550ebb1
move getClassNameOfThisPtr to chg builder and add diff test
jumormt Jan 10, 2024
3063af8
remove getelementptr in SVFExt and llvmmodule
jumormt Jan 10, 2024
376d729
return max field for ptr type
jumormt Jan 11, 2024
fd0e4d4
default for heap is i8
jumormt Jan 11, 2024
9a89761
for param of ext api, first find source and then derive type
jumormt Jan 11, 2024
868e023
refactor getOrInferLLVMObjType
jumormt Jan 11, 2024
9f45f32
skip global function value -> callsite when forward infer type
jumormt Jan 11, 2024
578a379
update comment
jumormt Jan 11, 2024
ef078d7
fix passing a function as a param
jumormt Jan 11, 2024
8889fd0
rename typesizedifftest, remove unnecessary getfirstcast
jumormt Jan 12, 2024
ef8ccd1
remove getptrelement and getpointerto in svf/*
jumormt Jan 12, 2024
058f626
ptr in svf main
jumormt Jan 12, 2024
b13b37f
thisptr class name prepare
jumormt Jan 12, 2024
8639716
infer type based on c++ constructor
jumormt Jan 13, 2024
ec19b79
add comments
jumormt Jan 13, 2024
1d33ec4
getOrInferThisPtrClassName update
jumormt Jan 13, 2024
d17948b
refine type diff test
jumormt Jan 14, 2024
5f35694
refine type diff test
jumormt Jan 14, 2024
1d52b55
fix indirect call passing
jumormt Jan 14, 2024
f854a53
separate cpp source and allocation
jumormt Jan 15, 2024
1857464
refactor iscpp constructor
jumormt Jan 15, 2024
a243d10
update
jumormt Jan 15, 2024
8efc471
for c++ fw type inference, consider constructor for now
jumormt Jan 15, 2024
04d89a8
update
jumormt Jan 15, 2024
f3a4f8e
delete c++
jumormt Jan 15, 2024
6cf0f73
delete c++
jumormt Jan 15, 2024
146fbd8
update based on comments
jumormt Jan 16, 2024
ab8963d
rename
jumormt Jan 16, 2024
ab04330
refactor
jumormt Jan 17, 2024
0aeeacb
reformat
jumormt Jan 17, 2024
76cdfc3
refactor
jumormt Jan 17, 2024
22dd059
move typeinference to LLVMModuleSet
jumormt Jan 21, 2024
12b3431
release llvm modouleset immediately after svfir is built
jumormt Jan 21, 2024
7352b98
remove static method
jumormt Jan 21, 2024
c363ad3
fix ander diff test
jumormt Jan 21, 2024
6ffb132
fix saber
jumormt Jan 21, 2024
3cdc19e
bytesize default 1
jumormt Jan 24, 2024
37f43f2
fix wpa release llvm module
jumormt Jan 24, 2024
8118f53
fix mac CI
jumormt Jan 24, 2024
eb34d0a
delete cpp
jumormt Jan 24, 2024
a176ca5
move release llvmmoduleset to the end of main
jumormt Jan 24, 2024
63aa46e
merge SVF master into opaque c
jumormt Jan 24, 2024
4d2f565
rename typeinference to objtypeinference
jumormt Jan 25, 2024
82f2e31
enable type check by default
jumormt Jan 25, 2024
9e61dd0
refactor
jumormt Jan 25, 2024
b0980a0
rename cpp and add ctest type infer CI
jumormt Jan 25, 2024
d620c42
add some assertions for npd
jumormt Jan 25, 2024
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
Prev Previous commit
Next Next commit
remove getelementptr in SVFExt and llvmmodule
  • Loading branch information
jumormt committed Jan 24, 2024
commit 3063af8d307db9b579fe3618214a8ce46e305612
6 changes: 3 additions & 3 deletions svf-llvm/include/SVF-LLVM/TypeInference.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ class TypeInference {
/// Forward collect all possible infer sites starting from a value
const Type *getOrInferLLVMObjType(const Value *startValue);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

InferObjType


/// Default type
const Type *defaultTy(const Value *val);

/// Validate type inference
void validateTypeCheck(const CallBase *cs);

Expand All @@ -74,6 +71,9 @@ class TypeInference {

protected:
static const Type *infersiteToType(const Value *val);

/// Default type
const Type *defaultTy(const Value *val);
};
}
#endif //SVF_TYPEINFERENCE_H
9 changes: 0 additions & 9 deletions svf-llvm/lib/LLVMModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1380,15 +1380,6 @@ 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");
// TODO: getPtrElementType to be removed
if(!pt->isOpaque())
svfPtrType->setPtrElementType(getSVFType(LLVMUtil::getPtrElementType(pt)));
}

return svftype;
}
Expand Down
11 changes: 4 additions & 7 deletions svf-llvm/lib/SVFIRExtAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "SVF-LLVM/SVFIRBuilder.h"
#include "Util/SVFUtil.h"
#include "SVF-LLVM/SymbolTableBuilder.h"
#include "SVF-LLVM/TypeInference.h"

using namespace std;
using namespace SVF;
Expand All @@ -43,12 +44,8 @@ const Type* SVFIRBuilder::getBaseTypeAndFlattenedFields(const Value* V, std::vec
{
assert(V);
const Value* value = getBaseValueForExtArg(V);
const Type* T = value->getType();
// TODO: getPtrElementType need type inference
while (const PointerType *ptype = SVFUtil::dyn_cast<PointerType>(T))
T = getPtrElementType(ptype);

u32_t numOfElems = pag->getSymbolInfo()->getNumOfFlattenElements(LLVMModuleSet::getLLVMModuleSet()->getSVFType(T));
const Type *objType = TypeInference::getTypeInference()->getOrInferLLVMObjType(value);
u32_t numOfElems = pag->getSymbolInfo()->getNumOfFlattenElements(LLVMModuleSet::getLLVMModuleSet()->getSVFType(objType));
/// use user-specified size for this copy operation if the size is a constaint int
if(szValue && SVFUtil::isa<ConstantInt>(szValue))
{
Expand All @@ -71,7 +68,7 @@ const Type* SVFIRBuilder::getBaseTypeAndFlattenedFields(const Value* V, std::vec
ls.addOffsetVarAndGepTypePair(getPAG()->getGNode(getPAG()->getValueNode(svfOffset)), nullptr);
fields.push_back(ls);
}
return T;
return objType;
}

/*!
Expand Down
5 changes: 0 additions & 5 deletions svf-llvm/lib/SymbolTableBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,11 +612,6 @@ const Type* SymbolTableBuilder::inferTypeOfHeapObjOrStaticObj(const Instruction
assert( false && "not a heap allocation instruction?");
}

if (inferedType == nullptr) {
// return a default type if the inferred type is empty
inferedType = getTypeInference()->defaultTy(startValue);
}

getTypeInference()->typeEleNumDiffTest(originalPType, inferedType, startValue);

return inferedType;
Expand Down
9 changes: 4 additions & 5 deletions svf-llvm/lib/TypeInference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const Type *TypeInference::getOrInferLLVMObjType(const Value *startValue) {
auto tIt = _valueToType.find(startValue);
if (tIt != _valueToType.end()) {
WARN_IFNOT(tIt->second, "empty type:" + VALUE_WITH_DBGINFO(startValue));
return tIt->second;
return tIt->second ? tIt->second : getTypeInference()->defaultTy(startValue);
}

INC_TRACE();
Expand Down Expand Up @@ -152,6 +152,8 @@ const Type *TypeInference::getOrInferLLVMObjType(const Value *startValue) {
if (!canUpdate && !_valueToInferSites.count(curValue)) {
workList.push({curValue, true});
}
if (const GetElementPtrInst *gepInst = SVFUtil::dyn_cast<GetElementPtrInst>(curValue))
insertInferSite(gepInst);
for (const auto &it: curValue->uses()) {
if (LoadInst *loadInst = SVFUtil::dyn_cast<LoadInst>(it.getUser())) {
/*
Expand Down Expand Up @@ -256,6 +258,7 @@ const Type *TypeInference::getOrInferLLVMObjType(const Value *startValue) {
}
const Type* type = _valueToType[startValue];
if (type == nullptr) {
type = getTypeInference()->defaultTy(startValue);
WARN_MSG("empty type, trace ID is " + std::to_string(traceId) + ":" + VALUE_WITH_DBGINFO(startValue));
}
return type;
Expand All @@ -270,10 +273,6 @@ void TypeInference::validateTypeCheck(const CallBase *cs) {
if (const Function *func = cs->getCalledFunction()) {
if (func->getName().find(TYPEMALLOC) != std::string::npos) {
const Type *objType = getOrInferLLVMObjType(cs);
if (!objType) {
// return an 8-bit integer type if the inferred type is empty
objType = Type::getInt8Ty(LLVMModuleSet::getLLVMModuleSet()->getContext());
}
ConstantInt *pInt =
SVFUtil::dyn_cast<llvm::ConstantInt>(cs->getOperand(1));
assert(pInt && "the second argument is a integer");
Expand Down