[clang] [analyzer] Use explicit call description mode in more checkers (PR #90974)
https://github.com/NagyDonat closed https://github.com/llvm/llvm-project/pull/90974 ___ 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 more checkers (PR #90974)
https://github.com/NagyDonat updated https://github.com/llvm/llvm-project/pull/90974 From 9ed06c41127c88b3e2e8596ddd83b42ab2856f61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Don=C3=A1t=20Nagy?= Date: Fri, 3 May 2024 16:13:19 +0200 Subject: [PATCH 1/3] [analyzer] Use explicit call description mode in more checkers This commit explicitly specifies the matching mode (C library function, any non-method function, or C++ method) for the `CallDescription`s constructed in various checkers. Some code was simplified to use `CallDescriptionSet`s instead of individual `CallDescription`s. 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 have already performed this change in other checkers: - easy chases: e2f1cbae45f81f3cd9a4d3c2bcf69a094eb060fa - MallocChecker: d6d84b5d1448e4f2e24b467a0abcf42fe9d543e9 - iterator checkers: 06eedffe0d2782922e63cc25cb927f4acdaf7b30 - InvalidPtr checker: 024281d4d26344f9613b9115ea1fcbdbdba23235 ... and follow-up commits will handle the remaining 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. --- .../BlockInCriticalSectionChecker.cpp | 38 +++- .../Checkers/CStringChecker.cpp | 4 +- .../Checkers/InnerPointerChecker.cpp | 58 --- .../Checkers/SmartPtrModeling.cpp | 18 +++--- .../StaticAnalyzer/Checkers/StreamChecker.cpp | 8 ++- 5 files changed, 64 insertions(+), 62 deletions(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp index e4373915410fb..9b612d03e93c3 100644 --- a/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp @@ -149,26 +149,34 @@ class BlockInCriticalSectionChecker : public Checker { private: const std::array MutexDescriptors{ MemberMutexDescriptor( - CallDescription(/*QualifiedName=*/{"std", "mutex", "lock"}, + CallDescription(/*MatchAs=*/CDM::CXXMethod, + /*QualifiedName=*/{"std", "mutex", "lock"}, /*RequiredArgs=*/0), - CallDescription({"std", "mutex", "unlock"}, 0)), - FirstArgMutexDescriptor(CallDescription({"pthread_mutex_lock"}, 1), - CallDescription({"pthread_mutex_unlock"}, 1)), - FirstArgMutexDescriptor(CallDescription({"mtx_lock"}, 1), - CallDescription({"mtx_unlock"}, 1)), - FirstArgMutexDescriptor(CallDescription({"pthread_mutex_trylock"}, 1), - CallDescription({"pthread_mutex_unlock"}, 1)), - FirstArgMutexDescriptor(CallDescription({"mtx_trylock"}, 1), - CallDescription({"mtx_unlock"}, 1)), - FirstArgMutexDescriptor(CallDescription({"mtx_timedlock"}, 1), - CallDescription({"mtx_unlock"}, 1)), + CallDescription(CDM::CXXMethod, {"std", "mutex", "unlock"}, 0)), + FirstArgMutexDescriptor( + CallDescription(CDM::CLibrary, {"pthread_mutex_lock"}, 1), + CallDescription(CDM::CLibrary, {"pthread_mutex_unlock"}, 1)), + FirstArgMutexDescriptor( + CallDescription(CDM::CLibrary, {"mtx_lock"}, 1), + CallDescription(CDM::CLibrary, {"mtx_unlock"}, 1)), + FirstArgMutexDescriptor( + CallDescription(CDM::CLibrary, {"pthread_mutex_trylock"}, 1), + CallDescription(CDM::CLibrary, {"pthread_mutex_unlock"}, 1)), + FirstArgMutexDescriptor( + CallDescription(CDM::CLibrary, {"mtx_trylock"}, 1), + CallDescription(CDM::CLibrary, {"mtx_unlock"}, 1)), + FirstArgMutexDescriptor( + CallDescription(CDM::CLibrary, {"mtx_timedlock"}, 1), + CallDescription(CDM::CLibrary, {"mtx_unlock"}, 1)), RAIIMutexDescriptor("lock_guard"), RAIIMutexDescriptor("unique_lock")}; const std::array BlockingFunctions{ - ArrayRef{StringRef{"sleep"}}, ArrayRef{StringRef{"getc"}}, - ArrayRef{StringRef{"fgets"}}, ArrayRef{StringRef{"read"}}, - ArrayRef{StringRef{"recv"}}}; + CallDescription(CDM::CLibrary, {"sleep"}), + CallDescription(CDM::CLibrary, {"getc"}), + CallDescription(CDM::CLibrary, {"fgets"}), + CallDescription(CDM::CLibrary, {"read"}), + CallDescription(CDM::CLibrary, {"recv"})}; const BugType BlockInCritSectionBugType{ this, "Call to blocking function in critical section", "Blocking Error"}; diff --git a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp index f9548b5c3010b..238e87a712a43 100644 ---
[clang] [analyzer] Use explicit call description mode in more checkers (PR #90974)
@@ -149,26 +149,34 @@ class BlockInCriticalSectionChecker : public Checker { private: const std::array MutexDescriptors{ MemberMutexDescriptor( - CallDescription(/*QualifiedName=*/{"std", "mutex", "lock"}, + CallDescription(/*MatchAs=*/CDM::CXXMethod, + /*QualifiedName=*/{"std", "mutex", "lock"}, /*RequiredArgs=*/0), NagyDonat wrote: I uploaded a commit that switches to `{...}`. Interestingly the initializer of `std::array<...> BlockingFunctions` did not work with `{...}` instead of `CallDescription(...)` -- but now that I looked at it I realized that it should be a `CallDescriptionSet` instead of a generic STL array. https://github.com/llvm/llvm-project/pull/90974 ___ 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 more checkers (PR #90974)
=?utf-8?q?Donát?= Nagy Message-ID: In-Reply-To: github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff fc7e74e879f37301edd9450d3bbf0fec620338a6 4d3dae37544097d3000f22ecc03f63b0c182dd56 -- clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp `` View the diff from clang-format here. ``diff diff --git a/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp index 290916c3c1..e138debd13 100644 --- a/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp @@ -148,35 +148,28 @@ using MutexDescriptor = class BlockInCriticalSectionChecker : public Checker { private: const std::array MutexDescriptors{ - MemberMutexDescriptor( - {/*MatchAs=*/CDM::CXXMethod, - /*QualifiedName=*/{"std", "mutex", "lock"}, - /*RequiredArgs=*/0}, - {CDM::CXXMethod, {"std", "mutex", "unlock"}, 0}), - FirstArgMutexDescriptor( - {CDM::CLibrary, {"pthread_mutex_lock"}, 1}, - {CDM::CLibrary, {"pthread_mutex_unlock"}, 1}), - FirstArgMutexDescriptor( - {CDM::CLibrary, {"mtx_lock"}, 1}, - {CDM::CLibrary, {"mtx_unlock"}, 1}), - FirstArgMutexDescriptor( - {CDM::CLibrary, {"pthread_mutex_trylock"}, 1}, - {CDM::CLibrary, {"pthread_mutex_unlock"}, 1}), - FirstArgMutexDescriptor( - {CDM::CLibrary, {"mtx_trylock"}, 1}, - {CDM::CLibrary, {"mtx_unlock"}, 1}), - FirstArgMutexDescriptor( - {CDM::CLibrary, {"mtx_timedlock"}, 1}, - {CDM::CLibrary, {"mtx_unlock"}, 1}), + MemberMutexDescriptor({/*MatchAs=*/CDM::CXXMethod, + /*QualifiedName=*/{"std", "mutex", "lock"}, + /*RequiredArgs=*/0}, +{CDM::CXXMethod, {"std", "mutex", "unlock"}, 0}), + FirstArgMutexDescriptor({CDM::CLibrary, {"pthread_mutex_lock"}, 1}, + {CDM::CLibrary, {"pthread_mutex_unlock"}, 1}), + FirstArgMutexDescriptor({CDM::CLibrary, {"mtx_lock"}, 1}, + {CDM::CLibrary, {"mtx_unlock"}, 1}), + FirstArgMutexDescriptor({CDM::CLibrary, {"pthread_mutex_trylock"}, 1}, + {CDM::CLibrary, {"pthread_mutex_unlock"}, 1}), + FirstArgMutexDescriptor({CDM::CLibrary, {"mtx_trylock"}, 1}, + {CDM::CLibrary, {"mtx_unlock"}, 1}), + FirstArgMutexDescriptor({CDM::CLibrary, {"mtx_timedlock"}, 1}, + {CDM::CLibrary, {"mtx_unlock"}, 1}), RAIIMutexDescriptor("lock_guard"), RAIIMutexDescriptor("unique_lock")}; - const CallDescriptionSet BlockingFunctions{ - {CDM::CLibrary, {"sleep"}}, - {CDM::CLibrary, {"getc"}}, - {CDM::CLibrary, {"fgets"}}, - {CDM::CLibrary, {"read"}}, - {CDM::CLibrary, {"recv"}}}; + const CallDescriptionSet BlockingFunctions{{CDM::CLibrary, {"sleep"}}, + {CDM::CLibrary, {"getc"}}, + {CDM::CLibrary, {"fgets"}}, + {CDM::CLibrary, {"read"}}, + {CDM::CLibrary, {"recv"}}}; const BugType BlockInCritSectionBugType{ this, "Call to blocking function in critical section", "Blocking Error"}; `` https://github.com/llvm/llvm-project/pull/90974 ___ 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 more checkers (PR #90974)
=?utf-8?q?Donát?= Nagy Message-ID: In-Reply-To: llvmbot wrote: @llvm/pr-subscribers-clang Author: Donát Nagy (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 various checkers. Some code was simplified to use `CallDescriptionSet`s instead of individual `CallDescription`s. 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 have already performed this change in other checkers: - easy cases: e2f1cbae45f81f3cd9a4d3c2bcf69a094eb060fa - MallocChecker: d6d84b5d1448e4f2e24b467a0abcf42fe9d543e9 - iterator checkers: 06eedffe0d2782922e63cc25cb927f4acdaf7b30 - InvalidPtr checker: 024281d4d26344f9613b9115ea1fcbdbdba23235 ... and follow-up commits will handle the remaining 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. --- Full diff: https://github.com/llvm/llvm-project/pull/90974.diff 5 Files Affected: - (modified) clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp (+26-19) - (modified) clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp (+2-2) - (modified) clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp (+25-33) - (modified) clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp (+9-9) - (modified) clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp (+5-3) ``diff diff --git a/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp index e4373915410fb..290916c3c1413 100644 --- a/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp @@ -149,26 +149,34 @@ class BlockInCriticalSectionChecker : public Checker { private: const std::array MutexDescriptors{ MemberMutexDescriptor( - CallDescription(/*QualifiedName=*/{"std", "mutex", "lock"}, - /*RequiredArgs=*/0), - CallDescription({"std", "mutex", "unlock"}, 0)), - FirstArgMutexDescriptor(CallDescription({"pthread_mutex_lock"}, 1), - CallDescription({"pthread_mutex_unlock"}, 1)), - FirstArgMutexDescriptor(CallDescription({"mtx_lock"}, 1), - CallDescription({"mtx_unlock"}, 1)), - FirstArgMutexDescriptor(CallDescription({"pthread_mutex_trylock"}, 1), - CallDescription({"pthread_mutex_unlock"}, 1)), - FirstArgMutexDescriptor(CallDescription({"mtx_trylock"}, 1), - CallDescription({"mtx_unlock"}, 1)), - FirstArgMutexDescriptor(CallDescription({"mtx_timedlock"}, 1), - CallDescription({"mtx_unlock"}, 1)), + {/*MatchAs=*/CDM::CXXMethod, + /*QualifiedName=*/{"std", "mutex", "lock"}, + /*RequiredArgs=*/0}, + {CDM::CXXMethod, {"std", "mutex", "unlock"}, 0}), + FirstArgMutexDescriptor( + {CDM::CLibrary, {"pthread_mutex_lock"}, 1}, + {CDM::CLibrary, {"pthread_mutex_unlock"}, 1}), + FirstArgMutexDescriptor( + {CDM::CLibrary, {"mtx_lock"}, 1}, + {CDM::CLibrary, {"mtx_unlock"}, 1}), + FirstArgMutexDescriptor( + {CDM::CLibrary, {"pthread_mutex_trylock"}, 1}, + {CDM::CLibrary, {"pthread_mutex_unlock"}, 1}), + FirstArgMutexDescriptor( + {CDM::CLibrary, {"mtx_trylock"}, 1}, + {CDM::CLibrary, {"mtx_unlock"}, 1}), + FirstArgMutexDescriptor( + {CDM::CLibrary, {"mtx_timedlock"}, 1}, + {CDM::CLibrary, {"mtx_unlock"}, 1}), RAIIMutexDescriptor("lock_guard"), RAIIMutexDescriptor("unique_lock")}; - const std::array BlockingFunctions{ - ArrayRef{StringRef{"sleep"}}, ArrayRef{StringRef{"getc"}}, - ArrayRef{StringRef{"fgets"}}, ArrayRef{StringRef{"read"}}, - ArrayRef{StringRef{"recv"}}}; + const CallDescriptionSet BlockingFunctions{ + {CDM::CLibrary, {"sleep"}}, + {CDM::CLibrary, {"getc"}}, + {CDM::CLibrary, {"fgets"}}, + {CDM::CLibrary, {"read"}}, + {CDM::CLibrary, {"recv"}}}; const BugType BlockInCritSectionBugType{ this, "Call to blocking function in critical section", "Blocking Error"}; @@ -291,8 +299,7 @@ void BlockInCriticalSectionChecker::handleUnlock( bool BlockInCriticalSectionChecker::isBlockingInCritSection( const CallEvent , CheckerContext ) const { - return llvm::any_of(BlockingFunctions, - [](auto &) { return Fn.matches(Call); }) && + return BlockingFunctions.contains(Call) && !C.getState()->get().isEmpty(); } diff --git
[clang] [analyzer] Use explicit call description mode in more checkers (PR #90974)
https://github.com/NagyDonat updated https://github.com/llvm/llvm-project/pull/90974 From 9ed06c41127c88b3e2e8596ddd83b42ab2856f61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Don=C3=A1t=20Nagy?= Date: Fri, 3 May 2024 16:13:19 +0200 Subject: [PATCH 1/2] [analyzer] Use explicit call description mode in more checkers This commit explicitly specifies the matching mode (C library function, any non-method function, or C++ method) for the `CallDescription`s constructed in various checkers. Some code was simplified to use `CallDescriptionSet`s instead of individual `CallDescription`s. 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 have already performed this change in other checkers: - easy chases: e2f1cbae45f81f3cd9a4d3c2bcf69a094eb060fa - MallocChecker: d6d84b5d1448e4f2e24b467a0abcf42fe9d543e9 - iterator checkers: 06eedffe0d2782922e63cc25cb927f4acdaf7b30 - InvalidPtr checker: 024281d4d26344f9613b9115ea1fcbdbdba23235 ... and follow-up commits will handle the remaining 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. --- .../BlockInCriticalSectionChecker.cpp | 38 +++- .../Checkers/CStringChecker.cpp | 4 +- .../Checkers/InnerPointerChecker.cpp | 58 --- .../Checkers/SmartPtrModeling.cpp | 18 +++--- .../StaticAnalyzer/Checkers/StreamChecker.cpp | 8 ++- 5 files changed, 64 insertions(+), 62 deletions(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp index e4373915410fb2..9b612d03e93c31 100644 --- a/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp @@ -149,26 +149,34 @@ class BlockInCriticalSectionChecker : public Checker { private: const std::array MutexDescriptors{ MemberMutexDescriptor( - CallDescription(/*QualifiedName=*/{"std", "mutex", "lock"}, + CallDescription(/*MatchAs=*/CDM::CXXMethod, + /*QualifiedName=*/{"std", "mutex", "lock"}, /*RequiredArgs=*/0), - CallDescription({"std", "mutex", "unlock"}, 0)), - FirstArgMutexDescriptor(CallDescription({"pthread_mutex_lock"}, 1), - CallDescription({"pthread_mutex_unlock"}, 1)), - FirstArgMutexDescriptor(CallDescription({"mtx_lock"}, 1), - CallDescription({"mtx_unlock"}, 1)), - FirstArgMutexDescriptor(CallDescription({"pthread_mutex_trylock"}, 1), - CallDescription({"pthread_mutex_unlock"}, 1)), - FirstArgMutexDescriptor(CallDescription({"mtx_trylock"}, 1), - CallDescription({"mtx_unlock"}, 1)), - FirstArgMutexDescriptor(CallDescription({"mtx_timedlock"}, 1), - CallDescription({"mtx_unlock"}, 1)), + CallDescription(CDM::CXXMethod, {"std", "mutex", "unlock"}, 0)), + FirstArgMutexDescriptor( + CallDescription(CDM::CLibrary, {"pthread_mutex_lock"}, 1), + CallDescription(CDM::CLibrary, {"pthread_mutex_unlock"}, 1)), + FirstArgMutexDescriptor( + CallDescription(CDM::CLibrary, {"mtx_lock"}, 1), + CallDescription(CDM::CLibrary, {"mtx_unlock"}, 1)), + FirstArgMutexDescriptor( + CallDescription(CDM::CLibrary, {"pthread_mutex_trylock"}, 1), + CallDescription(CDM::CLibrary, {"pthread_mutex_unlock"}, 1)), + FirstArgMutexDescriptor( + CallDescription(CDM::CLibrary, {"mtx_trylock"}, 1), + CallDescription(CDM::CLibrary, {"mtx_unlock"}, 1)), + FirstArgMutexDescriptor( + CallDescription(CDM::CLibrary, {"mtx_timedlock"}, 1), + CallDescription(CDM::CLibrary, {"mtx_unlock"}, 1)), RAIIMutexDescriptor("lock_guard"), RAIIMutexDescriptor("unique_lock")}; const std::array BlockingFunctions{ - ArrayRef{StringRef{"sleep"}}, ArrayRef{StringRef{"getc"}}, - ArrayRef{StringRef{"fgets"}}, ArrayRef{StringRef{"read"}}, - ArrayRef{StringRef{"recv"}}}; + CallDescription(CDM::CLibrary, {"sleep"}), + CallDescription(CDM::CLibrary, {"getc"}), + CallDescription(CDM::CLibrary, {"fgets"}), + CallDescription(CDM::CLibrary, {"read"}), + CallDescription(CDM::CLibrary, {"recv"})}; const BugType BlockInCritSectionBugType{ this, "Call to blocking function in critical section", "Blocking Error"}; diff --git a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp index f9548b5c3010bf..238e87a712a43a 100644 ---
[clang] [analyzer] Use explicit call description mode in more checkers (PR #90974)
@@ -149,26 +149,34 @@ class BlockInCriticalSectionChecker : public Checker { private: const std::array MutexDescriptors{ MemberMutexDescriptor( - CallDescription(/*QualifiedName=*/{"std", "mutex", "lock"}, + CallDescription(/*MatchAs=*/CDM::CXXMethod, + /*QualifiedName=*/{"std", "mutex", "lock"}, /*RequiredArgs=*/0), steakhal wrote: Do we need the `CallDescription(...)` stuff? Couldn't we just use braces `{...}` like we usually do? https://github.com/llvm/llvm-project/pull/90974 ___ 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 more checkers (PR #90974)
https://github.com/steakhal approved this pull request. LGTM, thanks. I had one minor nit. https://github.com/llvm/llvm-project/pull/90974 ___ 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 more checkers (PR #90974)
https://github.com/steakhal edited https://github.com/llvm/llvm-project/pull/90974 ___ 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 more checkers (PR #90974)
https://github.com/steakhal edited https://github.com/llvm/llvm-project/pull/90974 ___ 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 more checkers (PR #90974)
https://github.com/gamesh411 approved this pull request. LGTM, I especially like how InnerPointerChecker was simplified. https://github.com/llvm/llvm-project/pull/90974 ___ 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 more checkers (PR #90974)
https://github.com/NagyDonat created https://github.com/llvm/llvm-project/pull/90974 This commit explicitly specifies the matching mode (C library function, any non-method function, or C++ method) for the `CallDescription`s constructed in various checkers. Some code was simplified to use `CallDescriptionSet`s instead of individual `CallDescription`s. 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 have already performed this change in other checkers: - easy chases: e2f1cbae45f81f3cd9a4d3c2bcf69a094eb060fa - MallocChecker: d6d84b5d1448e4f2e24b467a0abcf42fe9d543e9 - iterator checkers: 06eedffe0d2782922e63cc25cb927f4acdaf7b30 - InvalidPtr checker: 024281d4d26344f9613b9115ea1fcbdbdba23235 ... and follow-up commits will handle the remaining 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. From 9ed06c41127c88b3e2e8596ddd83b42ab2856f61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Don=C3=A1t=20Nagy?= Date: Fri, 3 May 2024 16:13:19 +0200 Subject: [PATCH] [analyzer] Use explicit call description mode in more checkers This commit explicitly specifies the matching mode (C library function, any non-method function, or C++ method) for the `CallDescription`s constructed in various checkers. Some code was simplified to use `CallDescriptionSet`s instead of individual `CallDescription`s. 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 have already performed this change in other checkers: - easy chases: e2f1cbae45f81f3cd9a4d3c2bcf69a094eb060fa - MallocChecker: d6d84b5d1448e4f2e24b467a0abcf42fe9d543e9 - iterator checkers: 06eedffe0d2782922e63cc25cb927f4acdaf7b30 - InvalidPtr checker: 024281d4d26344f9613b9115ea1fcbdbdba23235 ... and follow-up commits will handle the remaining 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. --- .../BlockInCriticalSectionChecker.cpp | 38 +++- .../Checkers/CStringChecker.cpp | 4 +- .../Checkers/InnerPointerChecker.cpp | 58 --- .../Checkers/SmartPtrModeling.cpp | 18 +++--- .../StaticAnalyzer/Checkers/StreamChecker.cpp | 8 ++- 5 files changed, 64 insertions(+), 62 deletions(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp index e4373915410fb2..9b612d03e93c31 100644 --- a/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp @@ -149,26 +149,34 @@ class BlockInCriticalSectionChecker : public Checker { private: const std::array MutexDescriptors{ MemberMutexDescriptor( - CallDescription(/*QualifiedName=*/{"std", "mutex", "lock"}, + CallDescription(/*MatchAs=*/CDM::CXXMethod, + /*QualifiedName=*/{"std", "mutex", "lock"}, /*RequiredArgs=*/0), - CallDescription({"std", "mutex", "unlock"}, 0)), - FirstArgMutexDescriptor(CallDescription({"pthread_mutex_lock"}, 1), - CallDescription({"pthread_mutex_unlock"}, 1)), - FirstArgMutexDescriptor(CallDescription({"mtx_lock"}, 1), - CallDescription({"mtx_unlock"}, 1)), - FirstArgMutexDescriptor(CallDescription({"pthread_mutex_trylock"}, 1), - CallDescription({"pthread_mutex_unlock"}, 1)), - FirstArgMutexDescriptor(CallDescription({"mtx_trylock"}, 1), - CallDescription({"mtx_unlock"}, 1)), - FirstArgMutexDescriptor(CallDescription({"mtx_timedlock"}, 1), - CallDescription({"mtx_unlock"}, 1)), + CallDescription(CDM::CXXMethod, {"std", "mutex", "unlock"}, 0)), + FirstArgMutexDescriptor( + CallDescription(CDM::CLibrary, {"pthread_mutex_lock"}, 1), + CallDescription(CDM::CLibrary, {"pthread_mutex_unlock"}, 1)), + FirstArgMutexDescriptor( + CallDescription(CDM::CLibrary, {"mtx_lock"}, 1), + CallDescription(CDM::CLibrary, {"mtx_unlock"}, 1)), + FirstArgMutexDescriptor( + CallDescription(CDM::CLibrary, {"pthread_mutex_trylock"}, 1), + CallDescription(CDM::CLibrary, {"pthread_mutex_unlock"}, 1)), + FirstArgMutexDescriptor( + CallDescription(CDM::CLibrary, {"mtx_trylock"}, 1), +