diff --git a/clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp --- a/clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp @@ -35,9 +35,9 @@ class InnerPointerChecker : public Checker { - 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 @@ 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 @@ 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 --- a/clang/test/Analysis/inner-pointer.cpp +++ b/clang/test/Analysis/inner-pointer.cpp @@ -20,6 +20,9 @@ template T *addressof(T &arg); +template +T *__addressof(T &arg); + char *data(std::string &c); } // end namespace std @@ -383,6 +386,14 @@ 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;