19 Commits

Author SHA1 Message Date
Ryosuke Niwa
f9326ffb7e
[WebKit checkers] Treat a weak property / variable as safe (#163689)
Treat a weak Objective-C property, ivar, member variable, and local
variable as safe.
2025-12-09 12:28:22 -08:00
Ryosuke Niwa
b7e256dce9
[alpha.webkit.NoUnretainedMemberChecker] Allow a retaining property synthesis (#162576)
Don't emit a warning when an Objective-C property is defined using copy
or strong semantics.
2025-10-09 14:28:11 -07:00
Ryosuke Niwa
321a7c3caf
[alpha.webkit.NoUnretainedMemberChecker] Only check @property when @implementation is seen (#159947)
A @interface declaration with a raw pointer @property does not
necessarily mean it synthesizes ivar of that type. To determine whether
such a synthesis happens or not, we must wait for @implementation to
appear. So this PR makes the checker only validate @property then.
2025-09-25 11:12:23 -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
0123ee51ef
[alpha.webkit.NoUnretainedMemberChecker] Recognize NS_REQUIRES_PROPERTY_DEFINITIONS (#143408)
Allow @property of a raw pointer when NS_REQUIRES_PROPERTY_DEFINITIONS
is specified on the interface since such an interface does not
automatically synthesize raw pointer ivars.

Also emit a warning for @property(assign) and
@property(unsafe_unretained) under ARC as well as when explicitly
synthesizing a unsafe raw pointer property.
2025-06-09 20:55:50 -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
984475d82d
[RawPtrRefMemberChecker] Add the support for union and pointers to unsafe pointers. (#138042)
This PR adds support for detecting unsafe union members and pointers to
unsafe pointers (e.g. T** where T* is an unsafe pointer type).
2025-05-09 17:44:13 -07:00
Ryosuke Niwa
af4aeb325c
[RawPtrRefMemberChecker] Make RawPtrRefMemberChecker consistent with other checkers (#137559)
Refactor RawPtrRefMemberChecker so that each subclass override
isUnsafePtr like other WebKit checkers instead of overriding
isPtrCompatible.
2025-04-30 14:27:39 -07:00
Ryosuke Niwa
a05aeda305
[RawPtrRefMemberChecker] Member variable checker should allow T* in smart pointer classes (#136503)
This PR fixes member variable checker to allow the usage of T* in smart
pointer classes. e.g. alpha.webkit.NoUncheckedPtrMemberChecker should
allow T* to appear within RefPtr.
2025-04-23 12:41:56 -07:00
Ryosuke Niwa
6ff33edcdc
[alpha.webkit.NoUnretainedMemberChecker] Ignore system-header-defined ivar / property of a forward declared type (#133755)
Prior to this PR, we were emitting warnings for Objective-C ivars and
properties if the forward declaration of the type appeared first in a
non-system header. This PR fixes the checker so tha we'd ignore ivars
and properties defined for a forward declared type.
2025-03-31 14:59:41 -07:00
Ryosuke Niwa
304b3c5000
[alpha.webkit.RawPtrRefMemberChecker] The checker doesn't warn Objective-C types in ivars. (#132833)
This PR fixes the bug that we weren't generating warnings when a raw
poiner is used to point to a NS type in Objective-C ivars. Also fix the
bug that we weren't suppressing this warning in system headers.
2025-03-28 17:34:51 -07:00
Ryosuke Niwa
bb0cc69487
[webkit.NoUncountedMemberChecker] Fix a regression that every class is treated as if it's ref countable. (#131249)
This PR fixes a regression that webkit.NoUncountedMemberChecker and
alpha.webkit.NoUncheckedMemberChecker emits warnings for every class as
if they supported ref counting and checked ptr because we were
erroneously coercing the return value of isRefCountable and
isCheckedPtrCapable, which is std::optional<bool>, to boolean values.
2025-03-18 15:43:43 -07:00
Ryosuke Niwa
c8ec8073aa
[alpha.webkit.NoUnretainedMemberChecker] Add a new WebKit checker for unretained member variables and ivars. (#128641)
Add a new WebKit checker for member variables and instance variables of
NS and CF types. A member variable or instance variable to a CF type
should be RetainPtr regardless of whether ARC is enabled or disabled,
and that of a NS type should be RetainPtr when ARC is disabled.
2025-03-09 23:30:08 -07:00
Ryosuke Niwa
5f8b256821
Check the type of Objective-C++ instance variables in WebKit member variable checkers. (#127570)
Like a C++ member variable, every Objective-C++ instance variable must
be a RefPtr, Ref CheckedPtr, or CheckedRef to an object, not a raw
pointer or reference.
2025-02-19 13:24:12 -08:00
Sirraide
39a72be5e5
[Clang] [NFC] Introduce ConstDynamicRecursiveASTVisitor (reland) (#124821)
This relands #122991 (eeefa72).

The last attempt at landing this caused some problems; I’m not entirely
sure what happened, but it might have been due to an unnecessary use
of the `template` keyword in a few places. This removes that and attempts
to land the change again.
2025-01-29 16:14:18 +01:00
Sirraide
7873d3b50b
Revert "[Clang] [NFC] Introduce ConstDynamicRecursiveASTVisitor" (#124667)
Reverts llvm/llvm-project#122991

One of the bots is breaking; I’ll have to investigate what the issue is;
this might be because I haven’t updated the branch in a while.
2025-01-28 02:21:18 +01:00
Sirraide
eeefa72f7c
[Clang] [NFC] Introduce ConstDynamicRecursiveASTVisitor (#122991)
After some discussion around #116823, it was decided that it would be
nice to have a `const` variant of `DynamicRecursiveASTVisitor`, so this
pr does exactly that by making the main DRAV implementation a template
with a single `bool` template parameter that turns several function
parameters from a `T*` or `T&` to a `const T*` or `const T&`.

Since that made the implementation of a bunch of DRAV functions quite a
bit more verbose, I’ve moved most of them to be stamped out by a macro,
which imo makes it easier to understand what’s actually going on there.

For functions which already accepted `const` parameters in the original
RAV implementation, the parameter is `const` in both versions (e.g.
`TraverseTemplateArgument()` always takes a `const TemplateArgument&`);
conversely, parameters that are passed by value (e.g. in
`TraverseType()`, which takes a `QualType` by value) are *not* `const`
in either variant (i.e. the `QualType` argument is always just a
`QualType`, never a `const QualType`).

As a sanity check, I’ve also migrated some random visitor in the static
analyser to the `const` version (and indeed, it ends up simplifying the
code around that particular visitor actually). It would make sense to do
a pass over all visitors and change all which can be `const` use the
`const` version, but that can be done in a follow-up pr.

The [performance
impact](https://llvm-compile-time-tracker.com/compare.php?from=e3cd88a7be1dfd912bb6e7c7e888e7b442ffb5de&to=d55c5afe4a485b6d0431386e6f45cb44c1fc8883&stat=instructions:u)
of this change seems to be negligible. Clang’s binary size went up by
0.5%, but that’s expected considering that this effectively adds an
extra instantiation of `RecursiveASTVisitor`. Fortunately, this is of
course a one-time cost.
2025-01-28 02:15:02 +01: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
3c0984309e
[alpha.webkit.NoUncheckedPtrMemberChecker] Introduce member variable checker for CheckedPtr/CheckedRef (#108352)
This PR introduces new WebKit checker to warn a member variable that is
a raw reference or a raw pointer to an object, which is capable of
creating a CheckedRef/CheckedPtr.
2024-09-27 00:42:18 -07:00