From 54415ade314ec4d352ecca621f5a2fb3daa3665b Mon Sep 17 00:00:00 2001 From: Jared Carlson Date: Tue, 28 Mar 2017 17:30:57 -0400 Subject: [PATCH 01/17] Starting to move this into 4.0; likely with some errors, but it looks like so far it's line and file information, i.e diagnostic so.. --- lib/Util/AnalysisUtil.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/Util/AnalysisUtil.cpp b/lib/Util/AnalysisUtil.cpp index 81322ebd0..be6d5faed 100644 --- a/lib/Util/AnalysisUtil.cpp +++ b/lib/Util/AnalysisUtil.cpp @@ -255,9 +255,16 @@ std::string analysisUtil::getSourceLocOfFunction(const llvm::Function *F) raw_string_ostream rawstr(str); NamedMDNode* CU_Nodes = F->getParent()->getNamedMetadata("llvm.dbg.cu"); if(CU_Nodes) { + /* + * Looks like the DICompileUnt->getSubprogram was moved into Function:: + */ for (unsigned i = 0, e = CU_Nodes->getNumOperands(); i != e; ++i) { DICompileUnit *CUNode = cast(CU_Nodes->getOperand(i)); - for (DISubprogram *SP : CUNode->getSubprograms()) { + /* + * https://reviews.llvm.org/D18074?id=50385 + * looks like the relevant + */ + if (DISubprogram *SP = F->getSubprogram()) { if (SP->describes(F)) rawstr << "in line: " << SP->getLine() << " file: " << SP->getFilename(); @@ -309,9 +316,11 @@ std::string analysisUtil::getSourceLoc(const Value* val) { if(CU_Nodes) { for (unsigned i = 0, e = CU_Nodes->getNumOperands(); i != e; ++i) { DICompileUnit *CUNode = cast(CU_Nodes->getOperand(i)); - for (DIGlobalVariable *GV : CUNode->getGlobalVariables()) { - if (gvar == GV->getVariable()) - rawstr << "ln: " << GV->getLine() << " fl: " << GV->getFilename(); + for (DIGlobalVariableExpression *GV : CUNode->getGlobalVariables()) { + DIGlobalVariable * DGV = GV->getVariable(); + const GlobalVariable *CDGV = dyn_cast(DGV); + if ( gvar == CDGV ) + rawstr << "ln: " << DGV->getLine() << " fl: " << DGV->getFilename(); } } } From 73f69af3c13234e327f3c8ae1aca89ec62c439c8 Mon Sep 17 00:00:00 2001 From: Jared Carlson Date: Tue, 28 Mar 2017 19:08:42 -0400 Subject: [PATCH 02/17] A few compilation fixes, the dataflow looks reasonable while the analysisUtil looks more like I might miss some diagnostic info --- include/Util/DataFlowUtil.h | 9 +++++---- lib/Util/AnalysisUtil.cpp | 6 ++++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/include/Util/DataFlowUtil.h b/include/Util/DataFlowUtil.h index cc36c1a78..a91b74446 100644 --- a/include/Util/DataFlowUtil.h +++ b/include/Util/DataFlowUtil.h @@ -174,10 +174,11 @@ class PTACFInfoBuilder { llvm::Function* fun = const_cast(f); FunToPostDTMap::iterator it = funToPDTMap.find(fun); if(it==funToPDTMap.end()) { - llvm::PostDominatorTree* postDT = new llvm::PostDominatorTree(); + llvm::PostDominatorTreeWrapperPass* postDT = new llvm::PostDominatorTreeWrapperPass(); postDT->runOnFunction(*fun); - funToPDTMap[fun] = postDT; - return postDT; + llvm::PostDominatorTree * PDT = &(postDT->getPostDomTree()); + funToPDTMap[fun] = PDT; + return PDT; } else return it->second; @@ -225,7 +226,7 @@ class IteratedDominanceFrontier: public llvm::DominanceFrontierBase(); + // AU.addRequired(); } // virtual bool runOnFunction(llvm::Function &m) { diff --git a/lib/Util/AnalysisUtil.cpp b/lib/Util/AnalysisUtil.cpp index be6d5faed..5535f6a3e 100644 --- a/lib/Util/AnalysisUtil.cpp +++ b/lib/Util/AnalysisUtil.cpp @@ -318,9 +318,11 @@ std::string analysisUtil::getSourceLoc(const Value* val) { DICompileUnit *CUNode = cast(CU_Nodes->getOperand(i)); for (DIGlobalVariableExpression *GV : CUNode->getGlobalVariables()) { DIGlobalVariable * DGV = GV->getVariable(); - const GlobalVariable *CDGV = dyn_cast(DGV); - if ( gvar == CDGV ) + + /* + if ( gvar == DGV ) rawstr << "ln: " << DGV->getLine() << " fl: " << DGV->getFilename(); + */ } } } From ea5c7d48a01ee86018141b48db0a9ce997b2ef17 Mon Sep 17 00:00:00 2001 From: Jared Carlson Date: Mon, 3 Apr 2017 13:09:36 -0400 Subject: [PATCH 03/17] I think I almost have the specializations right for the PTACallgraph --- .gitignore | 1 + include/Util/GraphUtil.h | 7 ++++--- include/Util/PTACallGraph.h | 5 +++++ include/Util/SCC.h | 2 +- include/WPA/WPASolver.h | 2 +- 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 844f28b45..4f821a880 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ Release/ Debug/ build/ +build-master/ html/ Release+Asserts/ Debug+Asserts/ diff --git a/include/Util/GraphUtil.h b/include/Util/GraphUtil.h index 7d2f11f65..95b8bfb08 100644 --- a/include/Util/GraphUtil.h +++ b/include/Util/GraphUtil.h @@ -33,7 +33,7 @@ #include // for debug #include // for Graphtraits #include -#include // for tool output file +#include // for tool output file #include // for graph write #include // for file open flag @@ -82,7 +82,8 @@ class GraphPrinter { const GraphType >) { ///Define the GTraits and node iterator for printing typedef GraphTraits GTraits; - typedef typename GTraits::NodeType NodeType; + + typedef typename GTraits::NodeRef NodeRef; typedef typename GTraits::nodes_iterator node_iterator; typedef typename GTraits::ChildIteratorType child_iterator; @@ -91,7 +92,7 @@ class GraphPrinter { node_iterator I = GTraits::nodes_begin(GT); node_iterator E = GTraits::nodes_end(GT); for (; I != E; ++I) { - NodeType *Node = *I; + NodeRef *Node = *I; O << "node :" << Node << "'\n"; child_iterator EI = GTraits::child_begin(Node); child_iterator EE = GTraits::child_end(Node); diff --git a/include/Util/PTACallGraph.h b/include/Util/PTACallGraph.h index 460d4f47e..fbaebbf3f 100644 --- a/include/Util/PTACallGraph.h +++ b/include/Util/PTACallGraph.h @@ -57,6 +57,8 @@ class PTACallGraphEdge : public GenericCallGraphEdgeTy { enum CEDGEK { CallRetEdge,TDForkEdge,TDJoinEdge,HareParForEdge }; + + private: CallInstSet directCalls; CallInstSet indirectCalls; @@ -216,6 +218,7 @@ class PTACallGraph : public GenericCallGraphTy { destroy(); } + /// Get callees from an indirect callsite //@{ inline CallEdgeMap& getIndCallMap() { @@ -368,8 +371,10 @@ struct GraphTraits > : public GraphTraits struct GraphTraits : public GraphTraits* > { + typedef PTACallGraph *NodeRef; }; + } diff --git a/include/Util/SCC.h b/include/Util/SCC.h index 46809b530..af30cd3a6 100644 --- a/include/Util/SCC.h +++ b/include/Util/SCC.h @@ -55,7 +55,7 @@ class SCCDetection { private: ///Define the GTraits and node iterator for printing typedef llvm::GraphTraits GTraits; - typedef typename GTraits::NodeType GNODE; + typedef typename GTraits::NodeRef GNODE; typedef typename GTraits::nodes_iterator node_iterator; typedef typename GTraits::ChildIteratorType child_iterator; typedef unsigned NodeID ; diff --git a/include/WPA/WPASolver.h b/include/WPA/WPASolver.h index db625bb49..0af1c4362 100644 --- a/include/WPA/WPASolver.h +++ b/include/WPA/WPASolver.h @@ -43,7 +43,7 @@ class WPASolver { public: ///Define the GTraits and node iterator for printing typedef llvm::GraphTraits GTraits; - typedef typename GTraits::NodeType GNODE; + typedef typename GTraits::NodeRef GNODE; typedef typename GTraits::EdgeType GEDGE; typedef typename GTraits::ChildIteratorType child_iterator; From 9abbd5694095cf7679ecc9604a09dac997d6cb96 Mon Sep 17 00:00:00 2001 From: Jared Carlson Date: Mon, 3 Apr 2017 15:10:50 -0400 Subject: [PATCH 04/17] Ok, fixed the PTACallGraph graph trait issue - at least for compilation --- include/Util/PTACallGraph.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/Util/PTACallGraph.h b/include/Util/PTACallGraph.h index fbaebbf3f..ff9c1d196 100644 --- a/include/Util/PTACallGraph.h +++ b/include/Util/PTACallGraph.h @@ -371,7 +371,7 @@ struct GraphTraits > : public GraphTraits struct GraphTraits : public GraphTraits* > { - typedef PTACallGraph *NodeRef; + typedef PTACallGraphNode *NodeRef; }; From fdab9cd6fdc709d133336b84f5ec5b61621702a8 Mon Sep 17 00:00:00 2001 From: Jared Carlson Date: Tue, 4 Apr 2017 08:58:51 -0400 Subject: [PATCH 05/17] Fixed the SVFG Noderef issue, but looks like I need to clear the X** vs X* in the node references, but let me take a look at this before rushing right in (I can do that this afternoon) --- include/MSSA/SVFG.h | 1 + include/MSSA/SVFGBuilder.h | 2 +- include/MemoryModel/ConsG.h | 1 + include/MemoryModel/PAGNode.h | 4 ++-- include/WPA/FlowSensitive.h | 1 + 5 files changed, 6 insertions(+), 3 deletions(-) diff --git a/include/MSSA/SVFG.h b/include/MSSA/SVFG.h index 9626166ef..55e56aeef 100644 --- a/include/MSSA/SVFG.h +++ b/include/MSSA/SVFG.h @@ -633,6 +633,7 @@ struct GraphTraits > : public GraphTraits struct GraphTraits : public GraphTraits* > { + typedef SVFGNode *NodeRef; }; } diff --git a/include/MSSA/SVFGBuilder.h b/include/MSSA/SVFGBuilder.h index 82b061011..ccbb9a7e7 100644 --- a/include/MSSA/SVFGBuilder.h +++ b/include/MSSA/SVFGBuilder.h @@ -43,7 +43,7 @@ class MemSSADF : public llvm::DominanceFrontier { bool runOnDT(llvm::DominatorTree& dt) { releaseMemory(); - getBase().analyze(dt); + analyze(dt); return false; } }; diff --git a/include/MemoryModel/ConsG.h b/include/MemoryModel/ConsG.h index f749322af..8771c963f 100644 --- a/include/MemoryModel/ConsG.h +++ b/include/MemoryModel/ConsG.h @@ -314,6 +314,7 @@ struct GraphTraits > : public GraphTraits struct GraphTraits : public GraphTraits* > { + typedef ConstraintNode *NodeRef; }; } diff --git a/include/MemoryModel/PAGNode.h b/include/MemoryModel/PAGNode.h index 81cf94dc0..072ab9f30 100644 --- a/include/MemoryModel/PAGNode.h +++ b/include/MemoryModel/PAGNode.h @@ -341,8 +341,8 @@ class GepValPN: public ValPN { /// Return name of a LLVM value const std::string getValueName() { if (value && value->hasName()) - return value->getName().str() + "_" + llvm::utostr_32(getOffset()); - return "offset_" + llvm::utostr_32(getOffset()); + return value->getName().str() + "_" + llvm::utostr(getOffset()); + return "offset_" + llvm::utostr(getOffset()); } const llvm::Type *getType() const { diff --git a/include/WPA/FlowSensitive.h b/include/WPA/FlowSensitive.h index dee9edbcd..61f3656ca 100644 --- a/include/WPA/FlowSensitive.h +++ b/include/WPA/FlowSensitive.h @@ -39,6 +39,7 @@ class AndersenWaveDiff; * Flow sensitive whole program pointer analysis */ typedef WPAFSSolver WPASVFGFSSolver; + class FlowSensitive : public WPASVFGFSSolver, public BVDataPTAImpl { friend class FlowSensitiveStat; private: From ef3bb89af62b885478dd5fcc7f535ba426a2cea9 Mon Sep 17 00:00:00 2001 From: Jared Carlson Date: Tue, 4 Apr 2017 14:10:08 -0400 Subject: [PATCH 06/17] Had to clean up where I was, should be moving forward again, needs clarification of pointers or double pointers in WPASolver --- include/MemoryModel/ConsG.h | 2 +- include/Util/SCC.h | 4 ++-- include/WPA/FlowSensitive.h | 1 - 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/include/MemoryModel/ConsG.h b/include/MemoryModel/ConsG.h index 8771c963f..a07696b57 100644 --- a/include/MemoryModel/ConsG.h +++ b/include/MemoryModel/ConsG.h @@ -314,7 +314,7 @@ struct GraphTraits > : public GraphTraits struct GraphTraits : public GraphTraits* > { - typedef ConstraintNode *NodeRef; + typedef ConstraintNode *NodeRef; }; } diff --git a/include/Util/SCC.h b/include/Util/SCC.h index af30cd3a6..5ab062f24 100644 --- a/include/Util/SCC.h +++ b/include/Util/SCC.h @@ -207,11 +207,11 @@ class SCCDetection { return _NodeSCCAuxInfo[n].inSCC(); } - inline GNODE* Node(NodeID id) const { + inline GNODE Node(NodeID id) const { return GTraits::getNode(_graph, id); } - inline NodeID Node_Index(GNODE* node) const { + inline NodeID Node_Index(GNODE node) const { return GTraits::getNodeID(node); } diff --git a/include/WPA/FlowSensitive.h b/include/WPA/FlowSensitive.h index 61f3656ca..dee9edbcd 100644 --- a/include/WPA/FlowSensitive.h +++ b/include/WPA/FlowSensitive.h @@ -39,7 +39,6 @@ class AndersenWaveDiff; * Flow sensitive whole program pointer analysis */ typedef WPAFSSolver WPASVFGFSSolver; - class FlowSensitive : public WPASVFGFSSolver, public BVDataPTAImpl { friend class FlowSensitiveStat; private: From b62082f3e7e0730cf713a1774bb817404754b1d7 Mon Sep 17 00:00:00 2001 From: Jared Carlson Date: Tue, 4 Apr 2017 16:05:48 -0400 Subject: [PATCH 07/17] Have an iterator conflict but if I can get past that looks like I'm making hey --- include/WPA/WPASolver.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/WPA/WPASolver.h b/include/WPA/WPASolver.h index 0af1c4362..4c44379b4 100644 --- a/include/WPA/WPASolver.h +++ b/include/WPA/WPASolver.h @@ -122,11 +122,11 @@ class WPASolver { /// Propagation for the solving, to be implemented in the child class virtual void propagate(GNODE* v) { - child_iterator EI = GTraits::direct_child_begin(v); - child_iterator EE = GTraits::direct_child_end(v); + child_iterator EI = GTraits::direct_child_begin(*v); + child_iterator EE = GTraits::direct_child_end(*v); for (; EI != EE; ++EI) { if (propFromSrcToDst(*(EI.getCurrent()))) - pushIntoWorklist(Node_Index(*EI)); + pushIntoWorklist(Node_Index(EI)); } } /// Propagate information from source to destination node, to be implemented in the child class @@ -163,7 +163,7 @@ class WPASolver { /// Get node ID inline NodeID Node_Index(GNODE* node) { - return GTraits::getNodeID(node); + return GTraits::getNodeID(*node); } private: From cab36c2665afe11df338cd02888788b29db79774 Mon Sep 17 00:00:00 2001 From: Jared Carlson Date: Wed, 5 Apr 2017 08:43:50 -0400 Subject: [PATCH 08/17] Fixed that iterator mismatch by changing the GNODE type in WPASolver.h --- include/WPA/WPASolver.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/WPA/WPASolver.h b/include/WPA/WPASolver.h index 4c44379b4..0b19c18c6 100644 --- a/include/WPA/WPASolver.h +++ b/include/WPA/WPASolver.h @@ -6,7 +6,7 @@ // Copyright (C) <2013-2016> // This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by +// it under the terms of the GNU Gg12eneral Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. @@ -126,7 +126,7 @@ class WPASolver { child_iterator EE = GTraits::direct_child_end(*v); for (; EI != EE; ++EI) { if (propFromSrcToDst(*(EI.getCurrent()))) - pushIntoWorklist(Node_Index(EI)); + pushIntoWorklist(Node_Index(*EI)); } } /// Propagate information from source to destination node, to be implemented in the child class @@ -162,8 +162,8 @@ class WPASolver { } /// Get node ID - inline NodeID Node_Index(GNODE* node) { - return GTraits::getNodeID(*node); + inline NodeID Node_Index(GNODE node) { + return GTraits::getNodeID(node); } private: From af491dca76cecd0d6c30518ea21bd33ad241753b Mon Sep 17 00:00:00 2001 From: Jared Carlson Date: Wed, 5 Apr 2017 09:21:24 -0400 Subject: [PATCH 09/17] Fixed const char to StringRef in the getPassName() of BreakConstantExpr --- include/Util/BreakConstantExpr.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/Util/BreakConstantExpr.h b/include/Util/BreakConstantExpr.h index 042a11600..2eb86a5fc 100644 --- a/include/Util/BreakConstantExpr.h +++ b/include/Util/BreakConstantExpr.h @@ -36,7 +36,7 @@ class BreakConstantGEPs : public llvm::ModulePass { public: static char ID; BreakConstantGEPs() : ModulePass(ID) {} - const char *getPassName() const { + llvm::StringRef getPassName() const { return "Remove Constant GEP Expressions"; } virtual bool runOnModule (llvm::Module & M); @@ -62,7 +62,7 @@ class MergeFunctionRets : public llvm::ModulePass { public: static char ID; MergeFunctionRets() : ModulePass(ID) {} - const char *getPassName() const { + llvm::StringRef getPassName() const { return "unify function exit into one dummy exit basic block"; } virtual bool runOnModule (llvm::Module & M) { From 5fbd66bfa70014185f277c6cd364af5b4bf078b4 Mon Sep 17 00:00:00 2001 From: Jared Carlson Date: Wed, 5 Apr 2017 16:33:23 -0400 Subject: [PATCH 10/17] A number of small fixes, mostly replacing const char* with llvm::StringRef, inserting a few NodeRef, etc, and now compiling a fair amount of the project, but still more to go... --- include/MemoryModel/CHA.h | 1 + include/MemoryModel/PAG.h | 1 + include/SABER/DoubleFreeChecker.h | 2 +- include/SABER/FileChecker.h | 2 +- include/SABER/LeakChecker.h | 2 +- lib/MemoryModel/LocMemModel.cpp | 10 +++++----- lib/MemoryModel/MemModel.cpp | 6 +++--- 7 files changed, 13 insertions(+), 11 deletions(-) diff --git a/include/MemoryModel/CHA.h b/include/MemoryModel/CHA.h index ac109ec2e..d3c7d7c13 100644 --- a/include/MemoryModel/CHA.h +++ b/include/MemoryModel/CHA.h @@ -249,6 +249,7 @@ struct GraphTraits > : public GraphTraits struct GraphTraits : public GraphTraits* > { + typedef CHNode *NodeRef; }; } diff --git a/include/MemoryModel/PAG.h b/include/MemoryModel/PAG.h index d5b449aa6..6a606a9e9 100644 --- a/include/MemoryModel/PAG.h +++ b/include/MemoryModel/PAG.h @@ -678,6 +678,7 @@ template<> struct GraphTraits > : public GraphTraits struct GraphTraits : public GraphTraits* > { + typedef PAGNode *NodeRef; }; } #endif /* PAG_H_ */ diff --git a/include/SABER/DoubleFreeChecker.h b/include/SABER/DoubleFreeChecker.h index c529d1425..7a667b789 100644 --- a/include/SABER/DoubleFreeChecker.h +++ b/include/SABER/DoubleFreeChecker.h @@ -58,7 +58,7 @@ class DoubleFreeChecker : public LeakChecker { } /// Get pass name - virtual const char* getPassName() const { + virtual llvm::StringRef getPassName() const { return "Double Free Analysis"; } diff --git a/include/SABER/FileChecker.h b/include/SABER/FileChecker.h index ec56fee10..4efc268fb 100644 --- a/include/SABER/FileChecker.h +++ b/include/SABER/FileChecker.h @@ -59,7 +59,7 @@ class FileChecker : public LeakChecker { } /// Get pass name - virtual const char* getPassName() const { + virtual llvm::StringRef getPassName() const { return "File Open/Close Analysis"; } diff --git a/include/SABER/LeakChecker.h b/include/SABER/LeakChecker.h index 92598cd66..7a0c27ab8 100644 --- a/include/SABER/LeakChecker.h +++ b/include/SABER/LeakChecker.h @@ -69,7 +69,7 @@ class LeakChecker : public SrcSnkDDA, public llvm::ModulePass { } /// Get pass name - virtual const char* getPassName() const { + virtual llvm::StringRef getPassName() const { return "Static Memory Leak Analysis"; } diff --git a/lib/MemoryModel/LocMemModel.cpp b/lib/MemoryModel/LocMemModel.cpp index 0aaac4a9b..ccb15055c 100644 --- a/lib/MemoryModel/LocMemModel.cpp +++ b/lib/MemoryModel/LocMemModel.cpp @@ -60,7 +60,7 @@ bool LocSymTableInfo::computeGepOffset(const llvm::User *V, LocationSet& ls) { if (index <= baseIndex) { /// variant offset // Handling pointer types - if (const PointerType* pty = dyn_cast(*gi)) { + if (const PointerType* pty = dyn_cast(gi.getIndexedType())) { const Type* et = pty->getElementType(); Size_t sz = getTypeSizeInBytes(et); @@ -73,7 +73,7 @@ bool LocSymTableInfo::computeGepOffset(const llvm::User *V, LocationSet& ls) { ls.addElemNumStridePair(std::make_pair(num, sz)); } // Calculate the size of the array element - else if(const ArrayType* at = dyn_cast(*gi)) { + else if(const ArrayType* at = dyn_cast(gi.getIndexedType())) { const Type* et = at->getElementType(); Size_t sz = getTypeSizeInBytes(et); Size_t num = at->getNumElements(); @@ -94,19 +94,19 @@ bool LocSymTableInfo::computeGepOffset(const llvm::User *V, LocationSet& ls) { // Handling pointer types // These GEP instructions are simply making address computations from the base pointer address // e.g. idx1 = (char*) &MyVar + 4, at this case gep only one offset index (idx) - if (const PointerType* pty = dyn_cast(*gi)) { + if (const PointerType* pty = dyn_cast(gi.getIndexedType())) { const Type* et = pty->getElementType(); Size_t sz = getTypeSizeInBytes(et); ls.offset += idx * sz; } // Calculate the size of the array element - else if(const ArrayType* at = dyn_cast(*gi)) { + else if(const ArrayType* at = dyn_cast(gi.getIndexedType())) { const Type* et = at->getElementType(); Size_t sz = getTypeSizeInBytes(et); ls.offset += idx * sz; } // Handling struct here - else if (const StructType *ST = dyn_cast(*gi)) { + else if (const StructType *ST = gi.getStructTypeOrNull() ) { assert(op && "non-const struct index in GEP"); const vector &so = SymbolTableInfo::Symbolnfo()->getStructOffsetVec(ST); if ((unsigned)idx >= so.size()) { diff --git a/lib/MemoryModel/MemModel.cpp b/lib/MemoryModel/MemModel.cpp index 1b0a24212..0c534ffde 100644 --- a/lib/MemoryModel/MemModel.cpp +++ b/lib/MemoryModel/MemModel.cpp @@ -189,7 +189,7 @@ bool SymbolTableInfo::computeGepOffset(const llvm::User *V, LocationSet& ls) { // Handling array types, skipe array handling here // We treat whole array as one, then we can distinguish different field of an array of struct // e.g. s[1].f1 is differet from s[0].f2 - if(isa(*gi)) + if(isa(gi.getIndexedType())) continue; @@ -209,7 +209,7 @@ bool SymbolTableInfo::computeGepOffset(const llvm::User *V, LocationSet& ls) { // These GEP instructions are simply making address computations from the base pointer address // e.g. idx1 = (char*) &MyVar + 4, at this case gep only one offset index (idx) - if (isa(*gi)) { + if (isa(gi.getIndexedType())) { // If this is a pointer, we're likely accessing an array through this pointer. // idx gives the array index of which element is being accessed. But since this // is a field-index based memory model, we consider array as containing one @@ -222,7 +222,7 @@ bool SymbolTableInfo::computeGepOffset(const llvm::User *V, LocationSet& ls) { // Handling struct here - if (const StructType *ST = dyn_cast(*gi)) { + if (const StructType *ST = gi.getStructTypeOrNull()) { assert(op && "non-const struct index in GEP"); const vector &so = SymbolTableInfo::Symbolnfo()->getStructOffsetVec(ST); if ((unsigned)idx >= so.size()) { From de31c2726d0951a4919b82cccc33f0154c49c6df Mon Sep 17 00:00:00 2001 From: Jared Carlson Date: Thu, 6 Apr 2017 10:38:12 -0400 Subject: [PATCH 11/17] Couple trivial fixes, more StringRef and a ref to pointer --- include/WPA/WPAPass.h | 2 +- lib/WPA/FlowSensitive.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/WPA/WPAPass.h b/include/WPA/WPAPass.h index ab081f33c..ff1a93a2b 100644 --- a/include/WPA/WPAPass.h +++ b/include/WPA/WPAPass.h @@ -88,7 +88,7 @@ class WPAPass: public llvm::ModulePass, public llvm::AliasAnalysis { virtual bool runOnModule(llvm::Module& module); /// PTA name - virtual inline const char* getPassName() const { + virtual inline llvm::StringRef getPassName() const { return "WPAPass"; } diff --git a/lib/WPA/FlowSensitive.cpp b/lib/WPA/FlowSensitive.cpp index a85339bf5..71a75f2a3 100644 --- a/lib/WPA/FlowSensitive.cpp +++ b/lib/WPA/FlowSensitive.cpp @@ -126,7 +126,7 @@ NodeStack& FlowSensitive::SCCDetect() void FlowSensitive::processNode(NodeID nodeId) { SVFGNode* node = svfg->getSVFGNode(nodeId); if (processSVFGNode(node)) - propagate(node); + propagate(&node); clearAllDFOutVarFlag(node); } From 7b7e39dbd59685b03aacb0384df7649d7767a165 Mon Sep 17 00:00:00 2001 From: Jared Carlson Date: Thu, 6 Apr 2017 16:19:36 -0400 Subject: [PATCH 12/17] Starting to compile actual products but linkage errors likely indicate some new virtual methods in 4.0 aren't implemented... --- include/WPA/WPAPass.h | 11 ++++++++--- lib/WPA/WPAPass.cpp | 8 ++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/include/WPA/WPAPass.h b/include/WPA/WPAPass.h index ff1a93a2b..e770c2d1f 100644 --- a/include/WPA/WPAPass.h +++ b/include/WPA/WPAPass.h @@ -39,6 +39,7 @@ #include "MemoryModel/PointerAnalysis.h" #include +#include #include @@ -46,7 +47,9 @@ * Whole program pointer analysis. * This class performs various pointer analysis on the given module. */ -class WPAPass: public llvm::ModulePass, public llvm::AliasAnalysis { +// excised ", public llvm::AliasAnalysis" as that has a very light interface +// and I want to see what breaks. +class WPAPass: public llvm::ModulePass { typedef std::vector PTAVector; public: @@ -59,8 +62,10 @@ class WPAPass: public llvm::ModulePass, public llvm::AliasAnalysis { Precise ///< return alias result by the most precise pta }; - /// Constructor - WPAPass() : llvm::ModulePass(ID), llvm::AliasAnalysis() {} + /// Constructor needs TargetLibraryInfo to be passed to the AliasAnalysis + WPAPass() : llvm::ModulePass(ID) { + + } /// Destructor ~WPAPass(); diff --git a/lib/WPA/WPAPass.cpp b/lib/WPA/WPAPass.cpp index 789d6856a..119acce89 100644 --- a/lib/WPA/WPAPass.cpp +++ b/lib/WPA/WPAPass.cpp @@ -55,15 +55,15 @@ static cl::bits PASelected(cl::desc("Select pointer anal clEnumValN(PointerAnalysis::AndersenLCD_WPA, "lander", "Lazy cycle detection inclusion-based analysis"), clEnumValN(PointerAnalysis::AndersenWave_WPA, "wander", "Wave propagation inclusion-based analysis"), clEnumValN(PointerAnalysis::AndersenWaveDiff_WPA, "ander", "Diff wave propagation inclusion-based analysis"), - clEnumValN(PointerAnalysis::FSSPARSE_WPA, "fspta", "Sparse flow sensitive pointer analysis"), - clEnumValEnd)); + clEnumValN(PointerAnalysis::FSSPARSE_WPA, "fspta", "Sparse flow sensitive pointer analysis") + )); static cl::bits AliasRule(cl::desc("Select alias check rule"), cl::values( clEnumValN(WPAPass::Conservative, "conservative", "return MayAlias if any pta says alias"), - clEnumValN(WPAPass::Veto, "veto", "return NoAlias if any pta says no alias"), - clEnumValEnd)); + clEnumValN(WPAPass::Veto, "veto", "return NoAlias if any pta says no alias") + )); cl::opt StoreAnder("store-ander", cl::init(false), cl::desc("Store Andersen's analysis result to a file")); From 837d2d2d8ac1adab1b15d36ee6886ca0d8cda90c Mon Sep 17 00:00:00 2001 From: Jared Carlson Date: Thu, 13 Apr 2017 17:40:17 -0400 Subject: [PATCH 13/17] 1% more to go... --- lib/CMakeLists.txt | 3 ++- tools/WPA/CMakeLists.txt | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 70ad9fe5f..fa1eef152 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -50,7 +50,8 @@ set(SOURCES add_llvm_loadable_module(Svf ${SOURCES}) add_llvm_Library(LLVMSvf ${SOURCES}) - +llvm_map_components_to_libnames(llvm_libs bitwriter core ipo irreader instcombine instrumentation target linker analysis scalaropts support ) +target_link_libraries(LLVMSvf ${llvm_libs}) if(DEFINED IN_SOURCE_BUILD) add_dependencies(Svf intrinsics_gen) diff --git a/tools/WPA/CMakeLists.txt b/tools/WPA/CMakeLists.txt index a95cff5c8..5c30565fd 100644 --- a/tools/WPA/CMakeLists.txt +++ b/tools/WPA/CMakeLists.txt @@ -3,7 +3,7 @@ if(DEFINED IN_SOURCE_BUILD) set(LLVM_LINK_COMPONENTS BitWriter Core IPO IrReader InstCombine Instrumentation Target Linker Analysis ScalarOpts Support Svf Cudd) add_llvm_tool( wpa wpa.cpp ) else() - llvm_map_components_to_libnames(llvm_libs BitWriter Core IPO IrReader InstCombine Instrumentation Target Linker Analysis ScalarOpts Support ) + llvm_map_components_to_libnames(llvm_libs bitwriter core ipo irreader instcombine instrumentation target linker analysis scalaropts support ) add_executable( wpa wpa.cpp ) target_link_libraries( wpa LLVMSvf LLVMCudd ${llvm_libs} ) From 099e7676cc6dd027265949db45cf4112d842f226 Mon Sep 17 00:00:00 2001 From: Jared Carlson Date: Sat, 15 Apr 2017 11:18:40 -0400 Subject: [PATCH 14/17] Ok, down to one little header issue and then write it up and pass it back to Yulei (with notes to help him...) --- CMakeLists.txt | 1 + lib/CMakeLists.txt | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 636653206..a9622b537 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,6 +31,7 @@ endif() include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_BINARY_DIR}/include) + add_subdirectory(lib) add_subdirectory(tools) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index fa1eef152..3c4207557 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -50,8 +50,13 @@ set(SOURCES add_llvm_loadable_module(Svf ${SOURCES}) add_llvm_Library(LLVMSvf ${SOURCES}) + +# It seems that the Svf library needs to explictly require the CUDD alloc/init/etc so LLVMCudd +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 ) target_link_libraries(LLVMSvf ${llvm_libs}) +target_link_libraries(Svf LLVMCudd ${llvm_libs}) if(DEFINED IN_SOURCE_BUILD) add_dependencies(Svf intrinsics_gen) From e5c9dd38b313cc381bbe978a416896b3f8a8915e Mon Sep 17 00:00:00 2001 From: Jared Carlson Date: Sun, 16 Apr 2017 22:58:39 -0400 Subject: [PATCH 15/17] Fixed that header issue, looks like the next few are pretty simple --- tools/SABER/saber.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/SABER/saber.cpp b/tools/SABER/saber.cpp index 706b9b8af..ba58ea2a3 100644 --- a/tools/SABER/saber.cpp +++ b/tools/SABER/saber.cpp @@ -39,7 +39,8 @@ #include // for pass list #include // for llvm LLVMContext #include // for SMDiagnostic -#include // for createBitcodeWriterPass + +#include // for createBitcodeWriterPass using namespace llvm; From 37111d4764affe5d07eb0dc8d777b97bf37101a2 Mon Sep 17 00:00:00 2001 From: Jared Carlson Date: Mon, 17 Apr 2017 09:25:43 -0400 Subject: [PATCH 16/17] Fixed the wpa and saber tools - just needed a few args changed and using the LLVMGetGlobalContext rather than getGlobalContext --- tools/SABER/saber.cpp | 8 +++++--- tools/WPA/wpa.cpp | 10 ++++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/tools/SABER/saber.cpp b/tools/SABER/saber.cpp index ba58ea2a3..a84b3f853 100644 --- a/tools/SABER/saber.cpp +++ b/tools/SABER/saber.cpp @@ -30,6 +30,7 @@ #include "SABER/FileChecker.h" #include "SABER/DoubleFreeChecker.h" +#include // for LLVMGetGlobalContext() #include // for cl #include // for bitcode write #include // pass manager @@ -59,15 +60,16 @@ static cl::opt DFREECHECKER("dfree", cl::init(false), int main(int argc, char ** argv) { - sys::PrintStackTraceOnErrorSignal(); + sys::PrintStackTraceOnErrorSignal(argv[0]); llvm::PrettyStackTraceProgram X(argc, argv); - LLVMContext &Context = getGlobalContext(); + LLVMOpaqueContext * WrappedContextRef = LLVMGetGlobalContext(); + LLVMContext &Context = *unwrap(WrappedContextRef); std::string OutputFilename; cl::ParseCommandLineOptions(argc, argv, "Software Bug Check\n"); - sys::PrintStackTraceOnErrorSignal(); + sys::PrintStackTraceOnErrorSignal(argv[0]); PassRegistry &Registry = *PassRegistry::getPassRegistry(); diff --git a/tools/WPA/wpa.cpp b/tools/WPA/wpa.cpp index bcbca6b38..a5917889c 100644 --- a/tools/WPA/wpa.cpp +++ b/tools/WPA/wpa.cpp @@ -28,6 +28,7 @@ #include "WPA/WPAPass.h" +#include // for LLVMGetGlobalContext() #include // for cl #include // for sys::fs::F_None #include // for bitcode write @@ -38,7 +39,7 @@ #include // for pass list #include // for llvm LLVMContext #include // for SMDiagnostic -#include // for createBitcodeWriterPass +#include // for createBitcodeWriterPass using namespace llvm; @@ -49,15 +50,16 @@ static cl::opt InputFilename(cl::Positional, int main(int argc, char ** argv) { - sys::PrintStackTraceOnErrorSignal(); + sys::PrintStackTraceOnErrorSignal(argv[0]); llvm::PrettyStackTraceProgram X(argc, argv); - LLVMContext &Context = getGlobalContext(); + LLVMOpaqueContext * WrappedContextRef = LLVMGetGlobalContext(); + LLVMContext &Context = *unwrap(WrappedContextRef); std::string OutputFilename; cl::ParseCommandLineOptions(argc, argv, "Whole Program Points-to Analysis\n"); - sys::PrintStackTraceOnErrorSignal(); + sys::PrintStackTraceOnErrorSignal(argv[0]); PassRegistry &Registry = *PassRegistry::getPassRegistry(); From 29ae917dec49bf21b845eaa1689a22d5b1bf258d Mon Sep 17 00:00:00 2001 From: Jared Carlson Date: Mon, 17 Apr 2017 20:48:14 -0400 Subject: [PATCH 17/17] Ready to issue a PR, one issue for others to decide I think but the rest should be pretty much ready to go --- SVF Alterations.txt | 24 ++++++++++++++++++++++++ include/WPA/WPAPass.h | 1 + 2 files changed, 25 insertions(+) create mode 100644 SVF Alterations.txt diff --git a/SVF Alterations.txt b/SVF Alterations.txt new file mode 100644 index 000000000..9dd875aa9 --- /dev/null +++ b/SVF Alterations.txt @@ -0,0 +1,24 @@ +Diff between “llvm-4” and “master” + +Likely the most important difference is the requirement that a NodeRef (rather than NodeType) be declared for types that will utilize the GraphTraits as part of the class definition. + +I altered most of the getPassName() instances to return a llvm::StringRef rather than a const char * type. This seems rather trivial and I didn’t see a reason not to use the preferred string type choice for LLVM. + +/include/Util/DataFlow.h +The PostDominatorTree becomes PostDominatorTreeWrapperPass, which is pretty consistent in recent revisions where a pass is accessed via a wrapper. + +I altered the base class /include/Util/GraphUtil.h + +To have a typedef typename Traits::NodeRef NodeRef, per llvm 4. I believe this is necessary, as I looked over the llvm-4. This with the NodeRef alterations in each of the specific graph classes required some alterations in terms of dereferencing, etc. Again, a quick pass and it seemed to work but this is a place where a simple “*” might have a subtle unintended consequence. + +include/WPA/WPAPass.h + +Here I had to remove the explicit inheritance from “AliasAnalysis”, and this likely needs a fix, as AliasAnalysis needs a TargetLibraryInfo to be passed as the argument now and I’m a little unsure as to where to get that from. There is no more default constructor… To get the TargetLibraryInfo it seems the best convention is: + +TLInfo = &getAnalysis().getTLI(); + +But it didn’t seem to “drop in” to the wpa tool perfectly. It seems that inheriting from AAResultsWrapperPass might make sense? Or to have a dependency there? That said, I’m still learning so I wanted to point this out and let others more familiar make that decision. + +I had a number of CMAKE issues, most of which I was able to solve but might have a few redundancies, perhaps that is because I’m on a Mac. + +I believe the rest is pretty straightforward. Looking back the WPAPass is likely an issue to be solved prior to merging into master, the rest \ No newline at end of file diff --git a/include/WPA/WPAPass.h b/include/WPA/WPAPass.h index e770c2d1f..bc0b4da88 100644 --- a/include/WPA/WPAPass.h +++ b/include/WPA/WPAPass.h @@ -66,6 +66,7 @@ class WPAPass: public llvm::ModulePass { WPAPass() : llvm::ModulePass(ID) { } + /// Destructor ~WPAPass();