8000 opaque pointer stage 2-1 by jumormt · Pull Request #1304 · SVF-tools/SVF · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

opaque pointer stage 2-1 #1304

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

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 0 additions & 4 deletions svf-llvm/include/SVF-LLVM/LLVMUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,6 @@ static inline Type* getPtrElementType(const PointerType* pty)
#endif
}

/// Infer type based on llvm value, this is for the migration to opaque pointer
/// please refer to: https://llvm.org/docs/OpaquePointers.html#migration-instructions
Type *getPointeeType(const Value *value);

/// Get the reference type of heap/static object from an allocation site.
//@{
const Type *inferTypeOfHeapObjOrStaticObj(const Instruction* inst);
Expand Down
65 changes: 0 additions & 65 deletions svf-llvm/lib/LLVMUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,71 +241,6 @@ const Value* LLVMUtil::stripConstantCasts(const Value* val)
return val;
}

/// Infer type based on llvm value, this is for the migration to opaque pointer
/// please refer to: https://llvm.org/docs/OpaquePointers.html#migration-instructions
Type *LLVMUtil::getPointeeType(const Value *value)
{
assert(value && "value cannot be nullptr!");
if (const LoadInst *loadInst = SVFUtil::dyn_cast<LoadInst>(value))
{
// get the pointee type of rhs based on lhs
// e.g., for `%lhs = load i64, ptr %rhs`, we return i64
return loadInst->getType();
}
else if (const StoreInst *storeInst = SVFUtil::dyn_cast<StoreInst>(value))
{
// get the pointee type of op1 based on op0
// e.g., for `store i64 %op0, ptr %op1`, we return i64
return storeInst->getValueOperand()->getType();
}
else if (const GetElementPtrInst *gepInst = SVFUtil::dyn_cast<GetElementPtrInst>(value))
{
// get the source element type of a gep instruction
// e.g., for `gep %struct.foo, ptr %base, i64 0`, we return struct.foo
return gepInst->getSourceElementType();
}
else if (const GEPOperator* gepOperator = SVFUtil::dyn_cast<GEPOperator>(value))
{
// get the source element type of a gep instruction
// e.g., for `gep %struct.foo, ptr %base, i64 0`, we return struct.foo
return gepOperator->getSourceElementType();
}
else if (const CallInst *callInst = SVFUtil::dyn_cast<CallInst>(value))
{
// get the pointee type of return value
// e.g., for `%call = call ptr @_Znwm(i64 noundef 8)`, we return i64
return callInst->getFunctionType();
}
else if (const CallBase *callBase = SVFUtil::dyn_cast<CallBase>(value))
{
// get the pointee type of return value
// e.g., for `%call = call ptr @_Znwm(i64 noundef 8)`, we return i64
return callBase->getFunctionType();
}
else if (const AllocaInst *allocaInst = SVFUtil::dyn_cast<AllocaInst>(value))
{
// get the type of the allocated memory
// e.g., for `%retval = alloca i64, align 4`, we return i64
return allocaInst->getAllocatedType();
}
else if (const GlobalVariable *globalVar = SVFUtil::dyn_cast<GlobalVariable>(value))
{
// get the pointee type of the global pointer
return globalVar->getValueType();
}
else if (const Function* func = SVFUtil::dyn_cast<Function>(value))
{
// get the pointee type of return value
// e.g., for `%call = call ptr @_Znwm(i64 noundef 8)`, we return i64
return func->getFunctionType();
}
else
{
assert(false && (LLVMUtil::dumpValue(value) + "Unknown llvm Type, cannot get Ptr Element Type").c_str());
Copy link
Collaborator

Choose a reason for hiding this comment

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

better to dump this unknown value.

abort();
}
}

void LLVMUtil::viewCFG(const Function* fun)
{
if (fun != nullptr)
Expand Down
2 changes: 1 addition & 1 deletion svf-llvm/lib/SVFIRBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ bool SVFIRBuilder::computeGepOffset(const User *V, AccessPath& ap)
// If it's a non-constant offset access
// If its point-to target is struct or array, it's likely an array accessing (%result = gep %struct.A* %a, i32 %non-const-index)
// If its point-to target is single value (pointer arithmetic), then it's a variant gep (%result = gep i8* %p, i32 %non-const-index)
if(!op && gepTy->isPointerTy() && LLVMUtil::getPointeeType(V)->isSingleValueType())
if(!op && gepTy->isPointerTy() && gepOp->getSourceElementType()->isSingleValueType())
{
isConst = false;
}
Expand Down
26 changes: 17 additions & 9 deletions svf-llvm/lib/SymbolTableBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,8 @@ void SymbolTableBuilder::buildMemModel(SVFModule* svfModule)

void SymbolTableBuilder::collectSVFTypeInfo(const Value* val)
{
(void)getOrAddSVFTypeInfo(val->getType());
if (const PointerType * ptrType = SVFUtil::dyn_cast<PointerType>(val->getType()))
{
// TODO: getPtrElementType to be removed
const Type* objtype = LLVMUtil::getPtrElementType(ptrType);
(void)getOrAddSVFTypeInfo(objtype);
}
Type *valType = val->getType();
(void)getOrAddSVFTypeInfo(valType);
if(isGepConstantExpr(val) || SVFUtil::isa<GetElementPtrInst>(val))
{
for (bridge_gep_iterator
Expand Down Expand Up @@ -590,12 +585,25 @@ ObjTypeInfo* SymbolTableBuilder::createObjTypeInfo(const Value* val)
// (2) Other objects (e.g., alloca, global, etc.)
else
{
if(const PointerType* refTy = SVFUtil::dyn_cast<PointerType>(val->getType()))
objTy = getPtrElementType(refTy);
if (SVFUtil::isa<PointerType>(val->getType())) {
if (const AllocaInst *allocaInst = SVFUtil::dyn_cast<AllocaInst>(val))
{
// get the type of the allocated memory
// e.g., for `%retval = alloca i64, align 4`, we return i64
objTy = allocaInst->getAllocatedType();
} else if (const GlobalValue *global = SVFUtil::dyn_cast<GlobalValue>(val)) {
// get the pointee type of the global pointer (begins with @ symbol in llvm)
objTy = global->getValueType();
} else {
SVFUtil::errs() << dumpValue(val) << "\n";
assert(false && "not an allocation or global?");
}
}
}

if (objTy)
{
(void) getOrAddSVFTypeInfo(objTy);
Copy link
Collaborator

Choose a reason for hiding this comment

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

should return an SVFType ad use it at line 596.

ObjTypeInfo* typeInfo = new ObjTypeInfo(
LLVMModuleSet::getLLVMModuleSet()->getSVFType(objTy),
Options::MaxFieldLimit());
Expand Down
0