[analyzer][NFC] Use enum for CallDescription flags

Yeah, let's prefer a slightly stronger type representing this.

Reviewed By: martong, xazax.hun

Differential Revision: https://reviews.llvm.org/D113595
This commit is contained in:
Balazs Benics 2021-11-19 18:32:13 +01:00
parent 97f1bf15b1
commit e6ef134f3c
5 changed files with 33 additions and 45 deletions

View File

@ -28,7 +28,9 @@ class IdentifierInfo;
namespace clang { namespace clang {
namespace ento { namespace ento {
enum CallDescriptionFlags : int { enum CallDescriptionFlags : unsigned {
CDF_None = 0,
/// Describes a C standard function that is sometimes implemented as a macro /// Describes a C standard function that is sometimes implemented as a macro
/// that expands to a compiler builtin with some __builtin prefix. /// that expands to a compiler builtin with some __builtin prefix.
/// The builtin may as well have a few extra arguments on top of the requested /// The builtin may as well have a few extra arguments on top of the requested
@ -61,7 +63,8 @@ public:
/// @param RequiredArgs The number of arguments that is expected to match a /// @param RequiredArgs The number of arguments that is expected to match a
/// call. Omit this parameter to match every occurrence of call with a given /// call. Omit this parameter to match every occurrence of call with a given
/// name regardless the number of arguments. /// name regardless the number of arguments.
CallDescription(int Flags, ArrayRef<const char *> QualifiedName, CallDescription(CallDescriptionFlags Flags,
ArrayRef<const char *> QualifiedName,
MaybeUInt RequiredArgs = None, MaybeUInt RequiredArgs = None,
MaybeUInt RequiredParams = None); MaybeUInt RequiredParams = None);

View File

@ -72,42 +72,27 @@ public:
SVal) const; SVal) const;
CallDescriptionMap<NoItParamFn> NoIterParamFunctions = { CallDescriptionMap<NoItParamFn> NoIterParamFunctions = {
{{0, "clear", 0}, {{"clear", 0}, &ContainerModeling::handleClear},
&ContainerModeling::handleClear}, {{"assign", 2}, &ContainerModeling::handleAssign},
{{0, "assign", 2}, {{"push_back", 1}, &ContainerModeling::handlePushBack},
&ContainerModeling::handleAssign}, {{"emplace_back", 1}, &ContainerModeling::handlePushBack},
{{0, "push_back", 1}, {{"pop_back", 0}, &ContainerModeling::handlePopBack},
&ContainerModeling::handlePushBack}, {{"push_front", 1}, &ContainerModeling::handlePushFront},
{{0, "emplace_back", 1}, {{"emplace_front", 1}, &ContainerModeling::handlePushFront},
&ContainerModeling::handlePushBack}, {{"pop_front", 0}, &ContainerModeling::handlePopFront},
{{0, "pop_back", 0},
&ContainerModeling::handlePopBack},
{{0, "push_front", 1},
&ContainerModeling::handlePushFront},
{{0, "emplace_front", 1},
&ContainerModeling::handlePushFront},
{{0, "pop_front", 0},
&ContainerModeling::handlePopFront},
}; };
CallDescriptionMap<OneItParamFn> OneIterParamFunctions = { CallDescriptionMap<OneItParamFn> OneIterParamFunctions = {
{{0, "insert", 2}, {{"insert", 2}, &ContainerModeling::handleInsert},
&ContainerModeling::handleInsert}, {{"emplace", 2}, &ContainerModeling::handleInsert},
{{0, "emplace", 2}, {{"erase", 1}, &ContainerModeling::handleErase},
&ContainerModeling::handleInsert}, {{"erase_after", 1}, &ContainerModeling::handleEraseAfter},
{{0, "erase", 1},
&ContainerModeling::handleErase},
{{0, "erase_after", 1},
&ContainerModeling::handleEraseAfter},
}; };
CallDescriptionMap<TwoItParamFn> TwoIterParamFunctions = { CallDescriptionMap<TwoItParamFn> TwoIterParamFunctions = {
{{0, "erase", 2}, {{"erase", 2}, &ContainerModeling::handleErase},
&ContainerModeling::handleErase}, {{"erase_after", 2}, &ContainerModeling::handleEraseAfter},
{{0, "erase_after", 2},
&ContainerModeling::handleEraseAfter},
}; };
}; };
bool isBeginCall(const FunctionDecl *Func); bool isBeginCall(const FunctionDecl *Func);

View File

@ -41,9 +41,9 @@ class DebugContainerModeling
CheckerContext &) const; CheckerContext &) const;
CallDescriptionMap<FnCheck> Callbacks = { CallDescriptionMap<FnCheck> Callbacks = {
{{0, "clang_analyzer_container_begin", 1}, {{"clang_analyzer_container_begin", 1},
&DebugContainerModeling::analyzerContainerBegin}, &DebugContainerModeling::analyzerContainerBegin},
{{0, "clang_analyzer_container_end", 1}, {{"clang_analyzer_container_end", 1},
&DebugContainerModeling::analyzerContainerEnd}, &DebugContainerModeling::analyzerContainerEnd},
}; };

View File

@ -42,11 +42,11 @@ class DebugIteratorModeling
CheckerContext &) const; CheckerContext &) const;
CallDescriptionMap<FnCheck> Callbacks = { CallDescriptionMap<FnCheck> Callbacks = {
{{0, "clang_analyzer_iterator_position", 1}, {{"clang_analyzer_iterator_position", 1},
&DebugIteratorModeling::analyzerIteratorPosition}, &DebugIteratorModeling::analyzerIteratorPosition},
{{0, "clang_analyzer_iterator_container", 1}, {{"clang_analyzer_iterator_container", 1},
&DebugIteratorModeling::analyzerIteratorContainer}, &DebugIteratorModeling::analyzerIteratorContainer},
{{0, "clang_analyzer_iterator_validity", 1}, {{"clang_analyzer_iterator_validity", 1},
&DebugIteratorModeling::analyzerIteratorValidity}, &DebugIteratorModeling::analyzerIteratorValidity},
}; };

View File

@ -34,7 +34,7 @@ static MaybeUInt readRequiredParams(MaybeUInt RequiredArgs,
return None; return None;
} }
ento::CallDescription::CallDescription(int Flags, ento::CallDescription::CallDescription(CallDescriptionFlags Flags,
ArrayRef<const char *> QualifiedName, ArrayRef<const char *> QualifiedName,
MaybeUInt RequiredArgs /*= None*/, MaybeUInt RequiredArgs /*= None*/,
MaybeUInt RequiredParams /*= None*/) MaybeUInt RequiredParams /*= None*/)
@ -50,7 +50,7 @@ ento::CallDescription::CallDescription(int Flags,
ento::CallDescription::CallDescription(ArrayRef<const char *> QualifiedName, ento::CallDescription::CallDescription(ArrayRef<const char *> QualifiedName,
MaybeUInt RequiredArgs /*= None*/, MaybeUInt RequiredArgs /*= None*/,
MaybeUInt RequiredParams /*= None*/) MaybeUInt RequiredParams /*= None*/)
: CallDescription(0, QualifiedName, RequiredArgs, RequiredParams) {} : CallDescription(CDF_None, QualifiedName, RequiredArgs, RequiredParams) {}
bool ento::CallDescription::matches(const CallEvent &Call) const { bool ento::CallDescription::matches(const CallEvent &Call) const {
// FIXME: Add ObjC Message support. // FIXME: Add ObjC Message support.