[PATCH] D109467: [analyzer] check for std::__addressof for inner pointer checker

Ali Shuja Siddiqui via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 8 14:49:56 PDT 2021


alishuja created this revision.
alishuja added reviewers: NoQ, steakhal, xazax.hun, ASDenysPetrov.
Herald added subscribers: manas, martong, dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware.
alishuja requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is an extension to diff D99260 <https://reviews.llvm.org/D99260>. This adds an additional exception for std::__addressof in InnerPointerChecker.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D109467

Files:
  clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp


Index: clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
@@ -34,9 +34,9 @@
 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 {
@@ -73,7 +73,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"}),
@@ -184,7 +184,7 @@

       // std::addressof function accepts a non-const reference as an argument,
       // but doesn't modify it.
-      if (Call.isCalled(AddressofFn))
+      if (Call.isCalled(AddressofFn) || Call.isCalled(AddressofFn_))
         continue;

       markPtrSymbolsReleased(Call, State, ArgRegion, C);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109467.371443.patch
Type: text/x-patch
Size: 1638 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210908/5acfcfbf/attachment-0001.bin>


More information about the cfe-commits mailing list