forked from OSchip/llvm-project
[llvm][analyzer][NFC] Introduce SFINAE for specializing FoldingSetTraits
Reviewed By: martong Differential Revision: https://reviews.llvm.org/D126803
This commit is contained in:
parent
cf1f1b7240
commit
7d24641f89
|
@ -24,7 +24,7 @@
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
|
||||||
class FoldingSetNodeID;
|
class FoldingSetNodeID;
|
||||||
template <typename T> struct FoldingSetTrait;
|
template <typename T, typename Enable> struct FoldingSetTrait;
|
||||||
|
|
||||||
} // namespace llvm
|
} // namespace llvm
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ class SourceLocation {
|
||||||
friend class ASTReader;
|
friend class ASTReader;
|
||||||
friend class ASTWriter;
|
friend class ASTWriter;
|
||||||
friend class SourceManager;
|
friend class SourceManager;
|
||||||
friend struct llvm::FoldingSetTrait<SourceLocation>;
|
friend struct llvm::FoldingSetTrait<SourceLocation, void>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using UIntTy = uint32_t;
|
using UIntTy = uint32_t;
|
||||||
|
@ -507,7 +507,7 @@ namespace llvm {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Allow calling FoldingSetNodeID::Add with SourceLocation object as parameter
|
// Allow calling FoldingSetNodeID::Add with SourceLocation object as parameter
|
||||||
template <> struct FoldingSetTrait<clang::SourceLocation> {
|
template <> struct FoldingSetTrait<clang::SourceLocation, void> {
|
||||||
static void Profile(const clang::SourceLocation &X, FoldingSetNodeID &ID);
|
static void Profile(const clang::SourceLocation &X, FoldingSetNodeID &ID);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -94,7 +94,7 @@ enum SelfFlagEnum {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
REGISTER_MAP_WITH_PROGRAMSTATE(SelfFlag, SymbolRef, unsigned)
|
REGISTER_MAP_WITH_PROGRAMSTATE(SelfFlag, SymbolRef, SelfFlagEnum)
|
||||||
REGISTER_TRAIT_WITH_PROGRAMSTATE(CalledInit, bool)
|
REGISTER_TRAIT_WITH_PROGRAMSTATE(CalledInit, bool)
|
||||||
|
|
||||||
/// A call receiving a reference to 'self' invalidates the object that
|
/// A call receiving a reference to 'self' invalidates the object that
|
||||||
|
@ -105,8 +105,8 @@ REGISTER_TRAIT_WITH_PROGRAMSTATE(PreCallSelfFlags, SelfFlagEnum)
|
||||||
|
|
||||||
static SelfFlagEnum getSelfFlags(SVal val, ProgramStateRef state) {
|
static SelfFlagEnum getSelfFlags(SVal val, ProgramStateRef state) {
|
||||||
if (SymbolRef sym = val.getAsSymbol())
|
if (SymbolRef sym = val.getAsSymbol())
|
||||||
if (const unsigned *attachedFlags = state->get<SelfFlag>(sym))
|
if (const SelfFlagEnum *attachedFlags = state->get<SelfFlag>(sym))
|
||||||
return (SelfFlagEnum)*attachedFlags;
|
return *attachedFlags;
|
||||||
return SelfFlag_None;
|
return SelfFlag_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,7 +118,8 @@ static void addSelfFlag(ProgramStateRef state, SVal val,
|
||||||
SelfFlagEnum flag, CheckerContext &C) {
|
SelfFlagEnum flag, CheckerContext &C) {
|
||||||
// We tag the symbol that the SVal wraps.
|
// We tag the symbol that the SVal wraps.
|
||||||
if (SymbolRef sym = val.getAsSymbol()) {
|
if (SymbolRef sym = val.getAsSymbol()) {
|
||||||
state = state->set<SelfFlag>(sym, getSelfFlags(val, state) | flag);
|
state = state->set<SelfFlag>(sym,
|
||||||
|
SelfFlagEnum(getSelfFlags(val, state) | flag));
|
||||||
C.addTransition(state);
|
C.addTransition(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -271,7 +272,7 @@ void ObjCSelfInitChecker::checkPostCall(const CallEvent &CE,
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ProgramStateRef state = C.getState();
|
ProgramStateRef state = C.getState();
|
||||||
SelfFlagEnum prevFlags = (SelfFlagEnum)state->get<PreCallSelfFlags>();
|
SelfFlagEnum prevFlags = state->get<PreCallSelfFlags>();
|
||||||
if (!prevFlags)
|
if (!prevFlags)
|
||||||
return;
|
return;
|
||||||
state = state->remove<PreCallSelfFlags>();
|
state = state->remove<PreCallSelfFlags>();
|
||||||
|
@ -339,7 +340,7 @@ void ObjCSelfInitChecker::printState(raw_ostream &Out, ProgramStateRef State,
|
||||||
const char *NL, const char *Sep) const {
|
const char *NL, const char *Sep) const {
|
||||||
SelfFlagTy FlagMap = State->get<SelfFlag>();
|
SelfFlagTy FlagMap = State->get<SelfFlag>();
|
||||||
bool DidCallInit = State->get<CalledInit>();
|
bool DidCallInit = State->get<CalledInit>();
|
||||||
SelfFlagEnum PreCallFlags = (SelfFlagEnum)State->get<PreCallSelfFlags>();
|
SelfFlagEnum PreCallFlags = State->get<PreCallSelfFlags>();
|
||||||
|
|
||||||
if (FlagMap.isEmpty() && !DidCallInit && !PreCallFlags)
|
if (FlagMap.isEmpty() && !DidCallInit && !PreCallFlags)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <type_traits>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
@ -256,8 +257,8 @@ template<typename T> struct DefaultFoldingSetTrait {
|
||||||
/// through template specialization the behavior can be tailored for specific
|
/// through template specialization the behavior can be tailored for specific
|
||||||
/// types. Combined with the FoldingSetNodeWrapper class, one can add objects
|
/// types. Combined with the FoldingSetNodeWrapper class, one can add objects
|
||||||
/// to FoldingSets that were not originally designed to have that behavior.
|
/// to FoldingSets that were not originally designed to have that behavior.
|
||||||
template<typename T> struct FoldingSetTrait
|
template <typename T, typename Enable = void>
|
||||||
: public DefaultFoldingSetTrait<T> {};
|
struct FoldingSetTrait : public DefaultFoldingSetTrait<T> {};
|
||||||
|
|
||||||
/// DefaultContextualFoldingSetTrait - Like DefaultFoldingSetTrait, but
|
/// DefaultContextualFoldingSetTrait - Like DefaultFoldingSetTrait, but
|
||||||
/// for ContextualFoldingSets.
|
/// for ContextualFoldingSets.
|
||||||
|
@ -828,6 +829,13 @@ struct FoldingSetTrait<std::pair<T1, T2>> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct FoldingSetTrait<T, typename std::enable_if_t<std::is_enum<T>::value>> {
|
||||||
|
static void Profile(const T &X, FoldingSetNodeID &ID) {
|
||||||
|
ID.AddInteger(static_cast<typename std::underlying_type_t<T>>(X));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
} // end namespace llvm
|
} // end namespace llvm
|
||||||
|
|
||||||
#endif // LLVM_ADT_FOLDINGSET_H
|
#endif // LLVM_ADT_FOLDINGSET_H
|
||||||
|
|
|
@ -58,7 +58,7 @@ class Pass;
|
||||||
class Type;
|
class Type;
|
||||||
template <class GraphType> struct GraphTraits;
|
template <class GraphType> struct GraphTraits;
|
||||||
template <typename T, unsigned int N> class SmallSetVector;
|
template <typename T, unsigned int N> class SmallSetVector;
|
||||||
template <typename T> struct FoldingSetTrait;
|
template <typename T, typename Enable> struct FoldingSetTrait;
|
||||||
class AAResults;
|
class AAResults;
|
||||||
class BlockAddress;
|
class BlockAddress;
|
||||||
class BlockFrequencyInfo;
|
class BlockFrequencyInfo;
|
||||||
|
|
Loading…
Reference in New Issue