[analyzer] Improve VirtualCallChecker and enable parts of it by default.
authorArtem Dergachev <artem.dergachev@gmail.com>
Tue, 20 Aug 2019 21:41:14 +0000 (21:41 +0000)
committerArtem Dergachev <artem.dergachev@gmail.com>
Tue, 20 Aug 2019 21:41:14 +0000 (21:41 +0000)
commitd3971fe97b64785c079d64bf4c8c3e2b5e1f85a1
tree24db2ed70a09909a251b77ad61768165dfb750a4
parent7fa6865392692e1446376e52f9c2b264d58b2294
[analyzer] Improve VirtualCallChecker and enable parts of it by default.

Calling a pure virtual method during construction or destruction
is undefined behavior. It's worth it to warn about it by default.
That part is now known as the cplusplus.PureVirtualCall checker.

Calling a normal virtual method during construction or destruction
may be fine, but does behave unexpectedly, as it skips virtual dispatch.
Do not warn about this by default, but let projects opt in into it
by enabling the optin.cplusplus.VirtualCall checker manually.

Give the two parts differentiated warning text:

  Before:

    Call to virtual function during construction or destruction:
    Call to pure virtual function during construction

    Call to virtual function during construction or destruction:
    Call to virtual function during destruction

  After:

    Pure virtual method call:
    Call to pure virtual method 'X::foo' during construction
        has undefined behavior

    Unexpected loss of virtual dispatch:
    Call to virtual method 'Y::bar' during construction
        bypasses virtual dispatch

Also fix checker names in consumers that support them (eg., clang-tidy)
because we now have different checker names for pure virtual calls and
regular virtual calls.

Also fix capitalization in the bug category.

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

llvm-svn: 369449
clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
clang/include/clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h
clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
clang/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
clang/lib/StaticAnalyzer/Core/CommonBugCategories.cpp
clang/test/Analysis/virtualcall-plist.cpp [new file with mode: 0644]
clang/test/Analysis/virtualcall.cpp
clang/test/Analysis/virtualcall.h