[PATCH] D36024: [analyzer] Improved bug reporting in MagentaHandleChecker

2021-01-05 Thread Haowei Wu via Phabricator via cfe-commits
haowei abandoned this revision.
haowei added a comment.
Herald added subscribers: steakhal, ASDenysPetrov, Charusso, dkrupp, 
donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware.

An updated version was landed in f4c26d993bdc 
 . This 
diff is no longer needed.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D36024/new/

https://reviews.llvm.org/D36024

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36024: [analyzer] Improved bug reporting in MagentaHandleChecker

2017-07-28 Thread Haowei Wu via Phabricator via cfe-commits
haowei created this revision.
Herald added a subscriber: xazax.hun.

This commit improves the bug reporting of MagentaHandleChecker introduced in 
https://reviews.llvm.org/D35968 , https://reviews.llvm.org/D36022 and 
https://reviews.llvm.org/D36023.

After this commit, the allocation and release sites of the handle that causes a 
bug will be marked in the generated bug report.  If the handle is declared as a 
local variable, the naming of the handle will also be marked in the generated 
bug report as well.


https://reviews.llvm.org/D36024

Files:
  lib/StaticAnalyzer/Checkers/MagentaHandleChecker.cpp
  test/Analysis/mxhandle.c

Index: test/Analysis/mxhandle.c
===
--- test/Analysis/mxhandle.c
+++ test/Analysis/mxhandle.c
@@ -210,16 +210,16 @@
 void checkLeak01() {
   mx_handle_t sa, sb;
   mx_channel_create(0, , );
-} // expected-warning {{Potential leak of handle}}
+} // expected-warning 2 {{Potential leak of handle pointed to by}}
 
 
 void checkLeak02(int tag) {
   mx_handle_t sa, sb;
   mx_channel_create(0, , );
   if (tag) {
 mx_handle_close(sa);
   }
-  mx_handle_close(sb); // expected-warning {{Potential leak of handle}}
+  mx_handle_close(sb); // expected-warning {{Potential leak of handle pointed to by 'sa'}}
 }
 
 void checkLeak03(mx_handle_t handle) {
@@ -273,24 +273,24 @@
   mx_channel_create(0, , );
 
   useHandle01(sa);
-  mx_handle_close(sb); // expected-warning {{Potential leak of handle}}
+  mx_handle_close(sb); // expected-warning {{Potential leak of handle pointed to by 'sa'}}
 }
 
 void checkLeak08() {
   mx_handle_t sa, sb;
   mx_channel_create(0, , );
 
   useHandle02();
-  mx_handle_close(sb); // expected-warning {{Potential leak of handle}}
+  mx_handle_close(sb); // expected-warning {{Potential leak of handle pointed to by 'sa'}}
 }
 
 void checkDoubleRelease01(int tag) {
   mx_handle_t sa, sb;
   mx_channel_create(0, , );
   if (tag) {
 mx_handle_close(sa);
   }
-  mx_handle_close(sa); // expected-warning {{Releasing a previously released handle}}
+  mx_handle_close(sa); // expected-warning {{Releasing a previously released handle pointed to by 'sa'}}
   mx_handle_close(sb);
 }
 
@@ -300,7 +300,27 @@
   if (tag) {
 mx_handle_close(sa);
   }
-  useHandle01(sa); // expected-warning {{Using a previously released handle}}
+  useHandle01(sa); // expected-warning {{Using a previously released handle pointed to by 'sa'}}
   mx_handle_close(sa);
   mx_handle_close(sb);
 }
+
+void checkSuppressWarning01() MX_SYSCALL_PARAM_ATTR(suppress_warning) {
+  mx_handle_t sa, sb;
+  if (mx_channel_create(0, , ) < 0) {
+return;
+  }
+  mx_handle_close(sa); // Should not report any bugs here
+}
+
+void checkSuppressWarning02() {
+  mx_handle_t sa, sb;
+  if (mx_channel_create(0, , ) < 0) {
+return;
+  }
+  mx_handle_close(sa); // Should not report any bugs here
+}
+
+void checkSuppressWarning03() MX_SYSCALL_PARAM_ATTR(suppress_warning) {
+  checkSuppressWarning02();
+}
Index: lib/StaticAnalyzer/Checkers/MagentaHandleChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/MagentaHandleChecker.cpp
+++ lib/StaticAnalyzer/Checkers/MagentaHandleChecker.cpp
@@ -235,6 +235,7 @@
 static const char *HANDLE_TYPE_NAME = "mx_handle_t";
 static const char *SYSCALL_RETURN_TYPE_NAME = "mx_status_t";
 static const int MAX_HANDLE_IN_ARRAY = 64;
+typedef std::pair AllocInfo;
 
 class MagentaHandleChecker
 : public Checker HandleState map
 REGISTER_MAP_WITH_PROGRAMSTATE(HStateMap, SymbolRef, HandleState)
 
+std::shared_ptr
+MagentaBugVisitor::VisitNode(const ExplodedNode *N, const ExplodedNode *PrevN,
+ BugReporterContext , BugReport ) {
+  ProgramStateRef State = N->getState();
+