Skip to content

Commit

Permalink
Upgrading SVF for LLVM 9.0.0 (https://github.com/llvm/llvm-project f7…
Browse files Browse the repository at this point in the history
…e52fbdb5a7af8ea0808e98458b497125a5eca1)
  • Loading branch information
lifeasageek committed Jul 25, 2019
1 parent 0b75f3e commit b7c0922
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 34 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.4.3)
# To support both in- and out-of-source builds,
# we check for the presence of the add_llvm_loadable_module command.
# - if this command is not present, we are building out-of-source
if(NOT COMMAND add_llvm_loadable_module)
if(NOT COMMAND add_llvm_library)
if (DEFINED ENV{LLVM_DIR})
# We need to match the build environment for LLVM:
# In particular, we need C++11 and the -fno-rtti flag
Expand Down
10 changes: 0 additions & 10 deletions include/MemoryModel/PAGBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ class PAGBuilder: public llvm::InstVisitor<PAGBuilder> {
}
void visitInvokeInst(llvm::InvokeInst &II) {
visitCallSite(&II);
visitTerminatorInst(II);
}
void visitCallSite(llvm::CallSite cs);
void visitReturnInst(llvm::ReturnInst &I);
Expand All @@ -147,9 +146,6 @@ class PAGBuilder: public llvm::InstVisitor<PAGBuilder> {
void visitExtractValueInst(llvm::ExtractValueInst &EVI);
void visitInsertValueInst(llvm::InsertValueInst &IVI) {
}
// Terminators
void visitTerminatorInst(llvm::TerminatorInst &TI) {
}
void visitBinaryOperator(llvm::BinaryOperator &I) {
}
void visitCmpInst(llvm::CmpInst &I) {
Expand All @@ -170,12 +166,6 @@ class PAGBuilder: public llvm::InstVisitor<PAGBuilder> {
}

/// Instruction not that often
void visitResumeInst(llvm::TerminatorInst &I) { /*returns void*/
}
void visitUnwindInst(llvm::TerminatorInst &I) { /*returns void*/
}
void visitUnreachableInst(llvm::TerminatorInst &I) { /*returns void*/
}
void visitFenceInst(llvm::FenceInst &I) { /*returns void*/
}
void visitAtomicCmpXchgInst(llvm::AtomicCmpXchgInst &I) {
Expand Down
6 changes: 3 additions & 3 deletions include/Util/PathCondAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class PathCondAllocator {
typedef DdNode Condition;
typedef std::map<u32_t,Condition*> CondPosMap; ///< map a branch to its Condition
typedef std::map<const llvm::BasicBlock*, CondPosMap > BBCondMap; // map bb to a Condition
typedef std::map<const Condition*, const llvm::TerminatorInst* > CondToTermInstMap; // map a condition to its branch instruction
typedef std::map<const Condition*, const llvm::Instruction* > CondToTermInstMap; // map a condition to its branch instruction
typedef std::set<const llvm::BasicBlock*> BasicBlockSet;
typedef std::map<const llvm::Function*, BasicBlockSet> FunToExitBBsMap; ///< map a function to all its basic blocks calling program exit
typedef std::map<const llvm::BasicBlock*, Condition*> BBToCondMap; ///< map a basic block to its condition during control-flow guard computation
Expand Down Expand Up @@ -85,7 +85,7 @@ class PathCondAllocator {
void allocate(const SVFModule module);

/// Get llvm conditional expression
inline const llvm::TerminatorInst* getCondInst(const Condition* cond) const {
inline const llvm::Instruction* getCondInst(const Condition* cond) const {
CondToTermInstMap::const_iterator it = condToInstMap.find(cond);
assert(it!=condToInstMap.end() && "this should be a fresh condition");
return it->second;
Expand Down Expand Up @@ -239,7 +239,7 @@ class PathCondAllocator {
//@}

/// Allocate a new condition
inline Condition* newCond(const llvm::TerminatorInst* inst) {
inline Condition* newCond(const llvm::Instruction* inst) {
Condition* cond = bddCondMgr->createNewCond(totalCondNum++);
assert(condToInstMap.find(cond)==condToInstMap.end() && "this should be a fresh condition");
condToInstMap[cond] = inst;
Expand Down
4 changes: 2 additions & 2 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ set(SOURCES
WPA/TypeAnalysis.cpp
WPA/WPAPass.cpp)

add_llvm_loadable_module(Svf ${SOURCES})
add_llvm_Library(LLVMSvf ${SOURCES})
add_llvm_library(Svf ${SOURCES})
add_llvm_library(LLVMSvf ${SOURCES})

link_directories( ${CMAKE_BINARY_DIR}/lib/Cudd )
llvm_map_components_to_libnames(llvm_libs bitwriter core ipo irreader instcombine instrumentation target linker analysis scalaropts support )
Expand Down
2 changes: 1 addition & 1 deletion lib/CUDD/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ set(SOURCES
restart.c
)

add_llvm_loadable_module(Cudd ${SOURCES})
add_llvm_library(Cudd ${SOURCES})
add_llvm_library(LLVMCudd ${SOURCES})

set_target_properties(Cudd PROPERTIES COMPILE_FLAGS "-Wno-format -Wno-int-to-pointer-cast -Wno-pointer-to-int-cast -O3 -w -DHAVE_IEEE_754 -DSIZEOF_VOID_P=8 -DSIZEOF_LONG=8")
Expand Down
4 changes: 2 additions & 2 deletions lib/SABER/ProgSlice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ std::string ProgSlice::evalFinalCond() const {
std::set<std::string> locations;
for(NodeBS::iterator it = elems.begin(), eit = elems.end(); it!=eit; ++it) {
Condition* atom = pathAllocator->getCond(*it);
const TerminatorInst* tinst = pathAllocator->getCondInst(atom);
const Instruction* tinst = pathAllocator->getCondInst(atom);
locations.insert(getSourceLoc(tinst));
}
/// print leak path after eliminating duplicated element
Expand All @@ -201,7 +201,7 @@ void ProgSlice::annotatePaths() {
NodeBS elems = pathAllocator->exactCondElem(finalCond);
for(NodeBS::iterator it = elems.begin(), eit = elems.end(); it!=eit; ++it) {
Condition* atom = pathAllocator->getCond(*it);
const TerminatorInst* tinst = pathAllocator->getCondInst(atom);
const Instruction* tinst = pathAllocator->getCondInst(atom);
if(const BranchInst* br = dyn_cast<BranchInst>(tinst)) {
annotator.annotateFeasibleBranch(br,0);
annotator.annotateFeasibleBranch(br,1);
Expand Down
10 changes: 5 additions & 5 deletions lib/Util/AnalysisUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,13 @@ const Type* analysisUtil::getTypeOfHeapAlloc(const Instruction *inst){
* Get position of a successor basic block
*/
u32_t analysisUtil::getBBSuccessorPos(const BasicBlock *BB, const BasicBlock *Succ) {
const TerminatorInst *Term = BB->getTerminator();
u32_t e = Term->getNumSuccessors();
for (u32_t i = 0; ; ++i) {
assert(i != e && "Didn't find succesor edge?");
if (Term->getSuccessor(i) == Succ)
u32_t i = 0;
for (const BasicBlock *SuccBB: successors(BB)) {
if (SuccBB == Succ)
return i;
i++;
}
assert(false && "Didn't find succesor edge?");
return 0;
}

Expand Down
16 changes: 11 additions & 5 deletions lib/Util/PathCondAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,11 +473,17 @@ void PathCondAllocator::printPathCond() {
for(BBCondMap::iterator it = bbConds.begin(), eit = bbConds.end(); it!=eit; ++it) {
const BasicBlock* bb = it->first;
for(CondPosMap::iterator cit = it->second.begin(), ecit = it->second.end(); cit!=ecit; ++cit) {
const TerminatorInst *Term = bb->getTerminator();
const BasicBlock* succ = Term->getSuccessor(cit->first);
Condition* cond = cit->second;
outs() << bb->getName() << "-->" << succ->getName() << ":";
outs() << dumpCond(cond) << "\n";
u32_t i=0;
for (const BasicBlock *succ: successors(bb)) {
if (i == cit->first) {
Condition* cond = cit->second;
outs() << bb->getName() << "-->" << succ->getName() << ":";
outs() << dumpCond(cond) << "\n";
break;
}
i++;
}

}
}
}
12 changes: 7 additions & 5 deletions lib/Util/SVFModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,24 +190,26 @@ void LLVMModuleSet::addSVFMain(){
Type * i8ptr2 = PointerType::getInt8PtrTy(M.getContext())->getPointerTo();
Type * i32 = IntegerType::getInt32Ty(M.getContext());
// define void @svf.main(i32, i8**, i8**)
Function *svfmain = (Function*)M.getOrInsertFunction(
FunctionCallee svfmain = M.getOrInsertFunction(
SVF_MAIN_FUNC_NAME,
Type::getVoidTy(M.getContext()),
i32,i8ptr2,i8ptr2
);
svfmain->setCallingConv(CallingConv::C);
BasicBlock* block = BasicBlock::Create(M.getContext(), "entry", svfmain);
Function *svfmainFn = dyn_cast<Function>(svfmain.getCallee());
svfmainFn->setCallingConv(CallingConv::C);

BasicBlock* block = BasicBlock::Create(M.getContext(), "entry", svfmainFn);
IRBuilder<> Builder(block);
// emit "call void @_GLOBAL__sub_I_XXX()"
for(auto & init: init_funcs){
Function *target = (Function*)M.getOrInsertFunction(
FunctionCallee target = M.getOrInsertFunction(
init->getName(),
Type::getVoidTy(M.getContext())
);
Builder.CreateCall(target);
}
// main() should be called after all _GLOBAL__sub_I_XXX functions.
Function::arg_iterator arg_it = svfmain->arg_begin();
Function::arg_iterator arg_it = svfmainFn->arg_begin();
Value * args[] = {arg_it, arg_it + 1, arg_it + 2 };
size_t cnt = orgMain->arg_size();
assert(cnt <= 3 && "Too many arguments for main()");
Expand Down

0 comments on commit b7c0922

Please sign in to comment.