13 Commits

Author SHA1 Message Date
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
0eb00eff47
[alpha.webkit.RetainPtrCtorAdoptChecker] Don't treat assignment to an +1 out argument as a leak (#161633)
Make RetainPtrCtorAdoptChecker recognize an assignment to an +1 out
argument so that it won't emit a memory leak warning.
2025-12-09 12:15:56 -08:00
Ryosuke Niwa
103d2cae80
[alpha.webkit.RetainPtrCtorAdoptChecker] Allow leakRef in copy methods (#160986)
Allow leakRef() in the return statement of an Objective-C copy method
and other methods which return +1.
2025-10-01 15:01:44 -07: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
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
992e928641
[alpha.webkit.RetainPtrCtorAdoptChecker] Check nullity before calling IgnoreParenCasts. (#137556) 2025-04-27 15:45:03 -07:00
Ryosuke Niwa
16e5c3ddad
[alpha.webkit.RetainPtrCtorAdoptChecker] An assortment of small enhancements (#135329)
This PR implements various small enhancements to
alpha.webkit.RetainPtrCtorAdoptChecker:
 - Detect leaks from [[X alloc] init] when ARC is disabled.
 - Detect leaks from calling Create, Copy, and other +1 CF functions.
 - Recognize [allocX() init] pattern where allocX is a C/C++ function.
 - Recognize _init in addition to init as an init function.
 - Recognize [[[X alloc] init] autorelease].
 - Recognize CFBridgingRelease.
 - Support CF_RETRUNS_RETAINED on out arguments of a C function.
- Support returning +1 object in Create, Copy, and other +1 functions or
+1 selectors.
 - Support variadic Create, Copy, and other +1 C/C++ functions.

To make these enhancements, this PR introduces new visit functions for
ObjCMessageExpr, ReturnStmt, VarDecl, and BinaryOperator. These
functions look for a specific construct mentioned above and adds an
expression such as [[X alloc] init] or CreateX to a DenseSet
CreateOrCopyFnCall when the expression does not result in leaks. When
the code to detect leaks such as the one in visitObjCMessageExpr later
encounters this expression, it can bail out early if the expression is
in the set.
2025-04-27 14:24:32 -07:00
Ryosuke Niwa
517605c20e
[alpha.webkit.UnretainedCallArgsChecker] Add the support for RetainPtrArc (#135532)
WebKit uses #define to rename RetainPtr to RetainPtrArc so add the
support for it.
2025-04-15 20:00:51 -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
Aaron Ballman
71f629fc2a
Initialize member variable; NFC (#135167)
This was found via a Coverity static analysis pass. There's no
indication this was being used incorrectly in practice, but there are
public interfaces which require `BR` to be non-null and valid, and `BR`
was not being initialized by the constructor.

This adds an in-class initializer for `BR` and some asserts, to be safe.
2025-04-10 08:10:16 -04:00
Ryosuke Niwa
c8d49e9dd2
[alpha.webkit.RetainPtrCtorAdoptChecker] Recognize mutableCopy from literal as +1 (#132350)
This PR adds the support for recognizing the return value of copy /
mutableCopy as +1. isAllocInit and isOwned now traverses
PseudoObjectExpr to its last semantic expression.
2025-04-09 10:33:08 -07:00
Ryosuke Niwa
be9ca85d64
[alpha.webkit.webkit.RetainPtrCtorAdoptChecker] Add a new WebKit checker for correct use of RetainPtr, adoptNS, and adoptCF (#128679)
Add a new WebKit checker to validate the correct use of RetainPtr
constructor as well as adoptNS and adoptCF functions. adoptNS and
adoptCf are used for +1 semantics and RetainPtr constructor is used for
+0 semantics.
2025-03-12 19:09:05 -07:00