You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[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.
Copy file name to clipboardExpand all lines: clang/docs/analyzer/checkers.rst
+45
Original file line number
Diff line number
Diff line change
@@ -3668,6 +3668,51 @@ Here are some examples of situations that we warn about as they *might* be poten
3668
3668
RefCountable* uncounted = counted.get(); // warn
3669
3669
}
3670
3670
3671
+
alpha.webkit.UnretainedLocalVarsChecker
3672
+
"""""""""""""""""""""""""""""""""""""""
3673
+
The goal of this rule is to make sure that any NS or CF local variable is backed by a RetainPtr with lifetime that is strictly larger than the scope of the unretained local variable. To be on the safe side we require the scope of an unretained variable to be embedded in the scope of Retainptr object that backs it.
3674
+
3675
+
The rules of when to use and not to use RetainPtr are same as alpha.webkit.UncountedCallArgsChecker for ref-counted objects.
3676
+
3677
+
These are examples of cases that we consider safe:
3678
+
3679
+
.. code-block:: cpp
3680
+
3681
+
void foo1() {
3682
+
RetainPtr<NSObject> retained;
3683
+
// The scope of unretained is EMBEDDED in the scope of retained.
3684
+
{
3685
+
NSObject* unretained = retained.get(); // ok
3686
+
}
3687
+
}
3688
+
3689
+
void foo2(RetainPtr<NSObject> retained_param) {
3690
+
NSObject* unretained = retained_param.get(); // ok
3691
+
}
3692
+
3693
+
void FooClass::foo_method() {
3694
+
NSObject* unretained = this; // ok
3695
+
}
3696
+
3697
+
Here are some examples of situations that we warn about as they *might* be potentially unsafe. The logic is that either we're able to guarantee that a local variable is safe or it's considered unsafe.
0 commit comments