[clang] cf7cd66 - [analyzer] Check for std::__addressof for inner pointer checker
Balazs Benics via cfe-commits
cfe-commits at lists.llvm.org
Tue May 3 05:05:48 PDT 2022
Author: Ali Shuja Siddiqui
Date: 2022-05-03T14:05:19+02:00
New Revision: cf7cd664f3fd212c0f1e4a83fd2fe96902569d20
URL: https://github.com/llvm/llvm-project/commit/cf7cd664f3fd212c0f1e4a83fd2fe96902569d20
DIFF: https://github.com/llvm/llvm-project/commit/cf7cd664f3fd212c0f1e4a83fd2fe96902569d20.diff
LOG: [analyzer] Check for std::__addressof for inner pointer checker
This is an extension to diff D99260. This adds an additional exception
for `std::__addressof` in `InnerPointerChecker`.
Patch By alishuja (Ali Shuja Siddiqui)!
Reviewed By: martong, alishuja
Differential Revision: https://reviews.llvm.org/D109467
Added:
Modified:
clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
clang/test/Analysis/inner-pointer.cpp
Removed:
################################################################################
diff --git a/clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
index a50674dc70f42..895212d134b88 100644
--- a/clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
@@ -35,9 +35,9 @@ namespace {
class InnerPointerChecker
: public Checker<check::DeadSymbols, check::PostCall> {
- CallDescription AppendFn, AssignFn, AddressofFn, ClearFn, CStrFn, DataFn,
- DataMemberFn, EraseFn, InsertFn, PopBackFn, PushBackFn, ReplaceFn,
- ReserveFn, ResizeFn, ShrinkToFitFn, SwapFn;
+ CallDescription AppendFn, AssignFn, AddressofFn, AddressofFn_, ClearFn,
+ CStrFn, DataFn, DataMemberFn, EraseFn, InsertFn, PopBackFn, PushBackFn,
+ ReplaceFn, ReserveFn, ResizeFn, ShrinkToFitFn, SwapFn;
public:
class InnerPointerBRVisitor : public BugReporterVisitor {
@@ -74,7 +74,7 @@ class InnerPointerChecker
InnerPointerChecker()
: AppendFn({"std", "basic_string", "append"}),
AssignFn({"std", "basic_string", "assign"}),
- AddressofFn({"std", "addressof"}),
+ AddressofFn({"std", "addressof"}), AddressofFn_({"std", "__addressof"}),
ClearFn({"std", "basic_string", "clear"}),
CStrFn({"std", "basic_string", "c_str"}), DataFn({"std", "data"}, 1),
DataMemberFn({"std", "basic_string", "data"}),
@@ -179,9 +179,9 @@ void InnerPointerChecker::checkFunctionArguments(const CallEvent &Call,
if (!ArgRegion)
continue;
- // std::addressof function accepts a non-const reference as an argument,
+ // std::addressof functions accepts a non-const reference as an argument,
// but doesn't modify it.
- if (AddressofFn.matches(Call))
+ if (matchesAny(Call, AddressofFn, AddressofFn_))
continue;
markPtrSymbolsReleased(Call, State, ArgRegion, C);
diff --git a/clang/test/Analysis/inner-pointer.cpp b/clang/test/Analysis/inner-pointer.cpp
index 5db17a952f90b..4cb194409412c 100644
--- a/clang/test/Analysis/inner-pointer.cpp
+++ b/clang/test/Analysis/inner-pointer.cpp
@@ -20,6 +20,9 @@ void default_arg(int a = 42, string &b = my_string);
template <class T>
T *addressof(T &arg);
+template <class T>
+T *__addressof(T &arg);
+
char *data(std::string &c);
} // end namespace std
@@ -383,6 +386,14 @@ void func_addressof() {
consume(c); // no-warning
}
+void func_AddressofFn_() {
+ const char *c;
+ std::string s;
+ c = s.c_str();
+ (void)std::__addressof(s);
+ consume(c); // no-warning
+}
+
void func_std_data() {
const char *c;
std::string s;
More information about the cfe-commits
mailing list