From: Eugene Zelenko Date: Tue, 6 Mar 2018 00:47:41 +0000 (+0000) Subject: [StaticAnalyzer] Fix some Clang-tidy modernize and Include What You Use warnings... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=09a80cc504e13cd931d86446f194d4a0ddf89e8f;p=clang [StaticAnalyzer] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@326757 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h b/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h index a04fa90059..5555b29253 100644 --- a/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h +++ b/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h @@ -14,33 +14,28 @@ // //===----------------------------------------------------------------------===// - #ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_PROGRAMSTATETRAIT_H #define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_PROGRAMSTATETRAIT_H +#include "llvm/ADT/ImmutableList.h" +#include "llvm/ADT/ImmutableMap.h" +#include "llvm/ADT/ImmutableSet.h" #include "llvm/Support/Allocator.h" -#include "llvm/Support/DataTypes.h" - -namespace llvm { - template class ImmutableMap; - template class ImmutableSet; - template class ImmutableList; - template class ImmutableListImpl; -} +#include namespace clang { - namespace ento { + template struct ProgramStatePartialTrait; /// Declares a program state trait for type \p Type called \p Name, and - /// introduce a typedef named \c NameTy. + /// introduce a type named \c NameTy. /// The macro should not be used inside namespaces, or for traits that must /// be accessible from more than one translation unit. #define REGISTER_TRAIT_WITH_PROGRAMSTATE(Name, Type) \ namespace { \ class Name {}; \ - typedef Type Name ## Ty; \ + using Name ## Ty = Type; \ } \ namespace clang { \ namespace ento { \ @@ -52,28 +47,30 @@ namespace ento { } \ } - // Partial-specialization for ImmutableMap. - template - struct ProgramStatePartialTrait< llvm::ImmutableMap > { - typedef llvm::ImmutableMap data_type; - typedef typename data_type::Factory& context_type; - typedef Key key_type; - typedef Data value_type; - typedef const value_type* lookup_type; - - static inline data_type MakeData(void *const* p) { - return p ? data_type((typename data_type::TreeTy*) *p) + struct ProgramStatePartialTrait> { + using data_type = llvm::ImmutableMap; + using context_type = typename data_type::Factory &; + using key_type = Key; + using value_type = Data; + using lookup_type = const value_type *; + + static data_type MakeData(void *const *p) { + return p ? data_type((typename data_type::TreeTy *) *p) : data_type(nullptr); } - static inline void *MakeVoidPtr(data_type B) { + + static void *MakeVoidPtr(data_type B) { return B.getRoot(); } + static lookup_type Lookup(data_type B, key_type K) { return B.lookup(K); } - static data_type Set(data_type B, key_type K, value_type E,context_type F){ + + static data_type Set(data_type B, key_type K, value_type E, + context_type F) { return F.add(B, K, E); } @@ -85,8 +82,8 @@ namespace ento { return B.contains(K); } - static inline context_type MakeContext(void *p) { - return *((typename data_type::Factory*) p); + static context_type MakeContext(void *p) { + return *((typename data_type::Factory *) p); } static void *CreateContext(llvm::BumpPtrAllocator& Alloc) { @@ -94,7 +91,7 @@ namespace ento { } static void DeleteContext(void *Ctx) { - delete (typename data_type::Factory*) Ctx; + delete (typename data_type::Factory *) Ctx; } }; @@ -107,21 +104,19 @@ namespace ento { /// can deal with. #define CLANG_ENTO_PROGRAMSTATE_MAP(Key, Value) llvm::ImmutableMap - // Partial-specialization for ImmutableSet. - template - struct ProgramStatePartialTrait< llvm::ImmutableSet > { - typedef llvm::ImmutableSet data_type; - typedef typename data_type::Factory& context_type; - typedef Key key_type; + struct ProgramStatePartialTrait> { + using data_type = llvm::ImmutableSet; + using context_type = typename data_type::Factory &; + using key_type = Key; - static inline data_type MakeData(void *const* p) { - return p ? data_type((typename data_type::TreeTy*) *p) + static data_type MakeData(void *const *p) { + return p ? data_type((typename data_type::TreeTy *) *p) : data_type(nullptr); } - static inline void *MakeVoidPtr(data_type B) { + static void *MakeVoidPtr(data_type B) { return B.getRoot(); } @@ -137,27 +132,25 @@ namespace ento { return B.contains(K); } - static inline context_type MakeContext(void *p) { - return *((typename data_type::Factory*) p); + static context_type MakeContext(void *p) { + return *((typename data_type::Factory *) p); } - static void *CreateContext(llvm::BumpPtrAllocator& Alloc) { + static void *CreateContext(llvm::BumpPtrAllocator &Alloc) { return new typename data_type::Factory(Alloc); } static void DeleteContext(void *Ctx) { - delete (typename data_type::Factory*) Ctx; + delete (typename data_type::Factory *) Ctx; } }; - // Partial-specialization for ImmutableList. - template - struct ProgramStatePartialTrait< llvm::ImmutableList > { - typedef llvm::ImmutableList data_type; - typedef T key_type; - typedef typename data_type::Factory& context_type; + struct ProgramStatePartialTrait> { + using data_type = llvm::ImmutableList; + using key_type = T; + using context_type = typename data_type::Factory &; static data_type Add(data_type L, key_type K, context_type F) { return F.add(K, L); @@ -167,83 +160,84 @@ namespace ento { return L.contains(K); } - static inline data_type MakeData(void *const* p) { - return p ? data_type((const llvm::ImmutableListImpl*) *p) + static data_type MakeData(void *const *p) { + return p ? data_type((const llvm::ImmutableListImpl *) *p) : data_type(nullptr); } - static inline void *MakeVoidPtr(data_type D) { + static void *MakeVoidPtr(data_type D) { return const_cast *>(D.getInternalPointer()); } - static inline context_type MakeContext(void *p) { - return *((typename data_type::Factory*) p); + static context_type MakeContext(void *p) { + return *((typename data_type::Factory *) p); } - static void *CreateContext(llvm::BumpPtrAllocator& Alloc) { + static void *CreateContext(llvm::BumpPtrAllocator &Alloc) { return new typename data_type::Factory(Alloc); } static void DeleteContext(void *Ctx) { - delete (typename data_type::Factory*) Ctx; + delete (typename data_type::Factory *) Ctx; } }; - // Partial specialization for bool. template <> struct ProgramStatePartialTrait { - typedef bool data_type; + using data_type = bool; - static inline data_type MakeData(void *const* p) { + static data_type MakeData(void *const *p) { return p ? (data_type) (uintptr_t) *p : data_type(); } - static inline void *MakeVoidPtr(data_type d) { - return (void*) (uintptr_t) d; + + static void *MakeVoidPtr(data_type d) { + return (void *) (uintptr_t) d; } }; // Partial specialization for unsigned. template <> struct ProgramStatePartialTrait { - typedef unsigned data_type; + using data_type = unsigned; - static inline data_type MakeData(void *const* p) { + static data_type MakeData(void *const *p) { return p ? (data_type) (uintptr_t) *p : data_type(); } - static inline void *MakeVoidPtr(data_type d) { - return (void*) (uintptr_t) d; + + static void *MakeVoidPtr(data_type d) { + return (void *) (uintptr_t) d; } }; // Partial specialization for void*. - template <> struct ProgramStatePartialTrait { - typedef void *data_type; + template <> struct ProgramStatePartialTrait { + using data_type = void *; - static inline data_type MakeData(void *const* p) { + static data_type MakeData(void *const *p) { return p ? *p : data_type(); } - static inline void *MakeVoidPtr(data_type d) { + + static void *MakeVoidPtr(data_type d) { return d; } }; // Partial specialization for const void *. template <> struct ProgramStatePartialTrait { - typedef const void *data_type; + using data_type = const void *; - static inline data_type MakeData(void * const *p) { + static data_type MakeData(void *const *p) { return p ? *p : data_type(); } - static inline void *MakeVoidPtr(data_type d) { + static void *MakeVoidPtr(data_type d) { return const_cast(d); } }; -} // end ento namespace - -} // end clang namespace +} // namespace ento +} // namespace clang -#endif +#endif // LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_PROGRAMSTATETRAIT_H diff --git a/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h b/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h index dae5b5495b..92acf7330b 100644 --- a/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h +++ b/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h @@ -16,23 +16,43 @@ #define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SVALBUILDER_H #include "clang/AST/ASTContext.h" +#include "clang/AST/DeclarationName.h" #include "clang/AST/Expr.h" #include "clang/AST/ExprObjC.h" +#include "clang/AST/Type.h" +#include "clang/Basic/LLVM.h" +#include "clang/Basic/LangOptions.h" #include "clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h" #include "clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState_Fwd.h" #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h" #include "clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h" +#include "llvm/ADT/ImmutableList.h" +#include "llvm/ADT/Optional.h" +#include namespace clang { +class BlockDecl; class CXXBoolLiteralExpr; +class CXXMethodDecl; +class CXXRecordDecl; +class DeclaratorDecl; +class FunctionDecl; +class LocationContext; +class StackFrameContext; +class Stmt; namespace ento { class ConditionTruthVal; +class ProgramStateManager; +class StoreRef; class SValBuilder { virtual void anchor(); + protected: ASTContext &Context; @@ -64,14 +84,12 @@ public: public: SValBuilder(llvm::BumpPtrAllocator &alloc, ASTContext &context, ProgramStateManager &stateMgr) - : Context(context), BasicVals(context, alloc), - SymMgr(context, BasicVals, alloc), - MemMgr(context, alloc), - StateMgr(stateMgr), - ArrayIndexTy(context.LongLongTy), - ArrayIndexWidth(context.getTypeSize(ArrayIndexTy)) {} + : Context(context), BasicVals(context, alloc), + SymMgr(context, BasicVals, alloc), MemMgr(context, alloc), + StateMgr(stateMgr), ArrayIndexTy(context.LongLongTy), + ArrayIndexWidth(context.getTypeSize(ArrayIndexTy)) {} - virtual ~SValBuilder() {} + virtual ~SValBuilder() = default; bool haveSameType(const SymExpr *Sym1, const SymExpr *Sym2) { return haveSameType(Sym1->getType(), Sym2->getType()); @@ -195,11 +213,11 @@ public: const LocationContext *LCtx, QualType type, unsigned count); - DefinedOrUnknownSVal conjureSymbolVal(const Stmt *stmt, const LocationContext *LCtx, QualType type, unsigned visitCount); + /// \brief Conjure a symbol representing heap allocated memory region. /// /// Note, the expression should represent a location. @@ -362,8 +380,8 @@ SValBuilder* createSimpleSValBuilder(llvm::BumpPtrAllocator &alloc, ASTContext &context, ProgramStateManager &stateMgr); -} // end GR namespace +} // namespace ento -} // end clang namespace +} // namespace clang -#endif +#endif // LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SVALBUILDER_H diff --git a/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h b/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h index 06132587b4..29e44b377c 100644 --- a/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h +++ b/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h @@ -1,4 +1,4 @@ -//== SVals.h - Abstract Values for Static Analysis ---------*- C++ -*--==// +//===- SVals.h - Abstract Values for Static Analysis ------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -16,11 +16,18 @@ #define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SVALS_H #include "clang/AST/Expr.h" +#include "clang/AST/Type.h" #include "clang/Basic/LLVM.h" -#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState_Fwd.h" #include "clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h" #include "llvm/ADT/FoldingSet.h" #include "llvm/ADT/ImmutableList.h" +#include "llvm/ADT/None.h" +#include "llvm/ADT/Optional.h" +#include "llvm/ADT/PointerUnion.h" +#include "llvm/Support/Casting.h" +#include +#include +#include //==------------------------------------------------------------------------==// // Base SVal types. @@ -28,34 +35,40 @@ namespace clang { +class CXXBaseSpecifier; +class DeclaratorDecl; +class FunctionDecl; +class LabelDecl; + namespace ento { +class BasicValueFactory; class CompoundValData; class LazyCompoundValData; -class PointerToMemberData; -class ProgramState; -class BasicValueFactory; class MemRegion; -class TypedValueRegion; -class MemRegionManager; -class ProgramStateManager; +class PointerToMemberData; class SValBuilder; +class TypedValueRegion; namespace nonloc { + /// Sub-kinds for NonLoc values. enum Kind { #define NONLOC_SVAL(Id, Parent) Id ## Kind, #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.def" }; -} + +} // namespace nonloc namespace loc { + /// Sub-kinds for Loc values. enum Kind { #define LOC_SVAL(Id, Parent) Id ## Kind, #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.def" }; -} + +} // namespace loc /// SVal - This represents a symbolic expression, which can be either /// an L-value or an R-value. @@ -71,20 +84,19 @@ public: enum { BaseBits = 2, BaseMask = 0x3 }; protected: - const void *Data; + const void *Data = nullptr; /// The lowest 2 bits are a BaseKind (0 -- 3). /// The higher bits are an unsigned "kind" value. - unsigned Kind; + unsigned Kind = 0; explicit SVal(const void *d, bool isLoc, unsigned ValKind) - : Data(d), Kind((isLoc ? LocKind : NonLocKind) | (ValKind << BaseBits)) {} + : Data(d), Kind((isLoc ? LocKind : NonLocKind) | (ValKind << BaseBits)) {} - explicit SVal(BaseKind k, const void *D = nullptr) - : Data(D), Kind(k) {} + explicit SVal(BaseKind k, const void *D = nullptr) : Data(D), Kind(k) {} public: - explicit SVal() : Data(nullptr), Kind(0) {} + explicit SVal() = default; /// \brief Convert to the specified SVal type, asserting that this SVal is of /// the desired type. @@ -103,38 +115,38 @@ public: return *static_cast(this); } - inline unsigned getRawKind() const { return Kind; } - inline BaseKind getBaseKind() const { return (BaseKind) (Kind & BaseMask); } - inline unsigned getSubKind() const { return (Kind & ~BaseMask) >> BaseBits; } + unsigned getRawKind() const { return Kind; } + BaseKind getBaseKind() const { return (BaseKind) (Kind & BaseMask); } + unsigned getSubKind() const { return (Kind & ~BaseMask) >> BaseBits; } // This method is required for using SVal in a FoldingSetNode. It // extracts a unique signature for this SVal object. - inline void Profile(llvm::FoldingSetNodeID& ID) const { + void Profile(llvm::FoldingSetNodeID &ID) const { ID.AddInteger((unsigned) getRawKind()); ID.AddPointer(Data); } - inline bool operator==(const SVal& R) const { + bool operator==(const SVal &R) const { return getRawKind() == R.getRawKind() && Data == R.Data; } - inline bool operator!=(const SVal& R) const { + bool operator!=(const SVal &R) const { return !(*this == R); } - inline bool isUnknown() const { + bool isUnknown() const { return getRawKind() == UnknownValKind; } - inline bool isUndef() const { + bool isUndef() const { return getRawKind() == UndefinedValKind; } - inline bool isUnknownOrUndef() const { + bool isUnknownOrUndef() const { return getRawKind() <= UnknownValKind; } - inline bool isValid() const { + bool isValid() const { return getRawKind() > UnknownValKind; } @@ -175,7 +187,7 @@ public: /// return that expression. Otherwise return NULL. const SymExpr *getAsSymbolicExpression() const; - const SymExpr* getAsSymExpr() const; + const SymExpr *getAsSymExpr() const; const MemRegion *getAsRegion() const; @@ -206,28 +218,28 @@ public: private: friend class SVal; + static bool isKind(const SVal& V) { return V.getBaseKind() == UndefinedValKind; } }; class DefinedOrUnknownSVal : public SVal { -private: +public: // We want calling these methods to be a compiler error since they are // tautologically false. bool isUndef() const = delete; bool isValid() const = delete; protected: - DefinedOrUnknownSVal() {} + DefinedOrUnknownSVal() = default; explicit DefinedOrUnknownSVal(const void *d, bool isLoc, unsigned ValKind) - : SVal(d, isLoc, ValKind) {} - - explicit DefinedOrUnknownSVal(BaseKind k, void *D = nullptr) - : SVal(k, D) {} + : SVal(d, isLoc, ValKind) {} + explicit DefinedOrUnknownSVal(BaseKind k, void *D = nullptr) : SVal(k, D) {} private: friend class SVal; + static bool isKind(const SVal& V) { return !V.isUndef(); } @@ -239,37 +251,43 @@ public: private: friend class SVal; + static bool isKind(const SVal &V) { return V.getBaseKind() == UnknownValKind; } }; class DefinedSVal : public DefinedOrUnknownSVal { -private: +public: // We want calling these methods to be a compiler error since they are // tautologically true/false. bool isUnknown() const = delete; bool isUnknownOrUndef() const = delete; bool isValid() const = delete; + protected: - DefinedSVal() {} + DefinedSVal() = default; explicit DefinedSVal(const void *d, bool isLoc, unsigned ValKind) - : DefinedOrUnknownSVal(d, isLoc, ValKind) {} + : DefinedOrUnknownSVal(d, isLoc, ValKind) {} + private: friend class SVal; + static bool isKind(const SVal& V) { return !V.isUnknownOrUndef(); } }; - /// \brief Represents an SVal that is guaranteed to not be UnknownVal. class KnownSVal : public SVal { - KnownSVal() {} friend class SVal; + + KnownSVal() = default; + static bool isKind(const SVal &V) { return !V.isUnknown(); } + public: KnownSVal(const DefinedSVal &V) : SVal(V) {} KnownSVal(const UndefinedVal &V) : SVal(V) {} @@ -277,20 +295,21 @@ public: class NonLoc : public DefinedSVal { protected: - NonLoc() {} + NonLoc() = default; explicit NonLoc(unsigned SubKind, const void *d) - : DefinedSVal(d, false, SubKind) {} + : DefinedSVal(d, false, SubKind) {} public: void dumpToStream(raw_ostream &Out) const; - static inline bool isCompoundType(QualType T) { + static bool isCompoundType(QualType T) { return T->isArrayType() || T->isRecordType() || T->isComplexType() || T->isVectorType(); } private: friend class SVal; + static bool isKind(const SVal& V) { return V.getBaseKind() == NonLocKind; } @@ -298,20 +317,21 @@ private: class Loc : public DefinedSVal { protected: - Loc() {} + Loc() = default; explicit Loc(unsigned SubKind, const void *D) - : DefinedSVal(const_cast(D), true, SubKind) {} + : DefinedSVal(const_cast(D), true, SubKind) {} public: void dumpToStream(raw_ostream &Out) const; - static inline bool isLocType(QualType T) { + static bool isLocType(QualType T) { return T->isAnyPointerType() || T->isBlockPointerType() || T->isReferenceType() || T->isNullPtrType(); } private: friend class SVal; + static bool isKind(const SVal& V) { return V.getBaseKind() == LocKind; } @@ -330,7 +350,7 @@ public: SymbolVal(SymbolRef sym) : NonLoc(SymbolValKind, sym) { assert(sym); } SymbolRef getSymbol() const { - return (const SymExpr*) Data; + return (const SymExpr *) Data; } bool isExpression() const { @@ -339,6 +359,7 @@ public: private: friend class SVal; + static bool isKind(const SVal& V) { return V.getBaseKind() == NonLocKind && V.getSubKind() == SymbolValKind; @@ -355,7 +376,7 @@ public: explicit ConcreteInt(const llvm::APSInt& V) : NonLoc(ConcreteIntKind, &V) {} const llvm::APSInt& getValue() const { - return *static_cast(Data); + return *static_cast(Data); } // Transfer functions for binary/unary operations on ConcreteInts. @@ -368,7 +389,9 @@ public: private: friend class SVal; - ConcreteInt() {} + + ConcreteInt() = default; + static bool isKind(const SVal& V) { return V.getBaseKind() == NonLocKind && V.getSubKind() == ConcreteIntKind; @@ -392,7 +415,6 @@ class LocAsInteger : public NonLoc { } public: - Loc getLoc() const { const std::pair *D = static_cast *>(Data); @@ -414,7 +436,9 @@ public: private: friend class SVal; - LocAsInteger() {} + + LocAsInteger() = default; + static bool isKind(const SVal& V) { return V.getBaseKind() == NonLocKind && V.getSubKind() == LocAsIntegerKind; @@ -432,16 +456,19 @@ class CompoundVal : public NonLoc { public: const CompoundValData* getValue() const { - return static_cast(Data); + return static_cast(Data); } - typedef llvm::ImmutableList::iterator iterator; + using iterator = llvm::ImmutableList::iterator; + iterator begin() const; iterator end() const; private: friend class SVal; - CompoundVal() {} + + CompoundVal() = default; + static bool isKind(const SVal& V) { return V.getBaseKind() == NonLocKind && V.getSubKind() == CompoundValKind; } @@ -455,21 +482,26 @@ class LazyCompoundVal : public NonLoc { friend class ento::SValBuilder; explicit LazyCompoundVal(const LazyCompoundValData *D) - : NonLoc(LazyCompoundValKind, D) {} + : NonLoc(LazyCompoundValKind, D) {} + public: const LazyCompoundValData *getCVData() const { - return static_cast(Data); + return static_cast(Data); } + const void *getStore() const; const TypedValueRegion *getRegion() const; private: friend class SVal; - LazyCompoundVal() {} + + LazyCompoundVal() = default; + static bool isKind(const SVal& V) { return V.getBaseKind() == NonLocKind && V.getSubKind() == LazyCompoundValKind; } + static bool isKind(const NonLoc& V) { return V.getSubKind() == LazyCompoundValKind; } @@ -488,28 +520,36 @@ class PointerToMember : public NonLoc { friend class ento::SValBuilder; public: - typedef llvm::PointerUnion PTMDataType; + using PTMDataType = + llvm::PointerUnion; + const PTMDataType getPTMData() const { return PTMDataType::getFromOpaqueValue(const_cast(Data)); } + bool isNullMemberPointer() const { return getPTMData().isNull(); } + const DeclaratorDecl *getDecl() const; + template - const AdjustedDecl* getDeclAs() const { + const AdjustedDecl *getDeclAs() const { return dyn_cast_or_null(getDecl()); } - typedef llvm::ImmutableList::iterator iterator; + + using iterator = llvm::ImmutableList::iterator; + iterator begin() const; iterator end() const; private: - explicit PointerToMember(const PTMDataType D) - : NonLoc(PointerToMemberKind, D.getOpaqueValue()) {} friend class SVal; - PointerToMember() {} + + PointerToMember() = default; + explicit PointerToMember(const PTMDataType D) + : NonLoc(PointerToMemberKind, D.getOpaqueValue()) {} + static bool isKind(const SVal& V) { return V.getBaseKind() == NonLocKind && V.getSubKind() == PointerToMemberKind; @@ -520,7 +560,7 @@ private: } }; -} // end namespace ento::nonloc +} // namespace nonloc //==------------------------------------------------------------------------==// // Subclasses of Loc. @@ -535,12 +575,14 @@ public: } const LabelDecl *getLabel() const { - return static_cast(Data); + return static_cast(Data); } private: friend class SVal; - GotoLabel() {} + + GotoLabel() = default; + static bool isKind(const SVal& V) { return V.getBaseKind() == LocKind && V.getSubKind() == GotoLabelKind; } @@ -550,7 +592,6 @@ private: } }; - class MemRegionVal : public Loc { public: explicit MemRegionVal(const MemRegion* r) : Loc(MemRegionValKind, r) { @@ -558,8 +599,8 @@ public: } /// \brief Get the underlining region. - const MemRegion* getRegion() const { - return static_cast(Data); + const MemRegion *getRegion() const { + return static_cast(Data); } /// \brief Get the underlining region and strip casts. @@ -570,17 +611,19 @@ public: return dyn_cast(getRegion()); } - inline bool operator==(const MemRegionVal& R) const { + bool operator==(const MemRegionVal &R) const { return getRegion() == R.getRegion(); } - inline bool operator!=(const MemRegionVal& R) const { + bool operator!=(const MemRegionVal &R) const { return getRegion() != R.getRegion(); } private: friend class SVal; - MemRegionVal() {} + + MemRegionVal() = default; + static bool isKind(const SVal& V) { return V.getBaseKind() == LocKind && V.getSubKind() == MemRegionValKind; @@ -595,8 +638,8 @@ class ConcreteInt : public Loc { public: explicit ConcreteInt(const llvm::APSInt& V) : Loc(ConcreteIntKind, &V) {} - const llvm::APSInt& getValue() const { - return *static_cast(Data); + const llvm::APSInt &getValue() const { + return *static_cast(Data); } // Transfer functions for binary/unary operations on ConcreteInts. @@ -605,7 +648,9 @@ public: private: friend class SVal; - ConcreteInt() {} + + ConcreteInt() = default; + static bool isKind(const SVal& V) { return V.getBaseKind() == LocKind && V.getSubKind() == ConcreteIntKind; @@ -616,11 +661,11 @@ private: } }; -} // end ento::loc namespace +} // namespace loc -} // end ento namespace +} // namespace ento -} // end clang namespace +} // namespace clang namespace llvm { @@ -629,6 +674,6 @@ template <> struct isPodLike { static const bool value = true; }; -} // end llvm namespace +} // namespace llvm -#endif +#endif // LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SVALS_H diff --git a/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h b/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h index 7d2e5ad8ba..f222e832ed 100644 --- a/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h +++ b/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h @@ -1,4 +1,4 @@ -//== SymbolManager.h - Management of Symbolic Values ------------*- C++ -*--==// +//===- SymbolManager.h - Management of Symbolic Values ----------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -15,8 +15,8 @@ #ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SYMBOLMANAGER_H #define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SYMBOLMANAGER_H -#include "clang/AST/Decl.h" #include "clang/AST/Expr.h" +#include "clang/AST/Type.h" #include "clang/Analysis/AnalysisDeclContext.h" #include "clang/Basic/LLVM.h" #include "clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h" @@ -26,17 +26,17 @@ #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/FoldingSet.h" #include "llvm/Support/Allocator.h" -#include "llvm/Support/DataTypes.h" +#include namespace clang { - class ASTContext; - class StackFrameContext; + +class ASTContext; +class Stmt; namespace ento { - class BasicValueFactory; - class SubRegion; - class TypedValueRegion; - class VarRegion; + +class BasicValueFactory; +class StoreManager; ///\brief A symbol representing the value stored at a MemRegion. class SymbolRegionValue : public SymbolData { @@ -66,7 +66,7 @@ public: QualType getType() const override; // Implement isa support. - static inline bool classof(const SymExpr *SE) { + static bool classof(const SymExpr *SE) { return SE->getKind() == SymbolRegionValueKind; } }; @@ -118,7 +118,7 @@ public: } // Implement isa support. - static inline bool classof(const SymExpr *SE) { + static bool classof(const SymExpr *SE) { return SE->getKind() == SymbolConjuredKind; } }; @@ -157,7 +157,7 @@ public: } // Implement isa support. - static inline bool classof(const SymExpr *SE) { + static bool classof(const SymExpr *SE) { return SE->getKind() == SymbolDerivedKind; } }; @@ -190,7 +190,7 @@ public: } // Implement isa support. - static inline bool classof(const SymExpr *SE) { + static bool classof(const SymExpr *SE) { return SE->getKind() == SymbolExtentKind; } }; @@ -206,11 +206,12 @@ class SymbolMetadata : public SymbolData { const LocationContext *LCtx; unsigned Count; const void *Tag; + public: SymbolMetadata(SymbolID sym, const MemRegion* r, const Stmt *s, QualType t, const LocationContext *LCtx, unsigned count, const void *tag) - : SymbolData(SymbolMetadataKind, sym), R(r), S(s), T(t), LCtx(LCtx), - Count(count), Tag(tag) { + : SymbolData(SymbolMetadataKind, sym), R(r), S(s), T(t), LCtx(LCtx), + Count(count), Tag(tag) { assert(r); assert(s); assert(isValidTypeForSymbol(t)); @@ -245,7 +246,7 @@ public: } // Implement isa support. - static inline bool classof(const SymExpr *SE) { + static bool classof(const SymExpr *SE) { return SE->getKind() == SymbolMetadataKind; } }; @@ -253,8 +254,10 @@ public: /// \brief Represents a cast expression. class SymbolCast : public SymExpr { const SymExpr *Operand; + /// Type of the operand. QualType FromTy; + /// The type of the result. QualType ToTy; @@ -286,7 +289,7 @@ public: } // Implement isa support. - static inline bool classof(const SymExpr *SE) { + static bool classof(const SymExpr *SE) { return SE->getKind() == SymbolCastKind; } }; @@ -311,7 +314,7 @@ public: BinaryOperator::Opcode getOpcode() const { return Op; } // Implement isa support. - static inline bool classof(const SymExpr *SE) { + static bool classof(const SymExpr *SE) { Kind k = SE->getKind(); return k >= BEGIN_BINARYSYMEXPRS && k <= END_BINARYSYMEXPRS; } @@ -349,7 +352,7 @@ public: } // Implement isa support. - static inline bool classof(const SymExpr *SE) { + static bool classof(const SymExpr *SE) { return SE->getKind() == SymIntExprKind; } }; @@ -386,7 +389,7 @@ public: } // Implement isa support. - static inline bool classof(const SymExpr *SE) { + static bool classof(const SymExpr *SE) { return SE->getKind() == IntSymExprKind; } }; @@ -423,20 +426,22 @@ public: } // Implement isa support. - static inline bool classof(const SymExpr *SE) { + static bool classof(const SymExpr *SE) { return SE->getKind() == SymSymExprKind; } }; class SymbolManager { - typedef llvm::FoldingSet DataSetTy; - typedef llvm::DenseMap SymbolDependTy; + using DataSetTy = llvm::FoldingSet; + using SymbolDependTy = llvm::DenseMap; DataSetTy DataSet; + /// Stores the extra dependencies between symbols: the data should be kept /// alive as long as the key is live. SymbolDependTy SymbolDependencies; - unsigned SymbolCounter; + + unsigned SymbolCounter = 0; llvm::BumpPtrAllocator& BPAlloc; BasicValueFactory &BV; ASTContext &Ctx; @@ -444,9 +449,7 @@ class SymbolManager { public: SymbolManager(ASTContext &ctx, BasicValueFactory &bv, llvm::BumpPtrAllocator& bpalloc) - : SymbolDependencies(16), SymbolCounter(0), - BPAlloc(bpalloc), BV(bv), Ctx(ctx) {} - + : SymbolDependencies(16), BPAlloc(bpalloc), BV(bv), Ctx(ctx) {} ~SymbolManager(); static bool canSymbolicate(QualType T); @@ -522,9 +525,9 @@ class SymbolReaper { HaveMarkedDependents }; - typedef llvm::DenseSet SymbolSetTy; - typedef llvm::DenseMap SymbolMapTy; - typedef llvm::DenseSet RegionSetTy; + using SymbolSetTy = llvm::DenseSet; + using SymbolMapTy = llvm::DenseMap; + using RegionSetTy = llvm::DenseSet; SymbolMapTy TheLiving; SymbolSetTy MetadataInUse; @@ -546,10 +549,9 @@ public: /// considered live. /// If the stack frame context is NULL, everything on stack is considered /// dead. - SymbolReaper(const StackFrameContext *Ctx, const Stmt *s, SymbolManager& symmgr, - StoreManager &storeMgr) - : LCtx(Ctx), Loc(s), SymMgr(symmgr), - reapedStore(nullptr, storeMgr) {} + SymbolReaper(const StackFrameContext *Ctx, const Stmt *s, + SymbolManager &symmgr, StoreManager &storeMgr) + : LCtx(Ctx), Loc(s), SymMgr(symmgr), reapedStore(nullptr, storeMgr) {} const LocationContext *getLocationContext() const { return LCtx; } @@ -580,7 +582,8 @@ public: /// Returns true if the symbol is dead, false if live. bool maybeDead(SymbolRef sym); - typedef SymbolSetTy::const_iterator dead_iterator; + using dead_iterator = SymbolSetTy::const_iterator; + dead_iterator dead_begin() const { return TheDead.begin(); } dead_iterator dead_end() const { return TheDead.end(); } @@ -588,7 +591,8 @@ public: return !TheDead.empty(); } - typedef RegionSetTy::const_iterator region_iterator; + using region_iterator = RegionSetTy::const_iterator; + region_iterator region_begin() const { return RegionRoots.begin(); } region_iterator region_end() const { return RegionRoots.end(); } @@ -629,8 +633,8 @@ public: virtual bool VisitMemRegion(const MemRegion *region) { return true; } }; -} // end GR namespace +} // namespace ento -} // end clang namespace +} // namespace clang -#endif +#endif // LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SYMBOLMANAGER_H diff --git a/lib/StaticAnalyzer/Core/SValBuilder.cpp b/lib/StaticAnalyzer/Core/SValBuilder.cpp index f49995d50c..ab5ec9f12f 100644 --- a/lib/StaticAnalyzer/Core/SValBuilder.cpp +++ b/lib/StaticAnalyzer/Core/SValBuilder.cpp @@ -1,4 +1,4 @@ -// SValBuilder.cpp - Basic class for all SValBuilder implementations -*- C++ -*- +//===- SValBuilder.cpp - Basic class for all SValBuilder implementations --===// // // The LLVM Compiler Infrastructure // @@ -13,12 +13,31 @@ //===----------------------------------------------------------------------===// #include "clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h" +#include "clang/AST/ASTContext.h" +#include "clang/AST/Decl.h" #include "clang/AST/DeclCXX.h" #include "clang/AST/ExprCXX.h" +#include "clang/AST/ExprObjC.h" +#include "clang/AST/Stmt.h" +#include "clang/AST/Type.h" +#include "clang/Basic/LLVM.h" +#include "clang/Analysis/AnalysisDeclContext.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/APSIntType.h" #include "clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h" #include "clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h" #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState_Fwd.h" #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/Store.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h" +#include "llvm/ADT/APSInt.h" +#include "llvm/ADT/None.h" +#include "llvm/ADT/Optional.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/Compiler.h" +#include +#include using namespace clang; using namespace ento; @@ -27,7 +46,7 @@ using namespace ento; // Basic SVal creation. //===----------------------------------------------------------------------===// -void SValBuilder::anchor() { } +void SValBuilder::anchor() {} DefinedOrUnknownSVal SValBuilder::makeZeroVal(QualType type) { if (Loc::isLocType(type)) @@ -95,7 +114,7 @@ nonloc::ConcreteInt SValBuilder::makeBoolVal(const CXXBoolLiteralExpr *boolean){ } DefinedOrUnknownSVal -SValBuilder::getRegionValueSymbolVal(const TypedValueRegion* region) { +SValBuilder::getRegionValueSymbolVal(const TypedValueRegion *region) { QualType T = region->getValueType(); if (T->isNullPtrType()) @@ -149,7 +168,6 @@ DefinedOrUnknownSVal SValBuilder::conjureSymbolVal(const void *symbolTag, return nonloc::SymbolVal(sym); } - DefinedOrUnknownSVal SValBuilder::conjureSymbolVal(const Stmt *stmt, const LocationContext *LCtx, QualType type, @@ -217,10 +235,10 @@ SValBuilder::getDerivedRegionValueSymbolVal(SymbolRef parentSymbol, return nonloc::SymbolVal(sym); } -DefinedSVal SValBuilder::getMemberPointer(const DeclaratorDecl* DD) { +DefinedSVal SValBuilder::getMemberPointer(const DeclaratorDecl *DD) { assert(!DD || isa(DD) || isa(DD)); - if (auto *MD = dyn_cast_or_null(DD)) { + if (const auto *MD = dyn_cast_or_null(DD)) { // Sema treats pointers to static member functions as have function pointer // type, so return a function pointer for the method. // We don't need to play a similar trick for static member fields @@ -277,19 +295,19 @@ Optional SValBuilder::getConstantVal(const Expr *E) { return makeZeroVal(E->getType()); case Stmt::ObjCStringLiteralClass: { - const ObjCStringLiteral *SL = cast(E); + const auto *SL = cast(E); return makeLoc(getRegionManager().getObjCStringRegion(SL)); } case Stmt::StringLiteralClass: { - const StringLiteral *SL = cast(E); + const auto *SL = cast(E); return makeLoc(getRegionManager().getStringRegion(SL)); } // Fast-path some expressions to avoid the overhead of going through the AST's // constant evaluator case Stmt::CharacterLiteralClass: { - const CharacterLiteral *C = cast(E); + const auto *C = cast(E); return makeIntVal(C->getValue(), C->getType()); } @@ -297,7 +315,7 @@ Optional SValBuilder::getConstantVal(const Expr *E) { return makeBoolVal(cast(E)); case Stmt::TypeTraitExprClass: { - const TypeTraitExpr *TE = cast(E); + const auto *TE = cast(E); return makeTruthVal(TE->getValue(), TE->getType()); } @@ -311,7 +329,7 @@ Optional SValBuilder::getConstantVal(const Expr *E) { return makeNull(); case Stmt::ImplicitCastExprClass: { - const CastExpr *CE = cast(E); + const auto *CE = cast(E); switch (CE->getCastKind()) { default: break; @@ -348,8 +366,6 @@ Optional SValBuilder::getConstantVal(const Expr *E) { } } -//===----------------------------------------------------------------------===// - SVal SValBuilder::makeSymExprValNN(ProgramStateRef State, BinaryOperator::Opcode Op, NonLoc LHS, NonLoc RHS, @@ -378,10 +394,8 @@ SVal SValBuilder::makeSymExprValNN(ProgramStateRef State, return UnknownVal(); } - SVal SValBuilder::evalBinOp(ProgramStateRef state, BinaryOperator::Opcode op, SVal lhs, SVal rhs, QualType type) { - if (lhs.isUndef() || rhs.isUndef()) return UndefinedVal(); @@ -463,7 +477,6 @@ static bool shouldBeModeledWithNoOp(ASTContext &Context, QualType ToTy, // of the original value is known to be greater than the max of the target type. SVal SValBuilder::evalIntegralCast(ProgramStateRef state, SVal val, QualType castTy, QualType originalTy) { - // No truncations if target type is big enough. if (getContext().getTypeSize(castTy) >= getContext().getTypeSize(originalTy)) return evalCast(val, castTy, originalTy); @@ -557,8 +570,8 @@ SVal SValBuilder::evalCast(SVal val, QualType castTy, QualType originalTy) { } // Check for casts from array type to another type. - if (const ArrayType *arrayT = - dyn_cast(originalTy.getCanonicalType())) { + if (const auto *arrayT = + dyn_cast(originalTy.getCanonicalType())) { // We will always decay to a pointer. QualType elemTy = arrayT->getElementType(); val = StateMgr.ArrayToPointer(val.castAs(), elemTy); diff --git a/lib/StaticAnalyzer/Core/SVals.cpp b/lib/StaticAnalyzer/Core/SVals.cpp index a83421426a..a75376543e 100644 --- a/lib/StaticAnalyzer/Core/SVals.cpp +++ b/lib/StaticAnalyzer/Core/SVals.cpp @@ -1,4 +1,4 @@ -//= RValues.cpp - Abstract RValues for Path-Sens. Value Tracking -*- C++ -*-==// +//===- RValues.cpp - Abstract RValues for Path-Sens. Value Tracking -------===// // // The LLVM Compiler Infrastructure // @@ -12,20 +12,31 @@ // //===----------------------------------------------------------------------===// -#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h" -#include "clang/AST/ExprObjC.h" -#include "clang/Basic/IdentifierTable.h" -#include "llvm/Support/raw_ostream.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h" +#include "clang/AST/Decl.h" #include "clang/AST/DeclCXX.h" +#include "clang/AST/Expr.h" +#include "clang/AST/Type.h" +#include "clang/Basic/LLVM.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h" +#include "llvm/ADT/Optional.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/Compiler.h" +#include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/raw_ostream.h" +#include + using namespace clang; using namespace ento; -using llvm::APSInt; //===----------------------------------------------------------------------===// // Symbol iteration within an SVal. //===----------------------------------------------------------------------===// - //===----------------------------------------------------------------------===// // Utility methods. //===----------------------------------------------------------------------===// @@ -39,7 +50,7 @@ bool SVal::hasConjuredSymbol() const { if (Optional RV = getAs()) { const MemRegion *R = RV->getRegion(); - if (const SymbolicRegion *SR = dyn_cast(R)) { + if (const auto *SR = dyn_cast(R)) { SymbolRef sym = SR->getSymbol(); if (isa(sym)) return true; @@ -53,12 +64,12 @@ const FunctionDecl *SVal::getAsFunctionDecl() const { if (Optional X = getAs()) { const MemRegion* R = X->getRegion(); if (const FunctionCodeRegion *CTR = R->getAs()) - if (const FunctionDecl *FD = dyn_cast(CTR->getDecl())) + if (const auto *FD = dyn_cast(CTR->getDecl())) return FD; } if (auto X = getAs()) { - if (const CXXMethodDecl *MD = dyn_cast_or_null(X->getDecl())) + if (const auto *MD = dyn_cast_or_null(X->getDecl())) return MD; } return nullptr; @@ -95,8 +106,8 @@ SymbolRef SVal::getLocSymbolInBase() const { const MemRegion *R = X->getRegion(); - while (const SubRegion *SR = dyn_cast(R)) { - if (const SymbolicRegion *SymR = dyn_cast(SR)) + while (const auto *SR = dyn_cast(R)) { + if (const auto *SymR = dyn_cast(SR)) return SymR->getSymbol(); else R = SR->getSuperRegion(); @@ -189,14 +200,14 @@ nonloc::CompoundVal::iterator nonloc::CompoundVal::end() const { nonloc::PointerToMember::iterator nonloc::PointerToMember::begin() const { const PTMDataType PTMD = getPTMData(); if (PTMD.is()) - return nonloc::PointerToMember::iterator(); + return {}; return PTMD.get()->begin(); } nonloc::PointerToMember::iterator nonloc::PointerToMember::end() const { const PTMDataType PTMD = getPTMData(); if (PTMD.is()) - return nonloc::PointerToMember::iterator(); + return {}; return PTMD.get()->end(); } @@ -220,7 +231,6 @@ bool SVal::isZeroConstant() const { return isConstant(0); } - //===----------------------------------------------------------------------===// // Transfer function dispatch for Non-Locs. //===----------------------------------------------------------------------===// @@ -254,7 +264,6 @@ nonloc::ConcreteInt::evalMinus(SValBuilder &svalBuilder) const { SVal loc::ConcreteInt::evalBinOp(BasicValueFactory& BasicVals, BinaryOperator::Opcode Op, const loc::ConcreteInt& R) const { - assert(BinaryOperator::isComparisonOp(Op) || Op == BO_Sub); const llvm::APSInt *X = BasicVals.evalAPSInt(Op, getValue(), R.getValue()); @@ -300,10 +309,10 @@ void NonLoc::dumpToStream(raw_ostream &os) const { << C.getValue().getBitWidth() << 'b'; break; } - case nonloc::SymbolValKind: { + case nonloc::SymbolValKind: os << castAs().getSymbol(); break; - } + case nonloc::LocAsIntegerKind: { const nonloc::LocAsInteger& C = castAs(); os << C.getLoc() << " [as " << C.getNumBits() << " bit integer]"; @@ -313,14 +322,14 @@ void NonLoc::dumpToStream(raw_ostream &os) const { const nonloc::CompoundVal& C = castAs(); os << "compoundVal{"; bool first = true; - for (nonloc::CompoundVal::iterator I=C.begin(), E=C.end(); I!=E; ++I) { + for (const auto &I : C) { if (first) { os << ' '; first = false; } else os << ", "; - (*I).dumpToStream(os); + I.dumpToStream(os); } os << "}"; break; @@ -353,7 +362,7 @@ void NonLoc::dumpToStream(raw_ostream &os) const { break; } default: - assert (false && "Pretty-printed not implemented for this NonLoc."); + assert(false && "Pretty-printed not implemented for this NonLoc."); break; } } diff --git a/lib/StaticAnalyzer/Core/SymbolManager.cpp b/lib/StaticAnalyzer/Core/SymbolManager.cpp index f2d5ee83f3..d18f83cb06 100644 --- a/lib/StaticAnalyzer/Core/SymbolManager.cpp +++ b/lib/StaticAnalyzer/Core/SymbolManager.cpp @@ -1,4 +1,4 @@ -//== SymbolManager.h - Management of Symbolic Values ------------*- C++ -*--==// +//===- SymbolManager.h - Management of Symbolic Values --------------------===// // // The LLVM Compiler Infrastructure // @@ -13,15 +13,27 @@ //===----------------------------------------------------------------------===// #include "clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h" +#include "clang/AST/ASTContext.h" +#include "clang/AST/Expr.h" #include "clang/Analysis/Analyses/LiveVariables.h" +#include "clang/Analysis/AnalysisDeclContext.h" +#include "clang/Basic/LLVM.h" #include "clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h" #include "clang/StaticAnalyzer/Core/PathSensitive/Store.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h" +#include "llvm/ADT/FoldingSet.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/Compiler.h" +#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/raw_ostream.h" +#include using namespace clang; using namespace ento; -void SymExpr::anchor() { } +void SymExpr::anchor() {} LLVM_DUMP_METHOD void SymExpr::dump() const { dumpToStream(llvm::errs()); @@ -88,7 +100,7 @@ void SymbolMetadata::dumpToStream(raw_ostream &os) const { << getRegion() << ',' << T.getAsString() << '}'; } -void SymbolData::anchor() { } +void SymbolData::anchor() {} void SymbolRegionValue::dumpToStream(raw_ostream &os) const { os << "reg_$" << getSymbolID() @@ -138,7 +150,7 @@ void SymExpr::symbol_iterator::expand() { itr.push_back(cast(SE)->getRHS()); return; case SymExpr::SymSymExprKind: { - const SymSymExpr *x = cast(SE); + const auto *x = cast(SE); itr.push_back(x->getLHS()); itr.push_back(x->getRHS()); return; @@ -192,7 +204,6 @@ const SymbolConjured* SymbolManager::conjureSymbol(const Stmt *E, const SymbolDerived* SymbolManager::getDerivedSymbol(SymbolRef parentSymbol, const TypedValueRegion *R) { - llvm::FoldingSetNodeID profile; SymbolDerived::Profile(profile, parentSymbol, R); void *InsertPos; @@ -227,7 +238,6 @@ const SymbolMetadata * SymbolManager::getMetadataSymbol(const MemRegion* R, const Stmt *S, QualType T, const LocationContext *LCtx, unsigned Count, const void *SymbolTag) { - llvm::FoldingSetNodeID profile; SymbolMetadata::Profile(profile, R, S, T, LCtx, Count, SymbolTag); void *InsertPos; @@ -382,11 +392,10 @@ void SymbolReaper::markDependentsLive(SymbolRef sym) { LI->second = HaveMarkedDependents; if (const SymbolRefSmallVectorTy *Deps = SymMgr.getDependentSymbols(sym)) { - for (SymbolRefSmallVectorTy::const_iterator I = Deps->begin(), - E = Deps->end(); I != E; ++I) { - if (TheLiving.find(*I) != TheLiving.end()) + for (const auto I : *Deps) { + if (TheLiving.find(I) != TheLiving.end()) continue; - markLive(*I); + markLive(I); } } } @@ -405,7 +414,7 @@ void SymbolReaper::markLive(const MemRegion *region) { void SymbolReaper::markElementIndicesLive(const MemRegion *region) { for (auto SR = dyn_cast(region); SR; SR = dyn_cast(SR->getSuperRegion())) { - if (auto ER = dyn_cast(SR)) { + if (const auto ER = dyn_cast(SR)) { SVal Idx = ER->getIndex(); for (auto SI = Idx.symbol_begin(), SE = Idx.symbol_end(); SI != SE; ++SI) markLive(*SI); @@ -432,10 +441,10 @@ bool SymbolReaper::isLiveRegion(const MemRegion *MR) { MR = MR->getBaseRegion(); - if (const SymbolicRegion *SR = dyn_cast(MR)) + if (const auto *SR = dyn_cast(MR)) return isLive(SR->getSymbol()); - if (const VarRegion *VR = dyn_cast(MR)) + if (const auto *VR = dyn_cast(MR)) return isLive(VR, true); // FIXME: This is a gross over-approximation. What we really need is a way to @@ -547,7 +556,7 @@ bool SymbolReaper::isLive(const VarRegion *VR, bool includeStoreBindings) const{ return false; unsigned &cachedQuery = - const_cast(this)->includedRegionCache[VR]; + const_cast(this)->includedRegionCache[VR]; if (cachedQuery) { return cachedQuery == 1;