23 Commits

Author SHA1 Message Date
Florian Mayer
ad905f133c [NFC] [clang] Use isa instead of dyn_cast 2025-02-11 13:42:31 -08:00
Florian Mayer
5c7071e996
[NFC] [clang] fix unused variable warning (#126796) 2025-02-11 13:22:22 -08:00
Ryosuke Niwa
8c67f14f62
[WebKit Checkers] Allow operator T&() in a const member function (#126470)
Allow operator T&() in a member function which returns a const member
variable.

In particular, this will allow UniqueRef::operator T&() and
Ref::operator T&() to be treated as a safe pointer origin when they're
called on a const member.
2025-02-11 11:07:52 -08:00
Ryosuke Niwa
71478ecdb4
[WebKit Checkers] Treat const Objective-C ivar as a safe origin (#126353)
Like const C++ member variables, treat const Ref, RefPtr, CheckedRef,
CheckedPtr Objective-C ivars as a safe pointer origin in WebKit
checkers.
2025-02-11 10:00:09 -08:00
Ryosuke Niwa
05860f9b38
[WebKit checkers] Recognize ensureFoo functions (#119681)
In WebKit, we often write Foo::ensureBar function which lazily
initializes m_bar and returns a raw pointer or a raw reference to m_bar.
Such a return value is safe to use for the duration of a member function
call in Foo so long as m_bar is const so that it never gets unset or
updated with a new value once it's initialized.

This PR adds support for recognizing these types of functions and
treating its return value as a safe origin of a function argument
(including "this") or a local variable.
2024-12-13 01:48:29 -08:00
Ryosuke Niwa
f7e868fe43
Fix a bug that CXXConstructExpr wasn't recognized by tryToFindPtrOrigin (#119336)
Prior to this PR, only CXXTemporaryObjectExpr, not CXXConstructExpr was
recognized in tryToFindPtrOrigin.
2024-12-12 09:37:04 -08:00
Ryosuke Niwa
6be567bfc2
[Webkit Checkers] Treat const member variables as a safe origin (#115594)
Treat const Ref, RefPtr, CheckedRef, CheckedPtr member variables as safe
pointer origin in WebKit's local variable and call arguments checkers.
2024-11-14 21:11:08 -08:00
Ryosuke Niwa
5c20891b2b
[WebKit Checkers] Allow a guardian CheckedPtr/CheckedRef (#110222)
This PR makes WebKit checkers allow a guardian variable which is
CheckedPtr or CheckedRef as in addition to RefPtr or Ref.
2024-10-25 08:52:56 -07:00
Ryosuke Niwa
0fc3e4093c
[alpha.webkit.UncountedCallArgsChecker] Skip std::forward in tryToFindPtrOrigin. (#111222)
Ignore std::forward when it appears while looking for the pointer
origin.
2024-10-10 10:00:42 -07:00
Ryosuke Niwa
33533baf63
[alpha.webkit.UncountedCallArgsChecker] Add support for Objective-C++ property access (#108669)
Treat a function call or property access via a Objective-C++ selector
which returns a Ref/RefPtr as safe.
2024-09-17 18:39:22 -07:00
Ryosuke Niwa
cf8b93d823
[alpha.webkit.UncountedCallArgsChecker] Allow explicit instantiation of Ref/RefPtr on call arguments. (#91875)
Co-authored-by: Ryosuke Niwa <rniwa@apple.com>
2024-05-13 21:05:41 -07:00
Ryosuke Niwa
21be818223
[analyzer] Support determining origins in a conditional operator in WebKit checkers. (#91143)
This PR adds the support for determining the origin of a pointer in a
conditional operator.

Because such an expression can have two distinct origins each of which
needs to be visited, this PR refactors tryToFindPtrOrigin to take a
callback instead of returning a pair.

The callback is called for the second operand and the third operand of
the conditioanl operator (i.e. E2 and E3 in E1 ? E2 : E3).

Also treat nullptr and integer literal as safe pointer origins in the
local variable checker.
2024-05-09 21:32:28 -07:00
Ryosuke Niwa
b86accceee
[alpha.webkit.UncountedCallArgsChecker] Treat (foo())->bar() like foo()->bar(). (#91052) 2024-05-06 15:59:08 -07:00
Fraser Cormack
4b369ff076 [analyzer][NFC] Fix unused variable warning 2024-03-20 11:43:38 +00:00
Ryosuke Niwa
c3b87a8810
[alpha.webkit.UncountedCallArgsChecker] Allow ASSERT and atomic<T> operations in a trivial function (#82063) 2024-02-19 16:11:49 -08:00
Ryosuke Niwa
a7982d5e7a
[analyzer] UncountedCallArgsChecker: Detect & ignore trivial function calls. (#81808)
This PR introduces the concept of a "trivial function" which applies to
a function that only calls other trivial functions and contain literals
and expressions that don't result in heap mutations (specifically it
does not call deref). This is implemented using ConstStmtVisitor and
checking each statement and expression's trivialness.

This PR also introduces the concept of a "ingleton function", which is a
static member function or a free standing function which ends with the
suffix "singleton". Such a function's return value is understood to be
safe to call any function with.
2024-02-14 18:46:30 -08:00
Ryosuke Niwa
7249692bd2
[analyzer] Detect a return value of Ref<T> & RefPtr<T> (#81580)
This PR makes the checker not emit warning when a function is called
with a return value of another function when the return value is of type
Ref<T> or RefPtr<T>.
2024-02-14 14:47:40 -08:00
Ryosuke Niwa
93a2a8cb7f
Fix a crash in clang::isGetterOfRefCounted by checking nullptr in tryToFindPtrOrigin (#80768) 2024-02-06 08:28:15 -08:00
Kazu Hirata
2d861436a9 [clang] Remove remaining uses of llvm::Optional (NFC)
This patch removes several "using" declarations and #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 13:37:25 -08: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
a7eb3692e7 [Analyzer][WebKit] UncountedCallArgsChecker
Differential Revision: https://reviews.llvm.org/D77179
2020-06-15 13:53:36 -07:00