13 Commits

Author SHA1 Message Date
Ryosuke Niwa
fd21b7911f
[webkit.RefCntblBaseVirtualDtor] ThreadSafeRefCounted still generates warnings (#108656)
Improve the fix in 203a2ca8cd6af505e11a38aebceeaf864271042c by allowing
variable references and more ignoring of parentheses.
2024-09-17 22:23:27 -07:00
Ryosuke Niwa
203a2ca8cd
[webkit.RefCntblBaseVirtualDtor] Make ThreadSafeRefCounted not generate warnings (#107676)
This PR makes WebKit's RefCntblBaseVirtualDtor checker not generate a
warning for ThreadSafeRefCounted when the destruction thread is a
specific thread.

Prior to this PR, we only allowed CRTP classes without a virtual
destructor if its deref function had an explicit cast to the derived
type, skipping any lambda declarations which aren't invoked. This ends
up generating a warning for ThreadSafeRefCounted when a specific thread
is used to destruct the object because there is no inline body /
definition for ensureOnMainThread and ensureOnMainRunLoop and
DerefFuncDeleteExprVisitor concludes that there is no explicit delete of
the derived type.

This PR relaxes the condition DerefFuncDeleteExprVisitor checks by
allowing a delete expression to appear within a lambda declaration if
it's an argument to an "opaque" function; i.e. a function without
definition / body.
2024-09-10 22:25:03 -07:00
Ryosuke Niwa
f28085aac2
Fix the warning in RefCntblBaseVirtualDtorChecker.cpp:61 (#93403) 2024-05-26 10:50:53 -07:00
Ryosuke Niwa
faef8b4aa2
[webkit.RefCntblBaseVirtualDtor] Allow CRTP classes without a virtual destructor. (#92837)
Exempt CRTP (Curiously Recurring Template Pattern) classes with a delete
operation acting on "this" pointer with an appropriate cast from the
requirement that a ref-countable superclass must have a virtual
destructor.

To do this, this PR introduces new DerefFuncDeleteExprVisitor, which
looks for a delete operation with an explicit cast to the derived class
in a base class.

This PR also changes the checker so that we only check a given class's
immediate base class instead of all ancestor base classes in the class
hierarchy. This is sufficient because the checker will eventually see
the definition for every class in the class hierarchy and transitively
proves every ref-counted base class has a virtual destructor or deref
function which casts this pointer back to the derived class before
deleting. Without this change, we would keep traversing the same list of
base classes whenever we encounter a new subclass, which is wholly
unnecessary.

It's possible for DerefFuncDeleteExprVisitor to come to a conclusoin that
there isn't enough information to determine whether a given templated
superclass invokes delete operation on a subclass when the template
isn't fully specialized for the subclass. In this case, we return
std::nullopt in HasSpecializedDelete, and visitCXXRecordDecl will skip
this declaration. This is okay because the checker will eventually see a
concreate fully specialized class definition if it ever gets
instantiated.
2024-05-25 09:32:48 -07:00
Ryosuke Niwa
6d6693e9f5
[webkit.RefCntblBaseVirtualDtor] Ignore WTF::RefCounted<T> and its variants missing virtual destructor (#91009) 2024-05-06 16:01:45 -07:00
Ryosuke Niwa
09273d408d
Fix WebKit static analyzers to support ref and deref methods to be defined on different classes. (#69985) 2023-11-10 12:21:36 -08:00
Vlad Serebrennikov
edd690b02e
[clang][NFC] Refactor TagTypeKind (#71160)
This patch converts TagTypeKind into scoped enum. Among other benefits,
this allows us to forward-declare it where necessary.
2023-11-03 21:45:39 +04:00
Kazu Hirata
6ad0788c33 [clang] Use std::optional instead of llvm::Optional (NFC)
This patch replaces (llvm::|)Optional< with std::optional<.  I'll post
a separate patch to remove #include "llvm/ADT/Optional.h".

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-14 12:31:01 -08:00
Kazu Hirata
a1580d7b59 [clang] Add #include <optional> (NFC)
This patch adds #include <optional> to those files containing
llvm::Optional<...> or Optional<...>.

I'll post a separate patch to actually replace llvm::Optional with
std::optional.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-14 11:07:21 -08:00
Jan Korous
47e6851423 [Analyzer][WebKit] Use tri-state types for relevant predicates
Some of the predicates can't always be decided - for example when a type
definition isn't available. At the same time it's necessary to let
client code decide what to do about such cases - specifically we can't
just use true or false values as there are callees with
conflicting strategies how to handle this.

This is a speculative fix for PR47276.

Differential Revision: https://reviews.llvm.org/D88133
2020-09-22 21:57:24 -07:00
Jan Korous
54e91a3c70 Reland "[Analyzer][WebKit] RefCntblBaseVirtualDtorChecker"
This reverts commit 1108f5c737dbdab0277874a7e5b237491839c43a.
2020-05-21 16:41:00 -07:00
Nico Weber
1108f5c737 Revert "[Analyzer][WebKit] RefCntblBaseVirtualDtorChecker"
This reverts commit f7c7e8a523f56b0ed1b14c0756ba4e5d1ccb48d2.
Breaks build everywhere.
2020-05-21 15:49:46 -04:00
Jan Korous
f7c7e8a523 [Analyzer][WebKit] RefCntblBaseVirtualDtorChecker
Differential Revision: https://reviews.llvm.org/D77177
2020-05-21 11:54:49 -07:00