diff --git a/build.sh b/build.sh index cc22ace7e..87aa3ca57 100755 --- a/build.sh +++ b/build.sh @@ -14,10 +14,10 @@ jobs=4 SVFHOME=$(pwd) sysOS=$(uname -s) arch=$(uname -m) -MacLLVM="https://github.com/llvm/llvm-project/releases/download/llvmorg-13.0.0/clang+llvm-13.0.0-x86_64-apple-darwin.tar.xz" -UbuntuLLVM="https://github.com/llvm/llvm-project/releases/download/llvmorg-13.0.0/clang+llvm-13.0.0-x86_64-linux-gnu-ubuntu-16.04.tar.xz" -UbuntuArmLLVM="https://github.com/llvm/llvm-project/releases/download/llvmorg-13.0.0/clang+llvm-13.0.0-aarch64-linux-gnu.tar.xz" -SourceLLVM="https://github.com/llvm/llvm-project/archive/refs/tags/llvmorg-13.0.0.zip" +MacArmLLVM="https://github.com/llvm/llvm-project/releases/download/llvmorg-15.0.0/clang+llvm-15.0.0-arm64-apple-darwin21.0.tar.xz" +MacLLVM="https://github.com/llvm/llvm-project/releases/download/llvmorg-15.0.0/clang+llvm-15.0.0-x86_64-apple-darwin.tar.xz" +UbuntuArmLLVM="https://github.com/llvm/llvm-project/releases/download/llvmorg-15.0.0/clang+llvm-15.0.0-aarch64-linux-gnu.tar.xz" +SourceLLVM="https://github.com/llvm/llvm-project/archive/refs/tags/llvmorg-15.0.0.zip" MacZ3="https://github.com/Z3Prover/z3/releases/download/z3-4.8.8/z3-4.8.8-x64-osx-10.14.6.zip" MacArmZ3="https://github.com/Z3Prover/z3/releases/download/z3-4.9.1/z3-4.9.1-arm64-osx-11.0.zip" UbuntuZ3="https://github.com/Z3Prover/z3/releases/download/z3-4.8.8/z3-4.8.8-x64-ubuntu-16.04.zip" @@ -25,7 +25,7 @@ SourceZ3="https://github.com/Z3Prover/z3/archive/refs/tags/z3-4.8.8.zip" # Keep LLVM version suffix for version checking and better debugging # keep the version consistent with LLVM_DIR in setup.sh and llvm_version in Dockerfile -LLVMHome="llvm-13.0.0.obj" +LLVMHome="llvm-15.0.0.obj" Z3Home="z3.obj" @@ -33,8 +33,7 @@ Z3Home="z3.obj" # depending on OS. # E.g. generic_download_file www.url.com/my.zip loc/my.zip function generic_download_file { - if [ $# -ne 2 ] - then + if [ $# -ne 2 ]; then echo "$0: bad args to generic_download_file!" exit 1 fi @@ -115,7 +114,7 @@ function build_llvm_from_source { mkdir llvm-build cd llvm-build # /*/ is a dirty hack to get llvm-project-llvmorg-version... - cmake -DCMAKE_INSTALL_PREFIX="$SVFHOME/$LLVMHome" ../llvm-source/*/llvm + cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="$SVFHOME/$LLVMHome" ../llvm-source/*/llvm make -j${jobs} make install @@ -132,27 +131,23 @@ OSDisplayName="" # Set OS-specific values, mainly URLs to download binaries from. # M1 Macs give back arm64, some Linuxes can give aarch64 for arm architecture ####### -if [[ $sysOS == "Darwin" ]] -then - if [[ "$arch" == "arm64" ]] - then - urlZ3="$MacArmZ3" - urlLLVM="llvm does not have osx arm pre-built libs" +if [[ $sysOS == "Darwin" ]]; then + if [[ "$arch" == "arm64" ]]; then + urlZ3="$MacArmZ3" + urlLLVM="$MacArmLLVM" OSDisplayName="macOS arm64" - else + else urlZ3="$MacZ3" urlLLVM="$MacLLVM" OSDisplayName="macOS x86" fi -elif [[ $sysOS == "Linux" ]] -then - if [[ "$arch" == "aarch64" ]] - then - urlLLVM="$UbuntuArmLLVM" +elif [[ $sysOS == "Linux" ]]; then + if [[ "$arch" == "aarch64" ]]; then + urlLLVM="$UbuntuArmLLVM" urlZ3="z3 does not have x86 arm pre-built libs" OSDisplayName="Ubuntu arm64" - else - urlLLVM="$UbuntuLLVM" + else + urlLLVM="x86_64 Linux does not have pre-built LLVM libs" urlZ3="$UbuntuZ3" OSDisplayName="Ubuntu x86" fi @@ -163,14 +158,13 @@ fi ######## # Download LLVM if need be. ####### -if [ ! -d "$LLVM_DIR" ] -then - if [ ! -d "$LLVMHome" ] - then - if [ "$sysOS" = "Darwin" ] && [ "$arch" = "arm64" ] # only mac arm build from source - then +if [ ! -d "$LLVM_DIR" ]; then + if [ ! -d "$LLVMHome" ]; then + if [[ "$sysOS" = "Linux" && "$arch" = "x86_64" ]]; then + # x86_64 Linux has to build LLVM from source build_llvm_from_source - else # everything else downloads pre-built lib includ osx "arm64" + else + # everything else downloads pre-built lib includ osx "arm64" echo "Downloading LLVM binary for $OSDisplayName" generic_download_file "$urlLLVM" llvm.tar.xz check_xz @@ -191,10 +185,11 @@ then if [ ! -d "$Z3Home" ] then # M1 Macs give back arm64, some Linuxes can give aarch64. - if [ "$sysOS" = "Linux" ] && [ "$arch" = "aarch64" ] # only linux arm build from source - then + if [[ "$sysOS" = "Linux" && "$arch" = "aarch64" ]]; then + # only linux arm build from source build_z3_from_source - else # everything else downloads pre-built lib includ osx "arm64" + else + # everything else downloads pre-built lib includ osx "arm64" echo "Downloading Z3 binary for $OSDisplayName" generic_download_file "$urlZ3" z3.zip check_unzip @@ -214,30 +209,25 @@ echo "Z3_DIR=$Z3_DIR" ######## # Build SVF ######## -if [[ $1 == 'debug' ]] -then - rm -rf ./'Debug-build' - mkdir ./'Debug-build' - cd ./'Debug-build' - cmake -D CMAKE_BUILD_TYPE:STRING=Debug ../ +if [[ $1 =~ [Dd]ebug ]]; then + build_type='Debug' else - rm -rf ./'Release-build' - mkdir ./'Release-build' - cd ./'Release-build' - cmake ../ - fi + build_type='Release' +fi +build_dir="./${build_type}-build" + +rm -rf "${build_dir}" +mkdir "${build_dir}" +cd "${build_dir}" +cmake -D CMAKE_BUILD_TYPE:STRING=$build_type ../ + make -j ${jobs} ######## # Set up environment variables of SVF ######## cd ../ -if [[ $1 == 'debug' ]] -then - . ./setup.sh debug -else - . ./setup.sh -fi +source ./setup.sh "${build_type}" ######### # Optionally, you can also specify a CXX_COMPILER and your $LLVM_HOME for your build diff --git a/include/Graphs/ConsGNode.h b/include/Graphs/ConsGNode.h index 4dca42757..5d51cf3ca 100644 --- a/include/Graphs/ConsGNode.h +++ b/include/Graphs/ConsGNode.h @@ -259,56 +259,68 @@ class ConstraintNode : public GenericConsNodeTy storeInEdges.insert(inEdge); addIncomingEdge(inEdge); } - inline void addIncomingDirectEdge(ConstraintEdge* inEdge) + inline bool addIncomingDirectEdge(ConstraintEdge* inEdge) { assert(inEdge->getDstID() == this->getId()); bool added1 = directInEdges.insert(inEdge).second; bool added2 = addIncomingEdge(inEdge); - assert(added1 && added2 && "edge not added, duplicated adding!!"); + bool both_added = added1 & added2; + assert(both_added && "edge not added, duplicated adding!!"); + return both_added; } inline void addOutgoingAddrEdge(AddrCGEdge* outEdge) { addressOutEdges.insert(outEdge); addOutgoingEdge(outEdge); } - inline void addOutgoingLoadEdge(LoadCGEdge* outEdge) + inline bool addOutgoingLoadEdge(LoadCGEdge* outEdge) { bool added1 = loadOutEdges.insert(outEdge).second; bool added2 = addOutgoingEdge(outEdge); - assert(added1 && added2 && "edge not added, duplicated adding!!"); + bool both_added = added1 & added2; + assert(both_added && "edge not added, duplicated adding!!"); + return both_added; } - inline void addOutgoingStoreEdge(StoreCGEdge* outEdge) + inline bool addOutgoingStoreEdge(StoreCGEdge* outEdge) { bool added1 = storeOutEdges.insert(outEdge).second; bool added2 = addOutgoingEdge(outEdge); - assert(added1 && added2 && "edge not added, duplicated adding!!"); + bool both_added = added1 & added2; + assert(both_added && "edge not added, duplicated adding!!"); + return both_added; } - inline void addOutgoingDirectEdge(ConstraintEdge* outEdge) + inline bool addOutgoingDirectEdge(ConstraintEdge* outEdge) { assert(outEdge->getSrcID() == this->getId()); bool added1 = directOutEdges.insert(outEdge).second; bool added2 = addOutgoingEdge(outEdge); - assert(added1 && added2 && "edge not added, duplicated adding!!"); + bool both_added = added1 & added2; + assert(both_added && "edge not added, duplicated adding!!"); + return both_added; } //@} /// Remove constraint graph edges //{@ - inline void removeOutgoingAddrEdge(AddrCGEdge* outEdge) + inline bool removeOutgoingAddrEdge(AddrCGEdge* outEdge) { u32_t num1 = addressOutEdges.erase(outEdge); u32_t num2 = removeOutgoingEdge(outEdge); - assert((num1 && num2) && "edge not in the set, can not remove!!!"); + bool removed = (num1 > 0) & (num2 > 0); + assert(removed && "edge not in the set, can not remove!!!"); + return removed; } - inline void removeIncomingAddrEdge(AddrCGEdge* inEdge) + inline bool removeIncomingAddrEdge(AddrCGEdge* inEdge) { u32_t num1 = addressInEdges.erase(inEdge); u32_t num2 = removeIncomingEdge(inEdge); - assert((num1 && num2) && "edge not in the set, can not remove!!!"); + bool removed = (num1 > 0) & (num2 > 0); + assert(removed && "edge not in the set, can not remove!!!"); + return removed; } - inline void removeOutgoingDirectEdge(ConstraintEdge* outEdge) + inline bool removeOutgoingDirectEdge(ConstraintEdge* outEdge) { if (SVFUtil::isa(outEdge)) gepOutEdges.erase(outEdge); @@ -316,10 +328,12 @@ class ConstraintNode : public GenericConsNodeTy copyOutEdges.erase(outEdge); u32_t num1 = directOutEdges.erase(outEdge); u32_t num2 = removeOutgoingEdge(outEdge); - assert((num1 && num2) && "edge not in the set, can not remove!!!"); + bool removed = (num1 > 0) & (num2 > 0); + assert(removed && "edge not in the set, can not remove!!!"); + return removed; } - inline void removeIncomingDirectEdge(ConstraintEdge* inEdge) + inline bool removeIncomingDirectEdge(ConstraintEdge* inEdge) { if (SVFUtil::isa(inEdge)) gepInEdges.erase(inEdge); @@ -327,35 +341,45 @@ class ConstraintNode : public GenericConsNodeTy copyInEdges.erase(inEdge); u32_t num1 = directInEdges.erase(inEdge); u32_t num2 = removeIncomingEdge(inEdge); - assert((num1 && num2) && "edge not in the set, can not remove!!!"); + bool removed = (num1 > 0) & (num2 > 0); + assert(removed && "edge not in the set, can not remove!!!"); + return removed; } - inline void removeOutgoingLoadEdge(LoadCGEdge* outEdge) + inline bool removeOutgoingLoadEdge(LoadCGEdge* outEdge) { u32_t num1 = loadOutEdges.erase(outEdge); u32_t num2 = removeOutgoingEdge(outEdge); - assert((num1 && num2) && "edge not in the set, can not remove!!!"); + bool removed = (num1 > 0) & (num2 > 0); + assert(removed && "edge not in the set, can not remove!!!"); + return removed; } - inline void removeIncomingLoadEdge(LoadCGEdge* inEdge) + inline bool removeIncomingLoadEdge(LoadCGEdge* inEdge) { u32_t num1 = loadInEdges.erase(inEdge); u32_t num2 = removeIncomingEdge(inEdge); - assert((num1 && num2) && "edge not in the set, can not remove!!!"); + bool removed = (num1 > 0) & (num2 > 0); + assert(removed && "edge not in the set, can not remove!!!"); + return removed; } - inline void removeOutgoingStoreEdge(StoreCGEdge* outEdge) + inline bool removeOutgoingStoreEdge(StoreCGEdge* outEdge) { u32_t num1 = storeOutEdges.erase(outEdge); u32_t num2 = removeOutgoingEdge(outEdge); - assert((num1 && num2) && "edge not in the set, can not remove!!!"); + bool removed = (num1 > 0) & (num2 > 0); + assert(removed && "edge not in the set, can not remove!!!"); + return removed; } - inline void removeIncomingStoreEdge(StoreCGEdge* inEdge) + inline bool removeIncomingStoreEdge(StoreCGEdge* inEdge) { u32_t num1 = storeInEdges.erase(inEdge); u32_t num2 = removeIncomingEdge(inEdge); - assert((num1 && num2) && "edge not in the set, can not remove!!!"); + bool removed = (num1 > 0) & (num2 > 0); + assert(removed && "edge not in the set, can not remove!!!"); + return removed; } //@} diff --git a/include/Graphs/GenericGraph.h b/include/Graphs/GenericGraph.h index 5205d2041..1122aecbe 100644 --- a/include/Graphs/GenericGraph.h +++ b/include/Graphs/GenericGraph.h @@ -292,13 +292,15 @@ class GenericNode { iterator it = InEdges.find(edge); assert(it != InEdges.end() && "can not find in edge in SVFG node"); - return InEdges.erase(edge); + InEdges.erase(it); + return 1; } inline u32_t removeOutgoingEdge(EdgeType* edge) { iterator it = OutEdges.find(edge); assert(it != OutEdges.end() && "can not find out edge in SVFG node"); - return OutEdges.erase(edge); + OutEdges.erase(it); + return 1; } ///@} diff --git a/include/Graphs/ICFG.h b/include/Graphs/ICFG.h index 75f845adc..5b8242842 100644 --- a/include/Graphs/ICFG.h +++ b/include/Graphs/ICFG.h @@ -179,8 +179,9 @@ class ICFG : public GenericICFGTy { bool added1 = edge->getDstNode()->addIncomingEdge(edge); bool added2 = edge->getSrcNode()->addOutgoingEdge(edge); - assert(added1 && added2 && "edge not added??"); - return true; + bool all_added = added1 && added2; + assert(all_added && "ICFGEdge not added?"); + return all_added; } /// Add a ICFG node diff --git a/include/Graphs/SVFGOPT.h b/include/Graphs/SVFGOPT.h index 2c53eab97..c2244e38a 100644 --- a/include/Graphs/SVFGOPT.h +++ b/include/Graphs/SVFGOPT.h @@ -261,23 +261,23 @@ class SVFGOPT : public SVFG { PAGNodeToDefMapTy::iterator it = PAGNodeToDefMap.find(pagNode); assert(it != PAGNodeToDefMap.end() && "a SVFIR node doesn't have definition before"); - PAGNodeToDefMap[pagNode] = node->getId(); + it->second = node->getId(); } /// Set def-site of actual-in/formal-out. ///@{ inline void setActualINDef(NodeID ai, NodeID def) { - NodeIDToNodeIDMap::const_iterator it = actualInToDefMap.find(ai); - assert(it == actualInToDefMap.end() && "can not set actual-in's def twice"); - actualInToDefMap[ai] = def; + bool inserted = actualInToDefMap.emplace(ai, def).second; + (void) inserted; // Make compiler happy + assert(inserted && "can not set actual-in's def twice"); defNodes.set(def); } inline void setFormalOUTDef(NodeID fo, NodeID def) { - NodeIDToNodeIDMap::const_iterator it = formalOutToDefMap.find(fo); - assert(it == formalOutToDefMap.end() && "can not set formal-out's def twice"); - formalOutToDefMap[fo] = def; + bool inserted = formalOutToDefMap.emplace(fo, def).second; + (void) inserted; + assert(inserted && "can not set formal-out's def twice"); defNodes.set(def); } ///@} diff --git a/include/Graphs/VFG.h b/include/Graphs/VFG.h index a3b860d78..3888e5480 100644 --- a/include/Graphs/VFG.h +++ b/include/Graphs/VFG.h @@ -340,8 +340,9 @@ class VFG : public GenericVFGTy { bool added1 = edge->getDstNode()->addIncomingEdge(edge); bool added2 = edge->getSrcNode()->addOutgoingEdge(edge); - assert(added1 && added2 && "edge not added??"); - return true; + bool both_added = added1 & added2; + assert(both_added && "VFGEdge not added??"); + return both_added; } protected: diff --git a/include/MSSA/MemSSA.h b/include/MSSA/MemSSA.h index f16223411..05df1696e 100644 --- a/include/MSSA/MemSSA.h +++ b/include/MSSA/MemSSA.h @@ -324,9 +324,9 @@ class MemSSA { if (const LoadStmt* load = SVFUtil::dyn_cast(inst)) { - assert(0 != load2MuSetMap.count(load) - && "not associated with mem region!"); - return true; + bool has_mu = load2MuSetMap.count(load) != 0; + assert(has_mu && "not associated with mem region!"); + return has_mu; } else return false; @@ -336,9 +336,9 @@ class MemSSA if (const StoreStmt* store = SVFUtil::dyn_cast( inst)) { - assert(0 != store2ChiSetMap.count(store) - && "not associated with mem region!"); - return true; + bool has_store = store2ChiSetMap.count(store) != 0; + assert(has_store && "not associated with mem region!"); + return has_store; } else return false; diff --git a/include/MemoryModel/PersistentPointsToDS.h b/include/MemoryModel/PersistentPointsToDS.h index df03515f1..be829830b 100644 --- a/include/MemoryModel/PersistentPointsToDS.h +++ b/include/MemoryModel/PersistentPointsToDS.h @@ -363,7 +363,7 @@ class PersistentDFPTData : public DFPTData virtual inline const KeySet& getRevPts(const Data&) override { assert(false && "PersistentDFPTData::getRevPts: not supported yet!"); - return *(KeySet*)nullptr; // suppress -Werror=return-type + abort(); } virtual inline bool unionPts(const Key& dstKey, const Key& srcKey) override diff --git a/include/MemoryModel/SVFIR.h b/include/MemoryModel/SVFIR.h index 5dd29e828..97cc13a10 100644 --- a/include/MemoryModel/SVFIR.h +++ b/include/MemoryModel/SVFIR.h @@ -456,6 +456,7 @@ class SVFIR : public IRGraph inline void addToStmt2TypeMap(SVFStmt* edge) { bool added = KindToSVFStmtSetMap[edge->getEdgeKind()].insert(edge).second; + (void) added; // Make compiler happy :) assert(added && "duplicated edge, not added!!!"); if (edge->isPTAEdge()) { @@ -494,7 +495,8 @@ class SVFIR : public IRGraph /// Add indirect callsites inline void addIndirectCallsites(const CallICFGNode* cs,NodeID funPtr) { - bool added = indCallSiteToFunPtrMap.insert(std::make_pair(cs,funPtr)).second; + bool added = indCallSiteToFunPtrMap.emplace(cs, funPtr).second; + (void) added; funPtrToCallSitesMap[funPtr].insert(cs); assert(added && "adding the same indirect callsite twice?"); } diff --git a/include/SABER/SaberCondAllocator.h b/include/SABER/SaberCondAllocator.h index 7028d379d..66162cb46 100644 --- a/include/SABER/SaberCondAllocator.h +++ b/include/SABER/SaberCondAllocator.h @@ -148,6 +148,7 @@ class SaberCondAllocator { const SVFFunction* keyFunc = LLVMModuleSet::getLLVMModuleSet()->getSVFFunction(bbKey->getParent()); const SVFFunction* valueFunc = LLVMModuleSet::getLLVMModuleSet()->getSVFFunction(bbValue->getParent()); + (void)(keyFunc == valueFunc); // make compiler happy assert((keyFunc == valueFunc) && "two basicblocks should be in the same function!"); return keyFunc->postDominate(bbKey,bbValue); @@ -157,6 +158,7 @@ class SaberCondAllocator { const SVFFunction* keyFunc = LLVMModuleSet::getLLVMModuleSet()->getSVFFunction(bbKey->getParent()); const SVFFunction* valueFunc = LLVMModuleSet::getLLVMModuleSet()->getSVFFunction(bbValue->getParent()); + (void)(keyFunc == valueFunc); // Make compiler happy assert((keyFunc == valueFunc) && "two basicblocks should be in the same function!"); return keyFunc->dominate(bbKey,bbValue); diff --git a/include/SVF-FE/IRAnnotator.h b/include/SVF-FE/IRAnnotator.h index fbf4bd047..ccc36310d 100644 --- a/include/SVF-FE/IRAnnotator.h +++ b/include/SVF-FE/IRAnnotator.h @@ -101,7 +101,9 @@ class IRAnnotator LocationSet locationSet = LocationSet(locationSetOffset); SVF::NodeID gepnodeId = pag->getGepObjVar(baseNodeId, locationSet); - assert(nodeId == gepnodeId && "nodeId != gepnodeId"); + bool idEq = nodeId == gepnodeId; + (void)idEq; // Make compiler happy + assert(idEq && "nodeId is not equal to gepnodeId?"); } } diff --git a/include/Util/SparseBitVector.h b/include/Util/SparseBitVector.h index 414007ca1..d51b1d605 100644 --- a/include/Util/SparseBitVector.h +++ b/include/Util/SparseBitVector.h @@ -321,6 +321,7 @@ template struct SparseBitVectorElement if (Bits[i] != 0) return i * BITWORD_SIZE + countTrailingZeros(Bits[i]); assert(false && "SBV: find_first: SBV cannot be empty"); + abort(); } /// find_last - Returns the index of the last set bit. @@ -334,6 +335,7 @@ template struct SparseBitVectorElement countLeadingZeros(Bits[Idx]) - 1; } assert(false && "SBV: find_last: SBV cannot be empty"); + abort(); } /// find_next - Returns the index of the next set bit starting from the diff --git a/lib/DDA/ContextDDA.cpp b/lib/DDA/ContextDDA.cpp index 6d27b8bce..4274d4672 100644 --- a/lib/DDA/ContextDDA.cpp +++ b/lib/DDA/ContextDDA.cpp @@ -335,22 +335,25 @@ bool ContextDDA::isHeapCondMemObj(const CxtVar& var, const StoreSVFGNode*) { const MemObj* mem = _pag->getObject(getPtrNodeID(var)); assert(mem && "memory object is null??"); - if(mem->isHeap()) + if (mem->isHeap()) { if (!mem->getValue()) { PAGNode *pnode = _pag->getGNode(getPtrNodeID(var)); - if(GepObjVar* gepobj = SVFUtil::dyn_cast(pnode)) + GepObjVar* gepobj = SVFUtil::dyn_cast(pnode); + if (gepobj != nullptr) { - assert(SVFUtil::isa(_pag->getGNode(gepobj->getBaseNode())) && "emtpy refVal in a gep object whose base is a non-dummy object"); + assert(SVFUtil::isa(_pag->getGNode(gepobj->getBaseNode())) + && "emtpy refVal in a gep object whose base is a non-dummy object"); } else { - assert((SVFUtil::isa(pnode) || SVFUtil::isa(pnode)) && "empty refVal in non-dummy object"); + assert((SVFUtil::isa(pnode) || SVFUtil::isa(pnode)) + && "empty refVal in non-dummy object"); } return true; } - else if(const Instruction* mallocSite = SVFUtil::dyn_cast(mem->getValue())) + else if (const Instruction* mallocSite = SVFUtil::dyn_cast(mem->getValue())) { const Function* fun = mallocSite->getFunction(); const SVFFunction* svfFun = LLVMModuleSet::getLLVMModuleSet()->getSVFFunction(fun); diff --git a/lib/Graphs/ConsG.cpp b/lib/Graphs/ConsG.cpp index c4fbe4e8b..e5cc71c0e 100644 --- a/lib/Graphs/ConsG.cpp +++ b/lib/Graphs/ConsG.cpp @@ -157,8 +157,11 @@ AddrCGEdge::AddrCGEdge(ConstraintNode* s, ConstraintNode* d, EdgeID id) { // Retarget addr edges may lead s to be a dummy node PAGNode* node = SVFIR::getPAG()->getGNode(s->getId()); + (void) node; // Make compiler happy if (!SVFModule::pagReadFromTXT()) + { assert(!SVFUtil::isa(node) && "a dummy node??"); + } } /*! @@ -168,11 +171,12 @@ AddrCGEdge* ConstraintGraph::addAddrCGEdge(NodeID src, NodeID dst) { ConstraintNode* srcNode = getConstraintNode(src); ConstraintNode* dstNode = getConstraintNode(dst); - if(hasEdge(srcNode,dstNode,ConstraintEdge::Addr)) + if (hasEdge(srcNode, dstNode, ConstraintEdge::Addr)) return nullptr; AddrCGEdge* edge = new AddrCGEdge(srcNode, dstNode, edgeIndex++); - bool added = AddrCGEdgeSet.insert(edge).second; - assert(added && "not added??"); + bool inserted = AddrCGEdgeSet.insert(edge).second; + (void)inserted; // Make compiler happy + assert(inserted && "new AddrCGEdge not added??"); srcNode->addOutgoingAddrEdge(edge); dstNode->addIncomingAddrEdge(edge); return edge; @@ -186,13 +190,13 @@ CopyCGEdge* ConstraintGraph::addCopyCGEdge(NodeID src, NodeID dst) ConstraintNode* srcNode = getConstraintNode(src); ConstraintNode* dstNode = getConstraintNode(dst); - if(hasEdge(srcNode,dstNode,ConstraintEdge::Copy) - || srcNode == dstNode) + if (hasEdge(srcNode, dstNode, ConstraintEdge::Copy) || srcNode == dstNode) return nullptr; CopyCGEdge* edge = new CopyCGEdge(srcNode, dstNode, edgeIndex++); - bool added = directEdgeSet.insert(edge).second; - assert(added && "not added??"); + bool inserted = directEdgeSet.insert(edge).second; + (void)inserted; // Make compiler happy + assert(inserted && "new CopyCGEdge not added??"); srcNode->addOutgoingCopyEdge(edge); dstNode->addIncomingCopyEdge(edge); return edge; @@ -206,12 +210,13 @@ NormalGepCGEdge* ConstraintGraph::addNormalGepCGEdge(NodeID src, NodeID dst, co { ConstraintNode* srcNode = getConstraintNode(src); ConstraintNode* dstNode = getConstraintNode(dst); - if(hasEdge(srcNode,dstNode,ConstraintEdge::NormalGep)) + if (hasEdge(srcNode, dstNode, ConstraintEdge::NormalGep)) return nullptr; NormalGepCGEdge* edge = new NormalGepCGEdge(srcNode, dstNode,ls, edgeIndex++); - bool added = directEdgeSet.insert(edge).second; - assert(added && "not added??"); + bool inserted = directEdgeSet.insert(edge).second; + (void)inserted; // Make compiler happy + assert(inserted && "new NormalGepCGEdge not added??"); srcNode->addOutgoingGepEdge(edge); dstNode->addIncomingGepEdge(edge); return edge; @@ -224,12 +229,13 @@ VariantGepCGEdge* ConstraintGraph::addVariantGepCGEdge(NodeID src, NodeID dst) { ConstraintNode* srcNode = getConstraintNode(src); ConstraintNode* dstNode = getConstraintNode(dst); - if(hasEdge(srcNode,dstNode,ConstraintEdge::VariantGep)) + if (hasEdge(srcNode, dstNode, ConstraintEdge::VariantGep)) return nullptr; VariantGepCGEdge* edge = new VariantGepCGEdge(srcNode, dstNode, edgeIndex++); - bool added = directEdgeSet.insert(edge).second; - assert(added && "not added??"); + bool inserted = directEdgeSet.insert(edge).second; + (void)inserted; // Make compiler happy + assert(inserted && "new VariantGepCGEdge not added??"); srcNode->addOutgoingGepEdge(edge); dstNode->addIncomingGepEdge(edge); return edge; @@ -242,12 +248,13 @@ LoadCGEdge* ConstraintGraph::addLoadCGEdge(NodeID src, NodeID dst) { ConstraintNode* srcNode = getConstraintNode(src); ConstraintNode* dstNode = getConstraintNode(dst); - if(hasEdge(srcNode,dstNode,ConstraintEdge::Load)) + if (hasEdge(srcNode, dstNode, ConstraintEdge::Load)) return nullptr; LoadCGEdge* edge = new LoadCGEdge(srcNode, dstNode, edgeIndex++); - bool added = LoadCGEdgeSet.insert(edge).second; - assert(added && "not added??"); + bool inserted = LoadCGEdgeSet.insert(edge).second; + (void)inserted; // Make compiler happy + assert(inserted && "new LoadCGEdge not added??"); srcNode->addOutgoingLoadEdge(edge); dstNode->addIncomingLoadEdge(edge); return edge; @@ -260,12 +267,13 @@ StoreCGEdge* ConstraintGraph::addStoreCGEdge(NodeID src, NodeID dst) { ConstraintNode* srcNode = getConstraintNode(src); ConstraintNode* dstNode = getConstraintNode(dst); - if(hasEdge(srcNode,dstNode,ConstraintEdge::Store)) + if (hasEdge(srcNode, dstNode, ConstraintEdge::Store)) return nullptr; StoreCGEdge* edge = new StoreCGEdge(srcNode, dstNode, edgeIndex++); - bool added = StoreCGEdgeSet.insert(edge).second; - assert(added && "not added??"); + bool inserted = StoreCGEdgeSet.insert(edge).second; + (void)inserted; // Make compiler happy + assert(inserted && "new StoreCGEdge not added??"); srcNode->addOutgoingStoreEdge(edge); dstNode->addIncomingStoreEdge(edge); return edge; @@ -369,8 +377,9 @@ void ConstraintGraph::removeAddrEdge(AddrCGEdge* edge) getConstraintNode(edge->getSrcID())->removeOutgoingAddrEdge(edge); getConstraintNode(edge->getDstID())->removeIncomingAddrEdge(edge); u32_t num = AddrCGEdgeSet.erase(edge); - delete edge; + (void) num; // make compiler happy assert(num && "edge not in the set, can not remove!!!"); + delete edge; } /*! @@ -381,8 +390,9 @@ void ConstraintGraph::removeLoadEdge(LoadCGEdge* edge) getConstraintNode(edge->getSrcID())->removeOutgoingLoadEdge(edge); getConstraintNode(edge->getDstID())->removeIncomingLoadEdge(edge); u32_t num = LoadCGEdgeSet.erase(edge); - delete edge; + (void) num; // make compiler happy assert(num && "edge not in the set, can not remove!!!"); + delete edge; } /*! @@ -393,8 +403,9 @@ void ConstraintGraph::removeStoreEdge(StoreCGEdge* edge) getConstraintNode(edge->getSrcID())->removeOutgoingStoreEdge(edge); getConstraintNode(edge->getDstID())->removeIncomingStoreEdge(edge); u32_t num = StoreCGEdgeSet.erase(edge); - delete edge; + (void) num; // make compiler happy assert(num && "edge not in the set, can not remove!!!"); + delete edge; } /*! @@ -406,7 +417,7 @@ void ConstraintGraph::removeDirectEdge(ConstraintEdge* edge) getConstraintNode(edge->getSrcID())->removeOutgoingDirectEdge(edge); getConstraintNode(edge->getDstID())->removeIncomingDirectEdge(edge); u32_t num = directEdgeSet.erase(edge); - + (void) num; // make compiler happy assert(num && "edge not in the set, can not remove!!!"); delete edge; } diff --git a/lib/Graphs/ICFG.cpp b/lib/Graphs/ICFG.cpp index 6724b3b87..3d349247c 100644 --- a/lib/Graphs/ICFG.cpp +++ b/lib/Graphs/ICFG.cpp @@ -364,7 +364,8 @@ ICFGEdge* ICFG::getICFGEdge(const ICFGNode* src, const ICFGNode* dst, ICFGEdge:: ICFGEdge* ICFG::addIntraEdge(ICFGNode* srcNode, ICFGNode* dstNode) { checkIntraEdgeParents(srcNode, dstNode); - if(ICFGEdge* edge = hasIntraICFGEdge(srcNode,dstNode, ICFGEdge::IntraCF)) + ICFGEdge* edge = hasIntraICFGEdge(srcNode, dstNode, ICFGEdge::IntraCF); + if (edge != nullptr) { assert(edge->isIntraCFGEdge() && "this should be an intra CFG edge!"); return nullptr; @@ -383,7 +384,8 @@ ICFGEdge* ICFG::addConditionalIntraEdge(ICFGNode* srcNode, ICFGNode* dstNode, co { checkIntraEdgeParents(srcNode, dstNode); - if(ICFGEdge* edge = hasIntraICFGEdge(srcNode,dstNode, ICFGEdge::IntraCF)) + ICFGEdge* edge = hasIntraICFGEdge(srcNode, dstNode, ICFGEdge::IntraCF); + if (edge != nullptr) { assert(edge->isIntraCFGEdge() && "this should be an intra CFG edge!"); return nullptr; @@ -402,7 +404,8 @@ ICFGEdge* ICFG::addConditionalIntraEdge(ICFGNode* srcNode, ICFGNode* dstNode, co */ ICFGEdge* ICFG::addCallEdge(ICFGNode* srcNode, ICFGNode* dstNode, const Instruction* cs) { - if(ICFGEdge* edge = hasInterICFGEdge(srcNode,dstNode, ICFGEdge::CallCF)) + ICFGEdge* edge = hasInterICFGEdge(srcNode,dstNode, ICFGEdge::CallCF); + if (edge != nullptr) { assert(edge->isCallCFGEdge() && "this should be a call CFG edge!"); return nullptr; @@ -419,7 +422,8 @@ ICFGEdge* ICFG::addCallEdge(ICFGNode* srcNode, ICFGNode* dstNode, const Instruct */ ICFGEdge* ICFG::addRetEdge(ICFGNode* srcNode, ICFGNode* dstNode, const Instruction* cs) { - if(ICFGEdge* edge = hasInterICFGEdge(srcNode,dstNode, ICFGEdge::RetCF)) + ICFGEdge* edge = hasInterICFGEdge(srcNode, dstNode, ICFGEdge::RetCF); + if (edge != nullptr) { assert(edge->isRetCFGEdge() && "this should be a return CFG edge!"); return nullptr; diff --git a/lib/Graphs/VFG.cpp b/lib/Graphs/VFG.cpp index 817e53d1d..859db8d90 100644 --- a/lib/Graphs/VFG.cpp +++ b/lib/Graphs/VFG.cpp @@ -677,7 +677,8 @@ VFGEdge* VFG::addIntraDirectVFEdge(NodeID srcId, NodeID dstId) VFGNode* srcNode = getVFGNode(srcId); VFGNode* dstNode = getVFGNode(dstId); checkIntraEdgeParents(srcNode, dstNode); - if(VFGEdge* edge = hasIntraVFGEdge(srcNode,dstNode, VFGEdge::IntraDirectVF)) + VFGEdge* edge = hasIntraVFGEdge(srcNode, dstNode, VFGEdge::IntraDirectVF); + if (edge != nullptr) { assert(edge->isDirectVFGEdge() && "this should be a direct value flow edge!"); return nullptr; @@ -701,7 +702,8 @@ VFGEdge* VFG::addCallEdge(NodeID srcId, NodeID dstId, CallSiteID csId) { VFGNode* srcNode = getVFGNode(srcId); VFGNode* dstNode = getVFGNode(dstId); - if(VFGEdge* edge = hasInterVFGEdge(srcNode,dstNode, VFGEdge::CallDirVF,csId)) + VFGEdge* edge = hasInterVFGEdge(srcNode, dstNode, VFGEdge::CallDirVF, csId); + if (edge != nullptr) { assert(edge->isCallDirectVFGEdge() && "this should be a direct value flow edge!"); return nullptr; @@ -720,7 +722,8 @@ VFGEdge* VFG::addRetEdge(NodeID srcId, NodeID dstId, CallSiteID csId) { VFGNode* srcNode = getVFGNode(srcId); VFGNode* dstNode = getVFGNode(dstId); - if(VFGEdge* edge = hasInterVFGEdge(srcNode,dstNode, VFGEdge::RetDirVF,csId)) + VFGEdge* edge = hasInterVFGEdge(srcNode, dstNode, VFGEdge::RetDirVF, csId); + if (edge != nullptr) { assert(edge->isRetDirectVFGEdge() && "this should be a direct value flow edge!"); return nullptr; diff --git a/lib/MSSA/MemRegion.cpp b/lib/MSSA/MemRegion.cpp index 890e3f976..cf170d2a5 100644 --- a/lib/MSSA/MemRegion.cpp +++ b/lib/MSSA/MemRegion.cpp @@ -562,6 +562,7 @@ void MRGenerator::getEscapObjviaGlobals(NodeBS& globs, const NodeBS& calleeModRe for(NodeBS::iterator it = calleeModRef.begin(), eit = calleeModRef.end(); it!=eit; ++it) { const MemObj* obj = pta->getPAG()->getObject(*it); + (void) obj; // Make compiler happy assert(obj && "object not found!!"); if(allGlobals.test(*it)) globs.set(*it); diff --git a/lib/MTA/TCT.cpp b/lib/MTA/TCT.cpp index f75aa8aad..663d655a7 100644 --- a/lib/MTA/TCT.cpp +++ b/lib/MTA/TCT.cpp @@ -661,6 +661,7 @@ struct DOTGraphTraits : public DefaultDOTGraphTraits { TCTEdge* edge = csThreadTree->getGraphEdge(node, *EI, TCTEdge::ThreadCreateEdge); + (void) edge; // Make compiler happy assert(edge && "No edge found!!"); /// black edge for direct call while two functions contain indirect calls will be label with red color return "color=black"; diff --git a/lib/MemoryModel/PointerAnalysisImpl.cpp b/lib/MemoryModel/PointerAnalysisImpl.cpp index 9ab4beb64..5eefb3674 100644 --- a/lib/MemoryModel/PointerAnalysisImpl.cpp +++ b/lib/MemoryModel/PointerAnalysisImpl.cpp @@ -322,7 +322,9 @@ bool BVDataPTAImpl::readFromFile(const string& filename) ss >> id >> base >> offset; NodeID n = pag->getGepObjVar(base, LocationSet(offset)); - assert(id == n && "Error adding GepObjNode into SVFIR!"); + bool matched = id == n; + (void) matched; + assert(matched && "Error adding GepObjNode into SVFIR!"); getline(F, line); } diff --git a/lib/SABER/SaberCondAllocator.cpp b/lib/SABER/SaberCondAllocator.cpp index 702ccc322..ac3c7df09 100644 --- a/lib/SABER/SaberCondAllocator.cpp +++ b/lib/SABER/SaberCondAllocator.cpp @@ -309,7 +309,9 @@ SaberCondAllocator::Condition SaberCondAllocator::evaluateBranchCond(const Basic { const BasicBlock *succ1 = branchStmt->getSuccessor(0)->getBB(); const BasicBlock *succ2 = branchStmt->getSuccessor(1)->getBB(); - assert((succ1 == succ || succ2 == succ) && "not a successor??"); + bool is_succ = succ1 == succ || succ2 == succ; + (void) is_succ; // Make compiler happy + assert(is_succ && "not a successor??"); Condition evalLoopExit = evaluateLoopExitBranch(bb, succ); if (!eq(evalLoopExit, Condition::nullExpr())) diff --git a/lib/SVF-FE/CHGBuilder.cpp b/lib/SVF-FE/CHGBuilder.cpp index 5dcebce79..c007f13ff 100644 --- a/lib/SVF-FE/CHGBuilder.cpp +++ b/lib/SVF-FE/CHGBuilder.cpp @@ -491,8 +491,8 @@ void CHGBuilder::analyzeVTables(const Module &M) else if (const ConstantExpr *aliasconst = SVFUtil::dyn_cast(aliasValue)) { - u32_t aliasopcode = aliasconst->getOpcode(); - assert(aliasopcode == Instruction::BitCast && + (void) aliasconst; // Make compiler happy + assert(aliasconst->getOpcode() == Instruction::BitCast && "aliased constantexpr in vtable not a bitcast"); const Function* aliasbitcastfunc = SVFUtil::dyn_cast(aliasconst->getOperand(0)); diff --git a/lib/SVF-FE/SVFIRBuilder.cpp b/lib/SVF-FE/SVFIRBuilder.cpp index 92daa5f71..9761d01af 100644 --- a/lib/SVF-FE/SVFIRBuilder.cpp +++ b/lib/SVF-FE/SVFIRBuilder.cpp @@ -621,7 +621,10 @@ void SVFIRBuilder::visitPHINode(PHINode &inst) { const Value* val = inst.getIncomingValue(i); const Instruction* incomingInst = SVFUtil::dyn_cast(val); - assert((incomingInst==nullptr) || (incomingInst->getFunction() == inst.getFunction())); + bool matched = incomingInst == nullptr || + incomingInst->getFunction() == inst.getFunction(); + (void)matched; // Make compiler happy + assert(matched && "incomingInst's Function incorrect"); const Instruction* predInst = &inst.getIncomingBlock(i)->back(); const ICFGNode* icfgNode = pag->getICFG()->getICFGNode(predInst); NodeID src = getValueNode(val); diff --git a/lib/WPA/AndersenSFR.cpp b/lib/WPA/AndersenSFR.cpp index ea3d270be..d4bc16100 100644 --- a/lib/WPA/AndersenSFR.cpp +++ b/lib/WPA/AndersenSFR.cpp @@ -139,7 +139,10 @@ void AndersenSFR::fieldExpand(NodeSet& initials, s32_t offset, NodeBS& strides, else if (SVFUtil::isa(initPN) || SVFUtil::isa(initPN)) initOffset = 0; else + { assert(false && "Not an object node!!"); + initOffset = 0; + } Set offsets; offsets.insert(offset); diff --git a/lib/WPA/TypeAnalysis.cpp b/lib/WPA/TypeAnalysis.cpp index af5a6c4f9..e984dc373 100644 --- a/lib/WPA/TypeAnalysis.cpp +++ b/lib/WPA/TypeAnalysis.cpp @@ -85,6 +85,7 @@ void TypeAnalysis::callGraphSolveBasedOnCHA(const CallSiteToFunPtrMap& callsites { virtualCallSites.insert(cs); const Value *vtbl = getVCallVtblPtr(cs); + (void) vtbl; // Make compiler happy assert(pag->hasValueNode(vtbl)); VFunSet vfns; getVFnsFromCHA(cbn, vfns); diff --git a/setup.sh b/setup.sh index a6b52f6a3..02ea731ef 100755 --- a/setup.sh +++ b/setup.sh @@ -18,7 +18,7 @@ function set_llvm { [ -n "$LLVM_DIR" ] && return 0 # use local download directory - LLVM_DIR="$SVF_DIR/llvm-13.0.0.obj" + LLVM_DIR="$SVF_DIR/llvm-15.0.0.obj" [ -d "$LLVM_DIR" ] && return 0 # ... otherwise don't set LLVM_DIR @@ -57,12 +57,12 @@ fi ######### #export PATH FOR SVF and LLVM executables ######### -if [[ $1 == 'debug' ]] -then -PTAOBJTY='Debug' +if [[ $1 =~ ^[Dd]ebug ]]; then + PTAOBJTY='Debug' else -PTAOBJTY='Release' + PTAOBJTY='Release' fi + Build=$PTAOBJTY'-build' export PATH=$LLVM_DIR/bin:$PATH