]> granicus.if.org Git - clang/commit
[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)
commitbb48adc4fe79c1b1eaf91c90ef8ab7d46e530899
treee8c4de498290d03783e3094994e05e4174ca2f45
parent4ae8f25fd92e267ed7a99289032d57746151158a
[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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@369449 91177308-0d34-0410-b5e6-96231b3b80d8
include/clang/StaticAnalyzer/Checkers/Checkers.td
include/clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h
include/clang/StaticAnalyzer/Core/CheckerManager.h
lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
lib/StaticAnalyzer/Core/CommonBugCategories.cpp
test/Analysis/virtualcall-plist.cpp [new file with mode: 0644]
test/Analysis/virtualcall.cpp
test/Analysis/virtualcall.h