[clang] [analyzer] Use explicit call description mode in iterator checkers (PR #88913)
https://github.com/NagyDonat closed https://github.com/llvm/llvm-project/pull/88913 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Use explicit call description mode in iterator checkers (PR #88913)
NagyDonat wrote: Uh oh, those niebloids are really deep black magic :skull_and_crossbones: I didn't know about them previously, so thanks for mentioning them. https://github.com/llvm/llvm-project/pull/88913 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Use explicit call description mode in iterator checkers (PR #88913)
https://github.com/steakhal approved this pull request. This should be all good. FYI std lib funcs are not always functions. They could be also niebloids, which we cant actually hook. This shouldnt affect these apis though. I left it here as food for thought. https://github.com/llvm/llvm-project/pull/88913 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Use explicit call description mode in iterator checkers (PR #88913)
llvmbot wrote: @llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-static-analyzer-1 Author: None (NagyDonat) Changes This commit explicitly specifies the matching mode (C library function, any non-method function, or C++ method) for the `CallDescription`s constructed in the iterator/container checkers. This change won't cause major functional changes, but isn't NFC because it ensures that e.g. call descriptions for a non-method function won't accidentally match a method that has the same name. Separate commits will perform (or have already performed) this change in other checkers. My goal is to ensure that the call description mode is always explicitly specified and eliminate (or strongly restrict) the vague "may be either a method or a simple function" mode that's the current default. I'm handling the iterator checkers in this separate commit because they're infamously complex; but I don't expect any trouble because this transition doesn't interact with the "central" logic of iterator handling. --- Full diff: https://github.com/llvm/llvm-project/pull/88913.diff 6 Files Affected: - (modified) clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp (+19-14) - (modified) clang/lib/StaticAnalyzer/Checkers/DebugContainerModeling.cpp (+2-2) - (modified) clang/lib/StaticAnalyzer/Checkers/DebugIteratorModeling.cpp (+3-3) - (modified) clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp (+4-3) - (modified) clang/lib/StaticAnalyzer/Checkers/IteratorRangeChecker.cpp (+8-3) - (modified) clang/lib/StaticAnalyzer/Checkers/STLAlgorithmModeling.cpp (+44-23) ``diff diff --git a/clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp b/clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp index 009c0d3fb93686..55ed809bfed6ce 100644 --- a/clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp @@ -72,26 +72,31 @@ class ContainerModeling SVal) const; CallDescriptionMap NoIterParamFunctions = { - {{{"clear"}, 0}, ::handleClear}, - {{{"assign"}, 2}, ::handleAssign}, - {{{"push_back"}, 1}, ::handlePushBack}, - {{{"emplace_back"}, 1}, ::handlePushBack}, - {{{"pop_back"}, 0}, ::handlePopBack}, - {{{"push_front"}, 1}, ::handlePushFront}, - {{{"emplace_front"}, 1}, ::handlePushFront}, - {{{"pop_front"}, 0}, ::handlePopFront}, + {{CDM::CXXMethod, {"clear"}, 0}, ::handleClear}, + {{CDM::CXXMethod, {"assign"}, 2}, ::handleAssign}, + {{CDM::CXXMethod, {"push_back"}, 1}, ::handlePushBack}, + {{CDM::CXXMethod, {"emplace_back"}, 1}, + ::handlePushBack}, + {{CDM::CXXMethod, {"pop_back"}, 0}, ::handlePopBack}, + {{CDM::CXXMethod, {"push_front"}, 1}, + ::handlePushFront}, + {{CDM::CXXMethod, {"emplace_front"}, 1}, + ::handlePushFront}, + {{CDM::CXXMethod, {"pop_front"}, 0}, ::handlePopFront}, }; CallDescriptionMap OneIterParamFunctions = { - {{{"insert"}, 2}, ::handleInsert}, - {{{"emplace"}, 2}, ::handleInsert}, - {{{"erase"}, 1}, ::handleErase}, - {{{"erase_after"}, 1}, ::handleEraseAfter}, + {{CDM::CXXMethod, {"insert"}, 2}, ::handleInsert}, + {{CDM::CXXMethod, {"emplace"}, 2}, ::handleInsert}, + {{CDM::CXXMethod, {"erase"}, 1}, ::handleErase}, + {{CDM::CXXMethod, {"erase_after"}, 1}, + ::handleEraseAfter}, }; CallDescriptionMap TwoIterParamFunctions = { - {{{"erase"}, 2}, ::handleErase}, - {{{"erase_after"}, 2}, ::handleEraseAfter}, + {{CDM::CXXMethod, {"erase"}, 2}, ::handleErase}, + {{CDM::CXXMethod, {"erase_after"}, 2}, + ::handleEraseAfter}, }; }; diff --git a/clang/lib/StaticAnalyzer/Checkers/DebugContainerModeling.cpp b/clang/lib/StaticAnalyzer/Checkers/DebugContainerModeling.cpp index 72186a99d94358..d3830a01dd0cbd 100644 --- a/clang/lib/StaticAnalyzer/Checkers/DebugContainerModeling.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/DebugContainerModeling.cpp @@ -42,9 +42,9 @@ class DebugContainerModeling CheckerContext &) const; CallDescriptionMap Callbacks = { - {{{"clang_analyzer_container_begin"}, 1}, + {{CDM::SimpleFunc, {"clang_analyzer_container_begin"}, 1}, ::analyzerContainerBegin}, - {{{"clang_analyzer_container_end"}, 1}, + {{CDM::SimpleFunc, {"clang_analyzer_container_end"}, 1}, ::analyzerContainerEnd}, }; diff --git a/clang/lib/StaticAnalyzer/Checkers/DebugIteratorModeling.cpp b/clang/lib/StaticAnalyzer/Checkers/DebugIteratorModeling.cpp index 79ab71d7829db7..203743dacda636 100644 --- a/clang/lib/StaticAnalyzer/Checkers/DebugIteratorModeling.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/DebugIteratorModeling.cpp @@ -43,11 +43,11 @@ class DebugIteratorModeling CheckerContext &) const; CallDescriptionMap Callbacks = { -
[clang] [analyzer] Use explicit call description mode in iterator checkers (PR #88913)
https://github.com/NagyDonat created https://github.com/llvm/llvm-project/pull/88913 This commit explicitly specifies the matching mode (C library function, any non-method function, or C++ method) for the `CallDescription`s constructed in the iterator/container checkers. This change won't cause major functional changes, but isn't NFC because it ensures that e.g. call descriptions for a non-method function won't accidentally match a method that has the same name. Separate commits will perform (or have already performed) this change in other checkers. My goal is to ensure that the call description mode is always explicitly specified and eliminate (or strongly restrict) the vague "may be either a method or a simple function" mode that's the current default. I'm handling the iterator checkers in this separate commit because they're infamously complex; but I don't expect any trouble because this transition doesn't interact with the "central" logic of iterator handling. >From b18e8aa88b7ef5b4cd131ba0908ecc6134d8caae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Don=C3=A1t=20Nagy?= Date: Tue, 16 Apr 2024 13:47:58 +0200 Subject: [PATCH] [analyzer] Use explicit call description mode in iterator checkers This commit explicitly specifies the matching mode (C library function, any non-method function, or C++ method) for the `CallDescription`s constructed in the iterator/container checkers. This change won't cause major functional changes, but isn't NFC because it ensures that e.g. call descriptions for a non-method function won't accidentally match a method that has the same name. Separate commits will perform (or have already performed) this change in other checkers. My goal is to ensure that the call description mode is always explicitly specified and eliminate (or strongly restrict) the vague "may be either a method or a simple function" mode that's the current default. I'm handling the iterator checkers in this separate commit because they're infamously complex; but I don't expect any trouble because this transition doesn't interact with the "central" logic of iterator handling. --- .../Checkers/ContainerModeling.cpp| 33 + .../Checkers/DebugContainerModeling.cpp | 4 +- .../Checkers/DebugIteratorModeling.cpp| 6 +- .../Checkers/IteratorModeling.cpp | 7 +- .../Checkers/IteratorRangeChecker.cpp | 11 ++- .../Checkers/STLAlgorithmModeling.cpp | 67 --- 6 files changed, 80 insertions(+), 48 deletions(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp b/clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp index 009c0d3fb93686..55ed809bfed6ce 100644 --- a/clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp @@ -72,26 +72,31 @@ class ContainerModeling SVal) const; CallDescriptionMap NoIterParamFunctions = { - {{{"clear"}, 0}, ::handleClear}, - {{{"assign"}, 2}, ::handleAssign}, - {{{"push_back"}, 1}, ::handlePushBack}, - {{{"emplace_back"}, 1}, ::handlePushBack}, - {{{"pop_back"}, 0}, ::handlePopBack}, - {{{"push_front"}, 1}, ::handlePushFront}, - {{{"emplace_front"}, 1}, ::handlePushFront}, - {{{"pop_front"}, 0}, ::handlePopFront}, + {{CDM::CXXMethod, {"clear"}, 0}, ::handleClear}, + {{CDM::CXXMethod, {"assign"}, 2}, ::handleAssign}, + {{CDM::CXXMethod, {"push_back"}, 1}, ::handlePushBack}, + {{CDM::CXXMethod, {"emplace_back"}, 1}, + ::handlePushBack}, + {{CDM::CXXMethod, {"pop_back"}, 0}, ::handlePopBack}, + {{CDM::CXXMethod, {"push_front"}, 1}, + ::handlePushFront}, + {{CDM::CXXMethod, {"emplace_front"}, 1}, + ::handlePushFront}, + {{CDM::CXXMethod, {"pop_front"}, 0}, ::handlePopFront}, }; CallDescriptionMap OneIterParamFunctions = { - {{{"insert"}, 2}, ::handleInsert}, - {{{"emplace"}, 2}, ::handleInsert}, - {{{"erase"}, 1}, ::handleErase}, - {{{"erase_after"}, 1}, ::handleEraseAfter}, + {{CDM::CXXMethod, {"insert"}, 2}, ::handleInsert}, + {{CDM::CXXMethod, {"emplace"}, 2}, ::handleInsert}, + {{CDM::CXXMethod, {"erase"}, 1}, ::handleErase}, + {{CDM::CXXMethod, {"erase_after"}, 1}, + ::handleEraseAfter}, }; CallDescriptionMap TwoIterParamFunctions = { - {{{"erase"}, 2}, ::handleErase}, - {{{"erase_after"}, 2}, ::handleEraseAfter}, + {{CDM::CXXMethod, {"erase"}, 2}, ::handleErase}, + {{CDM::CXXMethod, {"erase_after"}, 2}, + ::handleEraseAfter}, }; }; diff --git a/clang/lib/StaticAnalyzer/Checkers/DebugContainerModeling.cpp b/clang/lib/StaticAnalyzer/Checkers/DebugContainerModeling.cpp index 72186a99d94358..d3830a01dd0cbd 100644 --- a/clang/lib/StaticAnalyzer/Checkers/DebugContainerModeling.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/DebugContainerModeling.cpp @@ -42,9 +42,9 @@ class