23 Commits

Author SHA1 Message Date
Ryosuke Niwa
2158b83f61
Add nodelete annotation for WebKit checkers with a new checker for validation (#177839)
This PR adds the support for specifying
`[[clang::annotate_type("webkit.nodelete")]]` on a function return type,
in which case, the whole function is considered "trivial" or more
precisely that it does not trigger any destruction of an object.

This PR also introduces alpha.webkit.NoDeleteChecker which validates
soundness of the annotation by examining the function body. The checker
will warn if `[[clang::annotate_type("webkit.nodelete")]]` is specified
on a function with a body which does not pass the triviality test.

---------

Co-authored-by: Balazs Benics <benicsbalazs@gmail.com>
2026-01-27 09:18:45 -08:00
Ryosuke Niwa
06f0758282
[alpha.webkit.UnretainedCallArgsChecker] Recognize [allocObj() init] pattern (#161019)
Generalize the check for recognizing [[Obj alloc] init] to also
recognize [allocObj() init]. We do this by utilizing isAllocInit
function in RetainPtrCtorAdoptChecker.
2025-12-09 12:29:11 -08:00
Ryosuke Niwa
1127dd7754
[WebKit Checkers] Treat a NS/CF global defined in a system header as a safe pointer origin (#161146) 2025-10-14 16:52:19 -07:00
Ryosuke Niwa
86d767c3a0
[alpha.webkit.UnretainedCallArgsChecker] Treat boolean literal as safe (#159705) 2025-09-23 02:23:27 -07:00
Claudio Saavedra
a254f6524a
[WebKit checkers] fix a typo in a message in one of the checkers (#159593) 2025-09-19 11:31:17 +00:00
Ryosuke Niwa
9d933c794a
[WebKit checkers] Add the support for OSObjectPtr (#159484)
Add the support for OSObjectPtr, which behaves like RetainPtr.
2025-09-18 21:46:22 -07:00
Ryosuke Niwa
db74eae1dc
[WebKit checkers] Treat NULL, 0, and nil like nullptr (#157700)
This PR makes WebKit checkers treat NULL, 0, and nil like nullptr in
various places.
2025-09-10 16:04:03 -07:00
Rob Buis
524f090306
[alpha.webkit.UncountedCallArgsChecker] Treat CFEqual as a safe function (#146369)
CFEqual is a trivial function, so treat it as safe.
2025-07-01 13:57:53 +01:00
Ryosuke Niwa
e5fa38b02b
[WebKit checkers] Treat passing of a member variable which is capable of CheckedPtr as safe. (#142485)
It's safe for a member function of a class or struct to call a function
or allocate a local variable with a pointer or a reference to a member
variable since "this" pointer, and therefore all its members, will be
kept alive by its caller so recognize as such.
2025-06-09 07:32:15 -07:00
Kazu Hirata
8d49c64fa2
[StaticAnalyzer] Remove unused includes (NFC) (#141525)
These are identified by misc-include-cleaner.  I've filtered out those
that break builds.  Also, I'm staying away from llvm-config.h,
config.h, and Compiler.h, which likely cause platform- or
compiler-specific build failures.
2025-05-26 14:57:13 -07:00
Ryosuke Niwa
2206e15e78
[alpha.webkit.UnretainedCallArgsChecker] Don't emit a warning for RetainPtr::operator= (#135526)
Generalize the check for operator= so that it works for RetainPtr and
CheckedPtr instead of just RefPtr.
2025-04-14 15:03:21 -07:00
Ryosuke Niwa
c26d097d0c
[alpha.webkit.RetainPtrCtorAdoptChecker] Support adopt(cast(copy(~)) (#132316)
This PR adds the support for recognizing calling adoptCF/adoptNS on the
result of a cast operation on the return value of a function which
creates NS or CF types. It also fixes a bug that we weren't reporting
memory leaks when CF types are created without ever calling RetainPtr's
constructor, adoptCF, or adoptNS.

To do this, this PR adds a new mechanism to report a memory leak
whenever create or copy CF functions are invoked unless this CallExpr
has already been visited while validating a call to adoptCF. Also added
an early exit when isOwned returns IsOwnedResult::Skip due to an
unresolved template argument.
2025-04-10 15:26:10 -07:00
Ryosuke Niwa
bf1d27889b
[WebKit checkers] Treat Objective-C message send return value as safe (#133605)
Objective-C selectors are supposed to return autoreleased object. Treat
these return values as safe.
2025-04-04 11:25:24 -07:00
Ryosuke Niwa
a285be320a
[WebKit Checkers] Recognize Objective-C and CF pointer conversion functions. (#132784)
Recognize dynamic_objc_cast, checked_objc_cast, dynamic_cf_cast, and
checked_cf_cast.
2025-03-27 15:47:38 -07:00
Ryosuke Niwa
4781941160
[alpha.webkit.UncountedCallArgsChecker] os_log functions should be treated as safe. (#131500)
…os_log functions should be treated as safe in call arguments checkers.

Also treat __builtin_* functions and __libcpp_verbose_abort functions as
"trivial" for the purpose in call argument checkers.
2025-03-17 23:47:10 -07:00
Ryosuke Niwa
caf301891a
Add unretained call args checker (#130901)
Reland https://github.com/llvm/llvm-project/pull/130729
2025-03-12 10:37:13 -07:00
Ryosuke Niwa
7573ee1781
Revert "[alpha.webkit.UnretainedCallArgsChecker] Add a checker for NS or CF type call arguments." (#130828)
Reverts llvm/llvm-project#130729
2025-03-11 13:42:31 -07:00
Ryosuke Niwa
9e64fc6fb7
[alpha.webkit.UnretainedCallArgsChecker] Add a checker for NS or CF type call arguments. (#130729)
This PR adds alpha.webkit.UnretainedCallArgsChecker by generalizing
RawPtrRefCallArgsChecker. It checks call arguments of NS or CF types are
backed by a RetainPtr or not. The new checker emits warnings for CF
types in Objective-C++ code regardless of ARC and it emits warning for
NS types when ARC is disabled.

Hard-code a few cases as safe: class and superclass properties on class
interfaces and constant dictionary or array literals as well as the
return value of NSClassFromString.

Finally, add the support for variadic function calls and selector
invocations.
2025-03-11 12:47:13 -07:00
Ryosuke Niwa
3ce43c8b16
[WebKit checkers] Don't treat virtual functions as safe. (#129632)
Prior to this PR, WebKit checkers erroneously treated functions to be
safe if it has a trivial body even if it was marked as virtual. In the
case of a virtual function, it can have an override which does not pass
the triviality check so we must not make such an assumption.

This PR also restricts the allowed operator overloading while finding
the pointer origin to just operators on smart pointer types: Ref,
RefPtr, CheckedRef, CheckedPtr, RetainPtr, WeakPtr, WeakRef, unique_ptr,
and UniqueRef.
2025-03-10 21:01:39 -07:00
Ryosuke Niwa
cec3507702
[alpha.webkit.UnretainedLocalVarsChecker] Add a checker for local variables to NS and CF types. (#127554)
This PR adds alpha.webkit.UnretainedLocalVarsChecker by generalizing
RawPtrRefLocalVarsChecker. It checks local variables to NS or CF types
are guarded with a RetainPtr or not. The new checker is effective for NS
and CF types in Objective-C++ code without ARC, and it's effective for
CF types in code with ARC.
2025-02-24 12:14:14 -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
Sirraide
dde802b153
[Clang] [NFC] Refactor AST visitors in Sema and the static analyser to use DynamicRecursiveASTVisitor (#115144)
This pr refactors all recursive AST visitors in `Sema`, `Analyze`, and
`StaticAnalysis` to inherit from DRAV instead. This is over half of the
visitors that inherit from RAV directly.

See also #115132, #110040, #93462

LLVM Compile-Time Tracker link for this branch:
https://llvm-compile-time-tracker.com/compare.php?from=5adb5c05a2e9f31385fbba8b0436cbc07d91a44d&to=b58e589a86c06ba28d4d90613864d10be29aa5ba&stat=instructions%3Au
2024-11-15 08:04:08 +01:00
Ryosuke Niwa
ef353b02b0
Introduce a new WebKit checker for a unchecked call arguments (#113708) (#114522)
This PR introduces alpha.webkit.UncheckedCallArgsChecker which detects a
function argument which is a raw reference or a raw pointer to a
CheckedPtr capable object.
2024-11-07 08:34:37 -08:00