From 47219c775c97bb000f508acc355d67420452ed4c Mon Sep 17 00:00:00 2001 From: Xudong Wang Date: Sun, 11 Dec 2022 02:24:42 +1100 Subject: [PATCH] Remove LLVM header in SVFType.h & Remove getLLVMModuleSet() in LLVMUtil.h --- .clang-format | 1 + include/SVF-LLVM/LLVMUtil.h | 167 ++++++++++++------------ include/SVFIR/SVFStatements.h | 6 +- include/SVFIR/SVFType.h | 225 +++++++++++++++++--------------- include/SVFIR/SVFValue.h | 6 +- include/SVFIR/SVFVariables.h | 6 +- include/SVFIR/SymbolTableInfo.h | 6 +- 7 files changed, 219 insertions(+), 198 deletions(-) diff --git a/.clang-format b/.clang-format index a29b5ae95..72e3e20ff 100644 --- a/.clang-format +++ b/.clang-format @@ -3,3 +3,4 @@ PointerAlignment: Left IndentPPDirectives: AfterHash AllowShortFunctionsOnASingleLine: Empty ColumnLimit: 80 +AccessModifierOffset: -4 diff --git a/include/SVF-LLVM/LLVMUtil.h b/include/SVF-LLVM/LLVMUtil.h index 5a22a5819..2b60c7bdc 100644 --- a/include/SVF-LLVM/LLVMUtil.h +++ b/include/SVF-LLVM/LLVMUtil.h @@ -57,7 +57,8 @@ inline bool isCallSite(const Value* val) /// Get the definition of a function across multiple modules inline const Function* getDefFunForMultipleModule(const Function* fun) { - if(fun == nullptr) return nullptr; + if (fun == nullptr) + return nullptr; LLVMModuleSet* llvmModuleset = LLVMModuleSet::getLLVMModuleSet(); if (fun->isDeclaration() && llvmModuleset->hasDefinition(fun)) fun = LLVMModuleSet::getLLVMModuleSet()->getDefinition(fun); @@ -75,38 +76,38 @@ inline const Function* getCallee(const CallBase* cs) { // FIXME: do we need to strip-off the casts here to discover more library functions const Function* callee = SVFUtil::dyn_cast(cs->getCalledOperand()->stripPointerCasts()); - if(callee) - return getDefFunForMultipleModule(callee); - else - return nullptr; + return callee ? getDefFunForMultipleModule(callee) : nullptr; } /// Return LLVM function if this value is inline const Function* getLLVMFunction(const Value* val) { - const Function* fun = SVFUtil::dyn_cast(val->stripPointerCasts()); - return fun; + return SVFUtil::dyn_cast(val->stripPointerCasts()); } /// Get program entry function from module. inline const Function* getProgFunction(const std::string& funName) { - for (Module& M : LLVMModuleSet::getLLVMModuleSet()->getLLVMModules()) + for (const Module& M : LLVMModuleSet::getLLVMModuleSet()->getLLVMModules()) { - for (Module::const_iterator F = M.begin(), E = M.end(); F != E; ++F) - { - const Function *fun = &*F; - if (fun->getName().str()==funName) - return fun; + for (const Function& fun : M) { + if (fun.getName() == funName) + return &fun; } } return nullptr; } +/// Check whether a function is an entry function (i.e., main) +inline bool isProgEntryFunction(const Function* fun) +{ + return fun && fun->getName() == "main"; +} + /// Check whether this value is a black hole inline bool isBlackholeSym(const Value* val) { - return (SVFUtil::isa(val)); + return SVFUtil::isa(val); } /// Check whether this value is a black hole @@ -159,16 +160,16 @@ inline const PointerType *getRefTypeOfHeapAllocOrStatic(const Instruction* inst) //@} /// Return true if this value refers to a object -bool isObject (const Value* ref); +bool isObject(const Value* ref); /// Method for dead function, which does not have any possible caller /// function address is not taken and never be used in call or invoke instruction //@{ /// whether this is a function without any possible caller? -bool isUncalledFunction (const Function* fun); +bool isUncalledFunction(const Function* fun); /// whether this is an argument in dead function -inline bool ArgInDeadFunction (const Value* val) +inline bool ArgInDeadFunction(const Value* val) { return SVFUtil::isa(val) && isUncalledFunction(SVFUtil::cast(val)->getParent()); @@ -179,12 +180,11 @@ inline bool ArgInDeadFunction (const Value* val) inline bool ArgInProgEntryFunction(const Value* val) { return SVFUtil::isa(val) && - SVFUtil::isProgEntryFunction( - LLVMModuleSet::getLLVMModuleSet()->getSVFFunction( - SVFUtil::cast(val)->getParent())); + LLVMUtil::isProgEntryFunction( + SVFUtil::cast(val)->getParent()); } /// Return true if this is value in a dead function (function without any caller) -bool isPtrInUncalledFunction (const Value* value); +bool isPtrInUncalledFunction(const Value* value); //@} //@} @@ -194,9 +194,7 @@ bool isPtrInUncalledFunction (const Value* value); /// Return true if the function does not have a caller (either it is a main function or a dead function) inline bool isNoCallerFunction(const Function* fun) { - return isUncalledFunction(fun) || - SVFUtil::isProgEntryFunction( - LLVMModuleSet::getLLVMModuleSet()->getSVFFunction(fun)); + return isUncalledFunction(fun) || LLVMUtil::isProgEntryFunction(fun); } /// Return true if the argument in a function does not have a caller @@ -207,115 +205,121 @@ inline bool isArgOfUncalledFunction (const Value* val) } //@} -/// Return true if the function has a return instruction reachable from function entry -bool functionDoesNotRet (const Function* fun); +/// Return true if the function has a return instruction reachable from function +/// entry +bool functionDoesNotRet(const Function* fun); /// Get reachable basic block from function entry -void getFunReachableBBs (const Function* svfFun, std::vector& bbs); +void getFunReachableBBs(const Function* svfFun, + std::vector& bbs); /// Strip off the constant casts -const Value* stripConstantCasts(const Value* val); +const Value* stripConstantCasts(const Value* val); /// Strip off the all casts -const Value* stripAllCasts(const Value* val) ; +const Value* stripAllCasts(const Value* val); /// Get the type of the heap allocation -const Type* getTypeOfHeapAlloc(const Instruction* inst) ; +const Type* getTypeOfHeapAlloc(const Instruction* inst); -/// Return the bitcast instruction which is val's only use site, otherwise return nullptr +/// Return the bitcast instruction which is val's only use site, otherwise +/// return nullptr const Value* getUniqueUseViaCastInst(const Value* val); /// Return corresponding constant expression, otherwise return nullptr //@{ -inline const ConstantExpr *isGepConstantExpr(const Value* val) +inline const ConstantExpr* isGepConstantExpr(const Value* val) { - if(const ConstantExpr* constExpr = SVFUtil::dyn_cast(val)) + if (const ConstantExpr* constExpr = SVFUtil::dyn_cast(val)) { - if(constExpr->getOpcode() == Instruction::GetElementPtr) + if (constExpr->getOpcode() == Instruction::GetElementPtr) return constExpr; } return nullptr; } -inline const ConstantExpr *isInt2PtrConstantExpr(const Value* val) +inline const ConstantExpr* isInt2PtrConstantExpr(const Value* val) { - if(const ConstantExpr* constExpr = SVFUtil::dyn_cast(val)) + if (const ConstantExpr* constExpr = SVFUtil::dyn_cast(val)) { - if(constExpr->getOpcode() == Instruction::IntToPtr) + if (constExpr->getOpcode() == Instruction::IntToPtr) return constExpr; } return nullptr; } -inline const ConstantExpr *isPtr2IntConstantExpr(const Value* val) +inline const ConstantExpr* isPtr2IntConstantExpr(const Value* val) { - if(const ConstantExpr* constExpr = SVFUtil::dyn_cast(val)) + if (const ConstantExpr* constExpr = SVFUtil::dyn_cast(val)) { - if(constExpr->getOpcode() == Instruction::PtrToInt) + if (constExpr->getOpcode() == Instruction::PtrToInt) return constExpr; } return nullptr; } -inline const ConstantExpr *isCastConstantExpr(const Value* val) +inline const ConstantExpr* isCastConstantExpr(const Value* val) { - if(const ConstantExpr* constExpr = SVFUtil::dyn_cast(val)) + if (const ConstantExpr* constExpr = SVFUtil::dyn_cast(val)) { - if(constExpr->getOpcode() == Instruction::BitCast) + if (constExpr->getOpcode() == Instruction::BitCast) return constExpr; } return nullptr; } -inline const ConstantExpr *isSelectConstantExpr(const Value* val) +inline const ConstantExpr* isSelectConstantExpr(const Value* val) { - if(const ConstantExpr* constExpr = SVFUtil::dyn_cast(val)) + if (const ConstantExpr* constExpr = SVFUtil::dyn_cast(val)) { - if(constExpr->getOpcode() == Instruction::Select) + if (constExpr->getOpcode() == Instruction::Select) return constExpr; } return nullptr; } -inline const ConstantExpr *isTruncConstantExpr(const Value* val) +inline const ConstantExpr* isTruncConstantExpr(const Value* val) { - if(const ConstantExpr* constExpr = SVFUtil::dyn_cast(val)) + if (const ConstantExpr* constExpr = SVFUtil::dyn_cast(val)) { - if(constExpr->getOpcode() == Instruction::Trunc || - constExpr->getOpcode() == Instruction::FPTrunc || - constExpr->getOpcode() == Instruction::ZExt || - constExpr->getOpcode() == Instruction::SExt || - constExpr->getOpcode() == Instruction::FPExt) + if (constExpr->getOpcode() == Instruction::Trunc || + constExpr->getOpcode() == Instruction::FPTrunc || + constExpr->getOpcode() == Instruction::ZExt || + constExpr->getOpcode() == Instruction::SExt || + constExpr->getOpcode() == Instruction::FPExt) return constExpr; } return nullptr; } -inline const ConstantExpr *isCmpConstantExpr(const Value* val) +inline const ConstantExpr* isCmpConstantExpr(const Value* val) { - if(const ConstantExpr* constExpr = SVFUtil::dyn_cast(val)) + if (const ConstantExpr* constExpr = SVFUtil::dyn_cast(val)) { - if(constExpr->getOpcode() == Instruction::ICmp || constExpr->getOpcode() == Instruction::FCmp) + if (constExpr->getOpcode() == Instruction::ICmp || + constExpr->getOpcode() == Instruction::FCmp) return constExpr; } return nullptr; } -inline const ConstantExpr *isBinaryConstantExpr(const Value* val) +inline const ConstantExpr* isBinaryConstantExpr(const Value* val) { - if(const ConstantExpr* constExpr = SVFUtil::dyn_cast(val)) + if (const ConstantExpr* constExpr = SVFUtil::dyn_cast(val)) { - if((constExpr->getOpcode() >= Instruction::BinaryOpsBegin) && (constExpr->getOpcode() <= Instruction::BinaryOpsEnd)) + if ((constExpr->getOpcode() >= Instruction::BinaryOpsBegin) && + (constExpr->getOpcode() <= Instruction::BinaryOpsEnd)) return constExpr; } return nullptr; } -inline const ConstantExpr *isUnaryConstantExpr(const Value* val) +inline const ConstantExpr* isUnaryConstantExpr(const Value* val) { - if(const ConstantExpr* constExpr = SVFUtil::dyn_cast(val)) + if (const ConstantExpr* constExpr = SVFUtil::dyn_cast(val)) { - if((constExpr->getOpcode() >= Instruction::UnaryOpsBegin) && (constExpr->getOpcode() <= Instruction::UnaryOpsEnd)) + if ((constExpr->getOpcode() >= Instruction::UnaryOpsBegin) && + (constExpr->getOpcode() <= Instruction::UnaryOpsEnd)) return constExpr; } return nullptr; @@ -325,38 +329,41 @@ inline const ConstantExpr *isUnaryConstantExpr(const Value* val) inline static DataLayout* getDataLayout(Module* mod) { static DataLayout *dl = nullptr; - if (dl == nullptr) dl = new DataLayout(mod); + if (dl == nullptr) + dl = new DataLayout(mod); return dl; } /// Get the next instructions following control flow -void getNextInsts(const Instruction* curInst, std::vector& instList); +void getNextInsts(const Instruction* curInst, + std::vector& instList); /// Get the previous instructions following control flow -void getPrevInsts(const Instruction* curInst, std::vector& instList); +void getPrevInsts(const Instruction* curInst, + std::vector& instList); /// Get the next instructions following control flow -void getNextInsts(const Instruction* curInst, std::vector& instList); +void getNextInsts(const Instruction* curInst, + std::vector& instList); /// Get the previous instructions following control flow -void getPrevInsts(const Instruction* curInst, std::vector& instList); +void getPrevInsts(const Instruction* curInst, + std::vector& instList); /// Get num of BB's predecessors u32_t getBBPredecessorNum(const BasicBlock* BB); - - /// Check whether a file is an LLVM IR file -bool isIRFile(const std::string &filename); +bool isIRFile(const std::string& filename); /// Parse argument for multi-module analysis -void processArguments(int argc, char **argv, int &arg_num, char **arg_value, - std::vector &moduleNameVec); +void processArguments(int argc, char** argv, int& arg_num, char** arg_value, + std::vector& moduleNameVec); /// Helper method to get the size of the type from target data layout //@{ u32_t getTypeSizeInBytes(const Type* type); -u32_t getTypeSizeInBytes(const StructType *sty, u32_t field_index); +u32_t getTypeSizeInBytes(const StructType* sty, u32_t field_index); //@} const std::string getSourceLoc(const Value* val); @@ -374,17 +381,14 @@ inline const SVFFunction* getFunction(const std::string& name) /// Return true if the value refers to constant data, e.g., i32 0 inline bool isConstDataOrAggData(const Value* val) { - bool constDataOrConstAggregate = SVFUtil::isa(val) - || SVFUtil::isa(val) - || SVFUtil::isa(val) - || SVFUtil::isa(val); - return constDataOrConstAggregate; + return SVFUtil::isa(val); } /// find the unique defined global across multiple modules inline const Value* getGlobalRep(const Value* val) { - if(const GlobalVariable* gvar = SVFUtil::dyn_cast(val)) + if (const GlobalVariable* gvar = SVFUtil::dyn_cast(val)) { if (LLVMModuleSet::getLLVMModuleSet()->hasGlobalRep(gvar)) val = LLVMModuleSet::getLLVMModuleSet()->getGlobalRep(gvar); @@ -405,7 +409,7 @@ void viewCFG(const Function* fun); void viewCFGOnly(const Function* fun); bool isValVtbl(const Value* val); -bool isLoadVtblInst(const LoadInst *loadInst); +bool isLoadVtblInst(const LoadInst* loadInst); bool isVirtualCallSite(const CallBase* cs); bool isConstructor(const Function* F); bool isDestructor(const Function* F); @@ -451,7 +455,8 @@ bool VCallInCtorOrDtor(const CallBase* cs); * } * this and this1 are the same thisPtr in the constructor */ -bool isSameThisPtrInConstructor(const Argument* thisPtr1, const Value* thisPtr2); +bool isSameThisPtrInConstructor(const Argument* thisPtr1, + const Value* thisPtr2); } // End namespace LLVMUtil diff --git a/include/SVFIR/SVFStatements.h b/include/SVFIR/SVFStatements.h index f71e2f51f..43d76ec9f 100644 --- a/include/SVFIR/SVFStatements.h +++ b/include/SVFIR/SVFStatements.h @@ -28,8 +28,8 @@ * Author: Yulei Sui */ -#ifndef PAGEDGE_H_ -#define PAGEDGE_H_ +#ifndef INCLUDE_SVFIR_SVFSTATEMENT_H_ +#define INCLUDE_SVFIR_SVFSTATEMENT_H_ #include "Graphs/GenericGraph.h" #include "MemoryModel/LocationSet.h" @@ -1144,4 +1144,4 @@ class TDJoinPE: public RetPE } // End namespace SVF -#endif /* PAGEDGE_H_ */ +#endif /* INCLUDE_SVFIR_SVFSTATEMENT_H_ */ \ No newline at end of file diff --git a/include/SVFIR/SVFType.h b/include/SVFIR/SVFType.h index 2c154e588..be6a8fd7d 100644 --- a/include/SVFIR/SVFType.h +++ b/include/SVFIR/SVFType.h @@ -27,23 +27,20 @@ * Author: Yulei Sui */ +#ifndef INCLUDE_SVFIR_SVFTYPE_H_ +#define INCLUDE_SVFIR_SVFTYPE_H_ -#ifndef INCLUDE_UTIL_SVFBASICTYPES_H_ -#define INCLUDE_UTIL_SVFBASICTYPES_H_ - -#include // TODO: Remove LLVM Header - -#include +#include "Util/SparseBitVector.h" +#include #include -#include #include -#include -#include #include -#include +#include #include -#include +#include +#include +#include namespace SVF { @@ -74,7 +71,7 @@ template struct Hash> return a > b ? b * b + a : a * a + a + b; } - size_t operator()(const std::pair &t) const + size_t operator()(const std::pair& t) const { Hash first; Hash second; @@ -84,65 +81,68 @@ template struct Hash> template struct Hash { - size_t operator()(const T &t) const + size_t operator()(const T& t) const { std::hash h; return h(t); } }; -template , typename KeyEqual = std::equal_to, +template , + typename KeyEqual = std::equal_to, typename Allocator = std::allocator> using Set = std::unordered_set; -template, - typename KeyEqual = std::equal_to, - typename Allocator = std::allocator>> - using Map = std::unordered_map; - - template, typename Allocator = std::allocator> - using OrderedSet = std::set; - - template, - typename Allocator = std::allocator>> - using OrderedMap = std::map; - - typedef std::pair NodePair; - typedef OrderedSet OrderedNodeSet; - typedef Set NodeSet; - typedef Set NodePairSet; - typedef Map NodePairMap; - typedef std::vector NodeVector; - typedef std::vector EdgeVector; - typedef std::stack NodeStack; - typedef std::list NodeList; - typedef std::deque NodeDeque; - typedef NodeSet EdgeSet; - typedef std::vector CallStrCxt; - typedef unsigned Version; - typedef Set VersionSet; - typedef std::pair VersionedVar; - typedef Set VersionedVarSet; - - class SVFType; - class SVFPointerType; - - /*! - * Flatterned type information of StructType, ArrayType and SingleValueType - */ - class StInfo -{ +template , + typename KeyEqual = std::equal_to, + typename Allocator = std::allocator>> +using Map = std::unordered_map; +template , + typename Allocator = std::allocator> +using OrderedSet = std::set; + +template , + typename Allocator = std::allocator>> +using OrderedMap = std::map; + +typedef std::pair NodePair; +typedef OrderedSet OrderedNodeSet; +typedef Set NodeSet; +typedef Set NodePairSet; +typedef Map NodePairMap; +typedef std::vector NodeVector; +typedef std::vector EdgeVector; +typedef std::stack NodeStack; +typedef std::list NodeList; +typedef std::deque NodeDeque; +typedef NodeSet EdgeSet; +typedef std::vector CallStrCxt; +typedef unsigned Version; +typedef Set VersionSet; +typedef std::pair VersionedVar; +typedef Set VersionedVarSet; + +class SVFType; +class SVFPointerType; + +/*! + * Flatterned type information of StructType, ArrayType and SingleValueType + */ +class StInfo +{ private: /// flattened field indices of a struct (ignoring arrays) std::vector fldIdxVec; - /// flattened element indices including structs and arrays by considering strides + /// flattened element indices including structs and arrays by considering + /// strides std::vector elemIdxVec; /// Types of all fields of a struct Map fldIdx2TypeMap; /// All field infos after flattening a struct std::vector finfo; - /// stride represents the number of repetitive elements if this StInfo represent an ArrayType. stride is 1 by default. + /// stride represents the number of repetitive elements if this StInfo + /// represent an ArrayType. stride is 1 by default. u32_t stride; /// number of elements after flattenning (including array elements) u32_t numOfFlattenElements; @@ -158,14 +158,15 @@ template, void operator=(const StInfo&) = delete; /// Constructor - explicit StInfo(u32_t s) : stride(s), numOfFlattenElements(s), numOfFlattenFields(s) + explicit StInfo(u32_t s) + : stride(s), numOfFlattenElements(s), numOfFlattenFields(s) { } /// Destructor ~StInfo() = default; - /// struct A { int id; int salary; }; struct B { char name[20]; struct A a;} B b; - /// OriginalFieldType of b with field_idx 1 : Struct A + /// struct A { int id; int salary; }; struct B { char name[20]; struct A a;} B b; + // OriginalFieldType of b with field_idx 1 : Struct A /// FlatternedFieldType of b with field_idx 1 : int //{@ const SVFType* getOriginalElemType(u32_t fldIdx) const; @@ -250,27 +251,30 @@ class SVFType }; private: - GNodeK kind; ///< used for classof - const SVFPointerType* getPointerToTy; /// Return a pointer to the current type - StInfo* typeinfo; /// < SVF's TypeInfo - bool isSingleValTy; ///< The type represents a single value, not struct or array + GNodeK kind; ///< used for classof + const SVFPointerType* + getPointerToTy; /// Return a pointer to the current type + StInfo* typeinfo; /// < SVF's TypeInfo + bool isSingleValTy; ///< The type represents a single value, not struct or + ///< array protected: - SVFType(bool svt, SVFTyKind k) : kind(k), getPointerToTy(nullptr), typeinfo(nullptr), isSingleValTy(svt) + SVFType(bool svt, SVFTyKind k) + : kind(k), getPointerToTy(nullptr), typeinfo(nullptr), + isSingleValTy(svt) { } public: SVFType(void) = delete; - virtual ~SVFType() - { - } + virtual ~SVFType() {} inline GNodeK getKind() const { return kind; } - /// Needs to be implemented by a specific SVF front end (e.g., the implementation in LLVMUtil) + /// Needs to be implemented by a specific SVF front end (e.g., the + /// implementation in LLVMUtil) virtual const std::string toString() const; inline void setPointerTo(const SVFPointerType* ty) @@ -278,13 +282,13 @@ class SVFType getPointerToTy = ty; } - inline const SVFPointerType* getPointerTo () const + inline const SVFPointerType* getPointerTo() const { assert(getPointerToTy && "set the getPointerToTy first"); return getPointerToTy; } - inline void setTypeInfo (StInfo* ti) + inline void setTypeInfo(StInfo* ti) { typeinfo = ti; } @@ -303,7 +307,7 @@ class SVFType inline bool isPointerTy() const { - return kind==SVFPointerTy; + return kind == SVFPointerTy; } inline bool isSingleValueType() const @@ -319,10 +323,11 @@ class SVFPointerType : public SVFType const SVFType* ptrElementType; public: - SVFPointerType(const SVFType* pty) : SVFType(true, SVFPointerTy), ptrElementType(pty) + SVFPointerType(const SVFType* pty) + : SVFType(true, SVFPointerTy), ptrElementType(pty) { } - static inline bool classof(const SVFType *node) + static inline bool classof(const SVFType* node) { return node->getKind() == SVFPointerTy; } @@ -335,10 +340,8 @@ class SVFPointerType : public SVFType class SVFIntergerType : public SVFType { public: - SVFIntergerType() : SVFType(true, SVFIntergerTy) - { - } - static inline bool classof(const SVFType *node) + SVFIntergerType() : SVFType(true, SVFIntergerTy) {} + static inline bool classof(const SVFType* node) { return node->getKind() == SVFIntergerTy; } @@ -350,10 +353,11 @@ class SVFFunctionType : public SVFType const SVFType* retTy; public: - SVFFunctionType(const SVFType* rt) : SVFType(false, SVFFunctionTy), retTy(rt) + SVFFunctionType(const SVFType* rt) + : SVFType(false, SVFFunctionTy), retTy(rt) { } - static inline bool classof(const SVFType *node) + static inline bool classof(const SVFType* node) { return node->getKind() == SVFFunctionTy; } @@ -366,10 +370,8 @@ class SVFFunctionType : public SVFType class SVFStructType : public SVFType { public: - SVFStructType() : SVFType(false, SVFStructTy) - { - } - static inline bool classof(const SVFType *node) + SVFStructType() : SVFType(false, SVFStructTy) {} + static inline bool classof(const SVFType* node) { return node->getKind() == SVFStructTy; } @@ -378,10 +380,8 @@ class SVFStructType : public SVFType class SVFArrayType : public SVFType { public: - SVFArrayType() : SVFType(false, SVFArrayTy) - { - } - static inline bool classof(const SVFType *node) + SVFArrayType() : SVFType(false, SVFArrayTy) {} + static inline bool classof(const SVFType* node) { return node->getKind() == SVFArrayTy; } @@ -390,20 +390,17 @@ class SVFArrayType : public SVFType class SVFOtherType : public SVFType { public: - SVFOtherType(bool isSingleValueTy) : SVFType(isSingleValueTy, SVFOtherTy) - { - } - static inline bool classof(const SVFType *node) + SVFOtherType(bool isSingleValueTy) : SVFType(isSingleValueTy, SVFOtherTy) {} + static inline bool classof(const SVFType* node) { return node->getKind() == SVFOtherTy; } }; - // TODO: be explicit that this is a pair of 32-bit unsigneds? template <> struct Hash { - size_t operator()(const NodePair &p) const + size_t operator()(const NodePair& p) const { // Make sure our assumptions are sound: use u32_t // and u64_t. If NodeID is not actually u32_t or size_t @@ -415,12 +412,32 @@ template <> struct Hash } }; +#ifndef DEBUG_WITH_TYPE +# ifndef NDBUG +// TODO: This comes from the following link +// https://github.com/llvm/llvm-project/blob/75e33f71c2dae584b13a7d1186ae0a038ba98838/llvm/include/llvm/Support/Debug.h#L64 +// The original LLVM implementation makes use of type. But we can get that info, +// so we can't simulate the full behaviour for now. +# define DEBUG_WITH_TYPE(TYPE, X) \ + do \ + { \ + X; \ + } while (false) +# else +# define DEBUG_WITH_TYPE(TYPE, X) \ + do \ + { \ + } while (false) +# endif +#endif + /// LLVM debug macros, define type of your DEBUG model of each pass -#define DBOUT(TYPE, X) DEBUG_WITH_TYPE(TYPE, X) -#define DOSTAT(X) X -#define DOTIMESTAT(X) X +#define DBOUT(TYPE, X) DEBUG_WITH_TYPE(TYPE, X) +#define DOSTAT(X) X +#define DOTIMESTAT(X) X -/// General debug flag is for each phase of a pass, it is often in a colorful output format +/// General debug flag is for each phase of a pass, it is often in a colorful +/// output format #define DGENERAL "general" #define DPAGBuild "pag" @@ -467,10 +484,9 @@ enum AliasResult } // End namespace SVF - template <> struct std::hash { - size_t operator()(const SVF::NodePair &p) const + size_t operator()(const SVF::NodePair& p) const { // Make sure our assumptions are sound: use u32_t // and u64_t. If NodeID is not actually u32_t or size_t @@ -483,26 +499,25 @@ template <> struct std::hash }; /// Specialise hash for SparseBitVectors. -template -struct std::hash> +template struct std::hash> { - size_t operator()(const SVF::SparseBitVector &sbv) const + size_t operator()(const SVF::SparseBitVector& sbv) const { SVF::Hash, size_t>> h; - return h(std::make_pair(std::make_pair(sbv.count(), sbv.find_first()), sbv.find_last())); + return h(std::make_pair(std::make_pair(sbv.count(), sbv.find_first()), + sbv.find_last())); } }; -template -struct std::hash> +template struct std::hash> { - size_t operator()(const std::vector &v) const + size_t operator()(const std::vector& v) const { // TODO: repetition with CBV. size_t h = v.size(); SVF::Hash hf; - for (const T &t : v) + for (const T& t : v) { h ^= hf(t) + 0x9e3779b9 + (h << 6) + (h >> 2); } @@ -511,4 +526,4 @@ struct std::hash> } }; -#endif /* INCLUDE_UTIL_SVFBASICTYPES_H_ */ +#endif /* INCLUDE_SVFIR_SVFTYPE_H_ */ diff --git a/include/SVFIR/SVFValue.h b/include/SVFIR/SVFValue.h index 40a9ab52b..4ea0bd87c 100644 --- a/include/SVFIR/SVFValue.h +++ b/include/SVFIR/SVFValue.h @@ -27,8 +27,8 @@ * Author: Yulei Sui */ -#ifndef BASICTYPES_H_ -#define BASICTYPES_H_ +#ifndef INCLUDE_SVFIR_SVFVALUE_H_ +#define INCLUDE_SVFIR_SVFVALUE_H_ #include "SVFIR/SVFType.h" #include "Graphs/GraphPrinter.h" @@ -1117,4 +1117,4 @@ template <> struct std::hash } }; -#endif /* BASICTYPES_H_ */ +#endif /* INCLUDE_SVFIR_SVFVALUE_H_ */ diff --git a/include/SVFIR/SVFVariables.h b/include/SVFIR/SVFVariables.h index 9d12a833e..62da6b095 100644 --- a/include/SVFIR/SVFVariables.h +++ b/include/SVFIR/SVFVariables.h @@ -27,8 +27,8 @@ * Author: Yulei Sui */ -#ifndef OBJECTANDSYMBOL_H_ -#define OBJECTANDSYMBOL_H_ +#ifndef INCLUDE_SVFIR_SVFVARIABLE_H_ +#define INCLUDE_SVFIR_SVFVARIABLE_H_ #include "Graphs/GenericGraph.h" #include "SVFIR/SymbolTableInfo.h" @@ -718,4 +718,4 @@ class DummyObjVar: public ObjVar } // End namespace SVF -#endif /* OBJECTANDSYMBOL_H_ */ +#endif /* INCLUDE_SVFIR_SVFVARIABLE_H_ */ diff --git a/include/SVFIR/SymbolTableInfo.h b/include/SVFIR/SymbolTableInfo.h index 4f1573317..2b021e8d8 100644 --- a/include/SVFIR/SymbolTableInfo.h +++ b/include/SVFIR/SymbolTableInfo.h @@ -27,8 +27,8 @@ * Author: Yulei Sui */ -#ifndef INCLUDE_SVF_FE_SYMBOLTABLEINFO_H_ -#define INCLUDE_SVF_FE_SYMBOLTABLEINFO_H_ +#ifndef INCLUDE_SVFIR_SYMBOLTABLEINFO_H_ +#define INCLUDE_SVFIR_SYMBOLTABLEINFO_H_ #include "Util/SVFUtil.h" @@ -594,4 +594,4 @@ class ObjTypeInfo } // End namespace SVF -#endif /* INCLUDE_SVF_FE_SYMBOLTABLEINFO_H_ */ +#endif /* INCLUDE_SVFIR_SYMBOLTABLEINFO_H_ */