From b7c0922ade78da2e13340e25fb5a405ba80b5033 Mon Sep 17 00:00:00 2001 From: Byoungyoung Lee Date: Thu, 25 Jul 2019 09:05:15 -0700 Subject: [PATCH] Upgrading SVF for LLVM 9.0.0 (https://github.com/llvm/llvm-project f7e52fbdb5a7af8ea0808e98458b497125a5eca1) --- CMakeLists.txt | 2 +- include/MemoryModel/PAGBuilder.h | 10 ---------- include/Util/PathCondAllocator.h | 6 +++--- lib/CMakeLists.txt | 4 ++-- lib/CUDD/CMakeLists.txt | 2 +- lib/SABER/ProgSlice.cpp | 4 ++-- lib/Util/AnalysisUtil.cpp | 10 +++++----- lib/Util/PathCondAllocator.cpp | 16 +++++++++++----- lib/Util/SVFModule.cpp | 12 +++++++----- 9 files changed, 32 insertions(+), 34 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6c7324756..0c24fa800 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/include/MemoryModel/PAGBuilder.h b/include/MemoryModel/PAGBuilder.h index 5e837af25..c06664c18 100644 --- a/include/MemoryModel/PAGBuilder.h +++ b/include/MemoryModel/PAGBuilder.h @@ -137,7 +137,6 @@ class PAGBuilder: public llvm::InstVisitor { } void visitInvokeInst(llvm::InvokeInst &II) { visitCallSite(&II); - visitTerminatorInst(II); } void visitCallSite(llvm::CallSite cs); void visitReturnInst(llvm::ReturnInst &I); @@ -147,9 +146,6 @@ class PAGBuilder: public llvm::InstVisitor { 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) { @@ -170,12 +166,6 @@ class PAGBuilder: public llvm::InstVisitor { } /// 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) { diff --git a/include/Util/PathCondAllocator.h b/include/Util/PathCondAllocator.h index e3911f36d..e60a4e6e7 100644 --- a/include/Util/PathCondAllocator.h +++ b/include/Util/PathCondAllocator.h @@ -46,7 +46,7 @@ class PathCondAllocator { typedef DdNode Condition; typedef std::map CondPosMap; ///< map a branch to its Condition typedef std::map BBCondMap; // map bb to a Condition - typedef std::map CondToTermInstMap; // map a condition to its branch instruction + typedef std::map CondToTermInstMap; // map a condition to its branch instruction typedef std::set BasicBlockSet; typedef std::map FunToExitBBsMap; ///< map a function to all its basic blocks calling program exit typedef std::map BBToCondMap; ///< map a basic block to its condition during control-flow guard computation @@ -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; @@ -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; diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index f9c445692..89dab0efe 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -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 ) diff --git a/lib/CUDD/CMakeLists.txt b/lib/CUDD/CMakeLists.txt index d3381e632..0258181ae 100644 --- a/lib/CUDD/CMakeLists.txt +++ b/lib/CUDD/CMakeLists.txt @@ -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") diff --git a/lib/SABER/ProgSlice.cpp b/lib/SABER/ProgSlice.cpp index 87d7d43ed..44b875a54 100644 --- a/lib/SABER/ProgSlice.cpp +++ b/lib/SABER/ProgSlice.cpp @@ -177,7 +177,7 @@ std::string ProgSlice::evalFinalCond() const { std::set 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 @@ -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(tinst)) { annotator.annotateFeasibleBranch(br,0); annotator.annotateFeasibleBranch(br,1); diff --git a/lib/Util/AnalysisUtil.cpp b/lib/Util/AnalysisUtil.cpp index a69a8085e..1998be70e 100644 --- a/lib/Util/AnalysisUtil.cpp +++ b/lib/Util/AnalysisUtil.cpp @@ -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; } diff --git a/lib/Util/PathCondAllocator.cpp b/lib/Util/PathCondAllocator.cpp index 16fb079f7..e6846736f 100644 --- a/lib/Util/PathCondAllocator.cpp +++ b/lib/Util/PathCondAllocator.cpp @@ -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++; + } + } } } diff --git a/lib/Util/SVFModule.cpp b/lib/Util/SVFModule.cpp index a653e8311..1adcc3c6d 100644 --- a/lib/Util/SVFModule.cpp +++ b/lib/Util/SVFModule.cpp @@ -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(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()");