[analyzer] Add checker modeling gtest APIs.
authorDevin Coughlin <dcoughlin@apple.com>
Mon, 19 Dec 2016 22:50:31 +0000 (22:50 +0000)
committerDevin Coughlin <dcoughlin@apple.com>
Mon, 19 Dec 2016 22:50:31 +0000 (22:50 +0000)
commit8beac28564e9769efa9f473bafe6a5ff8d0e88b3
treeb83b5e52b01bb2bc9eafde7cbefbc0052c15fa26
parentfb7dd86fd667fa24dfb2bc2bb323d976058816e8
[analyzer] Add checker modeling gtest APIs.

gtest is a widely-used unit-testing API. It provides macros for unit test
assertions:

  ASSERT_TRUE(p != nullptr);

that expand into an if statement that constructs an object representing
the result of the assertion and returns when the assertion is false:

  if (AssertionResult gtest_ar_ = AssertionResult(p == nullptr))
      ;
  else
    return ...;

Unfortunately, the analyzer does not model the effect of the constructor
precisely because (1) the copy constructor implementation is missing from the
the header (so it can't be inlined) and (2) the boolean-argument constructor
is constructed into a temporary (so the analyzer decides not to inline it since
it doesn't reliably call temporary destructors right now).

This results in false positives because the analyzer does not realize that the
the assertion must hold along the non-return path.

This commit addresses the false positives by explicitly modeling the effects
of the two un-inlined constructors on the AssertionResult state.

I've added a new package, "apiModeling", for these kinds of checkers that
model APIs but don't emit any diagnostics. I envision all the checkers in
this package always being on by default.

This addresses the false positives reported in PR30936.

Differential Revision: https://reviews.llvm.org/D27773

rdar://problem/22705813

llvm-svn: 290143
clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
clang/lib/Driver/Tools.cpp
clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
clang/lib/StaticAnalyzer/Checkers/GTestChecker.cpp [new file with mode: 0644]
clang/test/Analysis/gtest.cpp [new file with mode: 0644]
clang/test/Driver/analyzer-target-enabled-checkers.cpp