Skip to content

[analyzer] Use explicit call description mode in iterator checkers #88913

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,26 +72,31 @@ class ContainerModeling
SVal) const;

CallDescriptionMap<NoItParamFn> NoIterParamFunctions = {
{{{"clear"}, 0}, &ContainerModeling::handleClear},
{{{"assign"}, 2}, &ContainerModeling::handleAssign},
{{{"push_back"}, 1}, &ContainerModeling::handlePushBack},
{{{"emplace_back"}, 1}, &ContainerModeling::handlePushBack},
{{{"pop_back"}, 0}, &ContainerModeling::handlePopBack},
{{{"push_front"}, 1}, &ContainerModeling::handlePushFront},
{{{"emplace_front"}, 1}, &ContainerModeling::handlePushFront},
{{{"pop_front"}, 0}, &ContainerModeling::handlePopFront},
{{CDM::CXXMethod, {"clear"}, 0}, &ContainerModeling::handleClear},
{{CDM::CXXMethod, {"assign"}, 2}, &ContainerModeling::handleAssign},
{{CDM::CXXMethod, {"push_back"}, 1}, &ContainerModeling::handlePushBack},
{{CDM::CXXMethod, {"emplace_back"}, 1},
&ContainerModeling::handlePushBack},
{{CDM::CXXMethod, {"pop_back"}, 0}, &ContainerModeling::handlePopBack},
{{CDM::CXXMethod, {"push_front"}, 1},
&ContainerModeling::handlePushFront},
{{CDM::CXXMethod, {"emplace_front"}, 1},
&ContainerModeling::handlePushFront},
{{CDM::CXXMethod, {"pop_front"}, 0}, &ContainerModeling::handlePopFront},
};

CallDescriptionMap<OneItParamFn> OneIterParamFunctions = {
{{{"insert"}, 2}, &ContainerModeling::handleInsert},
{{{"emplace"}, 2}, &ContainerModeling::handleInsert},
{{{"erase"}, 1}, &ContainerModeling::handleErase},
{{{"erase_after"}, 1}, &ContainerModeling::handleEraseAfter},
{{CDM::CXXMethod, {"insert"}, 2}, &ContainerModeling::handleInsert},
{{CDM::CXXMethod, {"emplace"}, 2}, &ContainerModeling::handleInsert},
{{CDM::CXXMethod, {"erase"}, 1}, &ContainerModeling::handleErase},
{{CDM::CXXMethod, {"erase_after"}, 1},
&ContainerModeling::handleEraseAfter},
};

CallDescriptionMap<TwoItParamFn> TwoIterParamFunctions = {
{{{"erase"}, 2}, &ContainerModeling::handleErase},
{{{"erase_after"}, 2}, &ContainerModeling::handleEraseAfter},
{{CDM::CXXMethod, {"erase"}, 2}, &ContainerModeling::handleErase},
{{CDM::CXXMethod, {"erase_after"}, 2},
&ContainerModeling::handleEraseAfter},
};
};

Expand Down
4 changes: 2 additions & 2 deletions clang/lib/StaticAnalyzer/Checkers/DebugContainerModeling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ class DebugContainerModeling
CheckerContext &) const;

CallDescriptionMap<FnCheck> Callbacks = {
{{{"clang_analyzer_container_begin"}, 1},
{{CDM::SimpleFunc, {"clang_analyzer_container_begin"}, 1},
&DebugContainerModeling::analyzerContainerBegin},
{{{"clang_analyzer_container_end"}, 1},
{{CDM::SimpleFunc, {"clang_analyzer_container_end"}, 1},
&DebugContainerModeling::analyzerContainerEnd},
};

Expand Down
6 changes: 3 additions & 3 deletions clang/lib/StaticAnalyzer/Checkers/DebugIteratorModeling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ class DebugIteratorModeling
CheckerContext &) const;

CallDescriptionMap<FnCheck> Callbacks = {
{{{"clang_analyzer_iterator_position"}, 1},
{{CDM::SimpleFunc, {"clang_analyzer_iterator_position"}, 1},
&DebugIteratorModeling::analyzerIteratorPosition},
{{{"clang_analyzer_iterator_container"}, 1},
{{CDM::SimpleFunc, {"clang_analyzer_iterator_container"}, 1},
&DebugIteratorModeling::analyzerIteratorContainer},
{{{"clang_analyzer_iterator_validity"}, 1},
{{CDM::SimpleFunc, {"clang_analyzer_iterator_validity"}, 1},
&DebugIteratorModeling::analyzerIteratorValidity},
};

Expand Down
7 changes: 4 additions & 3 deletions clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,19 +129,20 @@ class IteratorModeling
CallDescriptionMap<AdvanceFn> AdvanceLikeFunctions = {
// template<class InputIt, class Distance>
// void advance(InputIt& it, Distance n);
{{{"std", "advance"}, 2}, &IteratorModeling::handleAdvance},
{{CDM::SimpleFunc, {"std", "advance"}, 2},
&IteratorModeling::handleAdvance},

// template<class BidirIt>
// BidirIt prev(
// BidirIt it,
// typename std::iterator_traits<BidirIt>::difference_type n = 1);
{{{"std", "prev"}, 2}, &IteratorModeling::handlePrev},
{{CDM::SimpleFunc, {"std", "prev"}, 2}, &IteratorModeling::handlePrev},

// template<class ForwardIt>
// ForwardIt next(
// ForwardIt it,
// typename std::iterator_traits<ForwardIt>::difference_type n = 1);
{{{"std", "next"}, 2}, &IteratorModeling::handleNext},
{{CDM::SimpleFunc, {"std", "next"}, 2}, &IteratorModeling::handleNext},
};

public:
Expand Down
11 changes: 8 additions & 3 deletions clang/lib/StaticAnalyzer/Checkers/IteratorRangeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,15 @@ class IteratorRangeChecker
using AdvanceFn = void (IteratorRangeChecker::*)(CheckerContext &, SVal,
SVal) const;

// FIXME: these three functions are also listed in IteratorModeling.cpp,
// perhaps unify their handling?
CallDescriptionMap<AdvanceFn> AdvanceFunctions = {
{{{"std", "advance"}, 2}, &IteratorRangeChecker::verifyAdvance},
{{{"std", "prev"}, 2}, &IteratorRangeChecker::verifyPrev},
{{{"std", "next"}, 2}, &IteratorRangeChecker::verifyNext},
{{CDM::SimpleFunc, {"std", "advance"}, 2},
&IteratorRangeChecker::verifyAdvance},
{{CDM::SimpleFunc, {"std", "prev"}, 2},
&IteratorRangeChecker::verifyPrev},
{{CDM::SimpleFunc, {"std", "next"}, 2},
&IteratorRangeChecker::verifyNext},
};
};

Expand Down
67 changes: 44 additions & 23 deletions clang/lib/StaticAnalyzer/Checkers/STLAlgorithmModeling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,50 @@ class STLAlgorithmModeling : public Checker<eval::Call> {
const CallExpr *) const;

const CallDescriptionMap<FnCheck> Callbacks = {
{{{"std", "find"}, 3}, &STLAlgorithmModeling::evalFind},
{{{"std", "find"}, 4}, &STLAlgorithmModeling::evalFind},
{{{"std", "find_if"}, 3}, &STLAlgorithmModeling::evalFind},
{{{"std", "find_if"}, 4}, &STLAlgorithmModeling::evalFind},
{{{"std", "find_if_not"}, 3}, &STLAlgorithmModeling::evalFind},
{{{"std", "find_if_not"}, 4}, &STLAlgorithmModeling::evalFind},
{{{"std", "find_first_of"}, 4}, &STLAlgorithmModeling::evalFind},
{{{"std", "find_first_of"}, 5}, &STLAlgorithmModeling::evalFind},
{{{"std", "find_first_of"}, 6}, &STLAlgorithmModeling::evalFind},
{{{"std", "find_end"}, 4}, &STLAlgorithmModeling::evalFind},
{{{"std", "find_end"}, 5}, &STLAlgorithmModeling::evalFind},
{{{"std", "find_end"}, 6}, &STLAlgorithmModeling::evalFind},
{{{"std", "lower_bound"}, 3}, &STLAlgorithmModeling::evalFind},
{{{"std", "lower_bound"}, 4}, &STLAlgorithmModeling::evalFind},
{{{"std", "upper_bound"}, 3}, &STLAlgorithmModeling::evalFind},
{{{"std", "upper_bound"}, 4}, &STLAlgorithmModeling::evalFind},
{{{"std", "search"}, 3}, &STLAlgorithmModeling::evalFind},
{{{"std", "search"}, 4}, &STLAlgorithmModeling::evalFind},
{{{"std", "search"}, 5}, &STLAlgorithmModeling::evalFind},
{{{"std", "search"}, 6}, &STLAlgorithmModeling::evalFind},
{{{"std", "search_n"}, 4}, &STLAlgorithmModeling::evalFind},
{{{"std", "search_n"}, 5}, &STLAlgorithmModeling::evalFind},
{{{"std", "search_n"}, 6}, &STLAlgorithmModeling::evalFind},
{{CDM::SimpleFunc, {"std", "find"}, 3}, &STLAlgorithmModeling::evalFind},
{{CDM::SimpleFunc, {"std", "find"}, 4}, &STLAlgorithmModeling::evalFind},
{{CDM::SimpleFunc, {"std", "find_if"}, 3},
&STLAlgorithmModeling::evalFind},
{{CDM::SimpleFunc, {"std", "find_if"}, 4},
&STLAlgorithmModeling::evalFind},
{{CDM::SimpleFunc, {"std", "find_if_not"}, 3},
&STLAlgorithmModeling::evalFind},
{{CDM::SimpleFunc, {"std", "find_if_not"}, 4},
&STLAlgorithmModeling::evalFind},
{{CDM::SimpleFunc, {"std", "find_first_of"}, 4},
&STLAlgorithmModeling::evalFind},
{{CDM::SimpleFunc, {"std", "find_first_of"}, 5},
&STLAlgorithmModeling::evalFind},
{{CDM::SimpleFunc, {"std", "find_first_of"}, 6},
&STLAlgorithmModeling::evalFind},
{{CDM::SimpleFunc, {"std", "find_end"}, 4},
&STLAlgorithmModeling::evalFind},
{{CDM::SimpleFunc, {"std", "find_end"}, 5},
&STLAlgorithmModeling::evalFind},
{{CDM::SimpleFunc, {"std", "find_end"}, 6},
&STLAlgorithmModeling::evalFind},
{{CDM::SimpleFunc, {"std", "lower_bound"}, 3},
&STLAlgorithmModeling::evalFind},
{{CDM::SimpleFunc, {"std", "lower_bound"}, 4},
&STLAlgorithmModeling::evalFind},
{{CDM::SimpleFunc, {"std", "upper_bound"}, 3},
&STLAlgorithmModeling::evalFind},
{{CDM::SimpleFunc, {"std", "upper_bound"}, 4},
&STLAlgorithmModeling::evalFind},
{{CDM::SimpleFunc, {"std", "search"}, 3},
&STLAlgorithmModeling::evalFind},
{{CDM::SimpleFunc, {"std", "search"}, 4},
&STLAlgorithmModeling::evalFind},
{{CDM::SimpleFunc, {"std", "search"}, 5},
&STLAlgorithmModeling::evalFind},
{{CDM::SimpleFunc, {"std", "search"}, 6},
&STLAlgorithmModeling::evalFind},
{{CDM::SimpleFunc, {"std", "search_n"}, 4},
&STLAlgorithmModeling::evalFind},
{{CDM::SimpleFunc, {"std", "search_n"}, 5},
&STLAlgorithmModeling::evalFind},
{{CDM::SimpleFunc, {"std", "search_n"}, 6},
&STLAlgorithmModeling::evalFind},
};

public:
Expand Down