diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h --- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h +++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h @@ -100,7 +100,7 @@ /// the desired type. template T castAs() const { - assert(T::isKind(*this)); + assert(T::classof(*this)); return *static_cast(this); } @@ -108,7 +108,7 @@ /// not of the desired type. template Optional getAs() const { - if (!T::isKind(*this)) + if (!T::classof(*this)) return None; return *static_cast(this); } @@ -124,13 +124,11 @@ ID.AddPointer(Data); } - bool operator==(const SVal &R) const { + bool operator==(SVal R) const { return getRawKind() == R.getRawKind() && Data == R.Data; } - bool operator!=(const SVal &R) const { - return !(*this == R); - } + bool operator!=(SVal R) const { return !(*this == R); } bool isUnknown() const { return getRawKind() == UnknownValKind; @@ -224,12 +222,10 @@ public: UndefinedVal() : SVal(UndefinedValKind) {} + static bool classof(SVal V) { return V.getBaseKind() == UndefinedValKind; } + private: friend class SVal; - - static bool isKind(const SVal& V) { - return V.getBaseKind() == UndefinedValKind; - } }; class DefinedOrUnknownSVal : public SVal { @@ -239,6 +235,8 @@ bool isUndef() const = delete; bool isValid() const = delete; + static bool classof(SVal V) { return !V.isUndef(); } + protected: DefinedOrUnknownSVal() = default; explicit DefinedOrUnknownSVal(const void *d, bool isLoc, unsigned ValKind) @@ -247,22 +245,16 @@ private: friend class SVal; - - static bool isKind(const SVal& V) { - return !V.isUndef(); - } }; class UnknownVal : public DefinedOrUnknownSVal { public: explicit UnknownVal() : DefinedOrUnknownSVal(UnknownValKind) {} + static bool classof(SVal V) { return V.getBaseKind() == UnknownValKind; } + private: friend class SVal; - - static bool isKind(const SVal &V) { - return V.getBaseKind() == UnknownValKind; - } }; class DefinedSVal : public DefinedOrUnknownSVal { @@ -273,6 +265,8 @@ bool isUnknownOrUndef() const = delete; bool isValid() const = delete; + static bool classof(SVal V) { return !V.isUnknownOrUndef(); } + protected: DefinedSVal() = default; explicit DefinedSVal(const void *d, bool isLoc, unsigned ValKind) @@ -280,25 +274,17 @@ private: friend class SVal; - - static bool isKind(const SVal& V) { - return !V.isUnknownOrUndef(); - } }; /// Represents an SVal that is guaranteed to not be UnknownVal. class KnownSVal : public SVal { 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) {} + static bool classof(SVal V) { return !V.isUnknown(); } }; class NonLoc : public DefinedSVal { @@ -315,12 +301,10 @@ T->isAnyComplexType() || T->isVectorType(); } + static bool classof(SVal V) { return V.getBaseKind() == NonLocKind; } + private: friend class SVal; - - static bool isKind(const SVal& V) { - return V.getBaseKind() == NonLocKind; - } }; class Loc : public DefinedSVal { @@ -337,12 +321,10 @@ T->isReferenceType() || T->isNullPtrType(); } + static bool classof(SVal V) { return V.getBaseKind() == LocKind; } + private: friend class SVal; - - static bool isKind(const SVal& V) { - return V.getBaseKind() == LocKind; - } }; //==------------------------------------------------------------------------==// @@ -368,17 +350,14 @@ return !isa(getSymbol()); } -private: - friend class SVal; - - static bool isKind(const SVal& V) { - return V.getBaseKind() == NonLocKind && - V.getSubKind() == SymbolValKind; + static bool classof(SVal V) { + return V.getBaseKind() == NonLocKind && V.getSubKind() == SymbolValKind; } - static bool isKind(const NonLoc& V) { - return V.getSubKind() == SymbolValKind; - } + static bool classof(NonLoc V) { return V.getSubKind() == SymbolValKind; } + +private: + friend class SVal; }; /// Value representing integer constant. @@ -398,19 +377,15 @@ ConcreteInt evalMinus(SValBuilder &svalBuilder) const; + static bool classof(SVal V) { + return V.getBaseKind() == NonLocKind && V.getSubKind() == ConcreteIntKind; + } + + static bool classof(NonLoc V) { return V.getSubKind() == ConcreteIntKind; } + private: friend class SVal; - ConcreteInt() = default; - - static bool isKind(const SVal& V) { - return V.getBaseKind() == NonLocKind && - V.getSubKind() == ConcreteIntKind; - } - - static bool isKind(const NonLoc& V) { - return V.getSubKind() == ConcreteIntKind; - } }; class LocAsInteger : public NonLoc { @@ -445,19 +420,15 @@ return D->second; } + static bool classof(SVal V) { + return V.getBaseKind() == NonLocKind && V.getSubKind() == LocAsIntegerKind; + } + + static bool classof(NonLoc V) { return V.getSubKind() == LocAsIntegerKind; } + private: friend class SVal; - LocAsInteger() = default; - - static bool isKind(const SVal& V) { - return V.getBaseKind() == NonLocKind && - V.getSubKind() == LocAsIntegerKind; - } - - static bool isKind(const NonLoc& V) { - return V.getSubKind() == LocAsIntegerKind; - } }; class CompoundVal : public NonLoc { @@ -475,18 +446,15 @@ iterator begin() const; iterator end() const; -private: - friend class SVal; - - CompoundVal() = default; - - static bool isKind(const SVal& V) { + static bool classof(SVal V) { return V.getBaseKind() == NonLocKind && V.getSubKind() == CompoundValKind; } - static bool isKind(const NonLoc& V) { - return V.getSubKind() == CompoundValKind; - } + static bool classof(NonLoc V) { return V.getSubKind() == CompoundValKind; } + +private: + friend class SVal; + CompoundVal() = default; }; class LazyCompoundVal : public NonLoc { @@ -503,19 +471,18 @@ const void *getStore() const; const TypedValueRegion *getRegion() const; -private: - friend class SVal; - - LazyCompoundVal() = default; - - static bool isKind(const SVal& V) { + static bool classof(SVal V) { return V.getBaseKind() == NonLocKind && V.getSubKind() == LazyCompoundValKind; } - static bool isKind(const NonLoc& V) { + static bool classof(NonLoc V) { return V.getSubKind() == LazyCompoundValKind; } + +private: + friend class SVal; + LazyCompoundVal() = default; }; /// Value representing pointer-to-member. @@ -553,21 +520,21 @@ iterator begin() const; iterator end() const; -private: - friend class SVal; - - PointerToMember() = default; - explicit PointerToMember(const PTMDataType D) - : NonLoc(PointerToMemberKind, D.getOpaqueValue()) {} - - static bool isKind(const SVal& V) { + static bool classof(SVal V) { return V.getBaseKind() == NonLocKind && V.getSubKind() == PointerToMemberKind; } - static bool isKind(const NonLoc& V) { + static bool classof(NonLoc V) { return V.getSubKind() == PointerToMemberKind; } + +private: + friend class SVal; + + PointerToMember() = default; + explicit PointerToMember(const PTMDataType D) + : NonLoc(PointerToMemberKind, D.getOpaqueValue()) {} }; } // namespace nonloc @@ -588,18 +555,15 @@ return static_cast(Data); } -private: - friend class SVal; - - GotoLabel() = default; - - static bool isKind(const SVal& V) { + static bool classof(SVal V) { return V.getBaseKind() == LocKind && V.getSubKind() == GotoLabelKind; } - static bool isKind(const Loc& V) { - return V.getSubKind() == GotoLabelKind; - } + static bool classof(Loc V) { return V.getSubKind() == GotoLabelKind; } + +private: + friend class SVal; + GotoLabel() = default; }; class MemRegionVal : public Loc { @@ -629,19 +593,15 @@ return getRegion() != R.getRegion(); } + static bool classof(SVal V) { + return V.getBaseKind() == LocKind && V.getSubKind() == MemRegionValKind; + } + + static bool classof(Loc V) { return V.getSubKind() == MemRegionValKind; } + private: friend class SVal; - MemRegionVal() = default; - - static bool isKind(const SVal& V) { - return V.getBaseKind() == LocKind && - V.getSubKind() == MemRegionValKind; - } - - static bool isKind(const Loc& V) { - return V.getSubKind() == MemRegionValKind; - } }; class ConcreteInt : public Loc { @@ -656,25 +616,19 @@ SVal evalBinOp(BasicValueFactory& BasicVals, BinaryOperator::Opcode Op, const ConcreteInt& R) const; + static bool classof(SVal V) { + return V.getBaseKind() == LocKind && V.getSubKind() == ConcreteIntKind; + } + + static bool classof(Loc V) { return V.getSubKind() == ConcreteIntKind; } + private: friend class SVal; - ConcreteInt() = default; - - static bool isKind(const SVal& V) { - return V.getBaseKind() == LocKind && - V.getSubKind() == ConcreteIntKind; - } - - static bool isKind(const Loc& V) { - return V.getSubKind() == ConcreteIntKind; - } }; } // namespace loc - } // namespace ento - } // namespace clang #endif // LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SVALS_H