[PATCH] D36475: [analyzer] Add "create_sink" annotation support to MagentaHandleChecker

Haowei Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 8 10:37:49 PDT 2017


haowei created this revision.
Herald added a subscriber: xazax.hun.

This patch adds "mx_create_sink" annotation support to MagentaHandleChecker to address the false positives found in Magenta unit tests. After this patch, when a call to a function contains this annotation, MagentaHandleChecker will create a sink node which will suppress the handle leaks warnings if the leak is post-dominated by this function (similar to a noreturn function).

The target problem it tries to solve can be illustrated in following example:

  static bool handle_info_test(void) {
      BEGIN_TEST;
  
      mx_handle_t event;
      ASSERT_EQ(mx_event_create(0u, &event), 0, "");
      mx_handle_t duped;
      mx_status_t status = mx_handle_duplicate(event, MX_RIGHT_SAME_RIGHTS, &duped);
      ASSERT_EQ(status, MX_OK, "");
      // ....
  }

Unlike the "assert" keyword in C++, the ASSERT_EQ macro will not terminate the execution of the unit test program (in other words, it will not invoke a noreturn function), instead it will return false and the error will be recorded by the unit test runner. Therefore, before this patch, the MagentaHandleChecker will report handle leaks on these assertion failures as the function reaches return and symbol that contains the acquired handles are acquired. These reports are not helpful as assertion failures in unit tests mean test failures. With the help of this patch, we add a call to a function with "mx_create_sink" annotation in the failure branch in definition "ASSERT_EQ". In this case, the MagentaHandleChecker will create a sink node in each assertion failure and suppress the warnings if the leaks are post-dominated by assertion failures.


https://reviews.llvm.org/D36475

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36475.110224.patch
Type: text/x-patch
Size: 3576 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170808/86e99a5f/attachment.bin>


More information about the cfe-commits mailing list