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
Copy file name to clipboardExpand all lines: clang/docs/analyzer/checkers.rst
+12-8Lines changed: 12 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3633,26 +3633,28 @@ See `WebKit Guidelines for Safer C++ Programming <https://github.com/WebKit/WebK
3633
3633
3634
3634
alpha.webkit.NoUnretainedMemberChecker
3635
3635
""""""""""""""""""""""""""""""""""""""""
3636
-
Raw pointers and references to a NS or CF object can't be used as class members or ivars. Only RetainPtr is allowed for CF types regardless of whether ARC is enabled or disabled. Only RetainPtr is allowed for NS types when ARC is disabled.
3636
+
Raw pointers and references to a NS or CF object can't be used as class members or ivars. Only RetainPtr is allowed for CF types regardless of whether ARC is enabled or disabled. Only RetainPtr or OSObjectPtr is allowed for NS types when ARC is disabled.
3637
3637
3638
3638
.. code-block:: cpp
3639
3639
3640
3640
struct Foo {
3641
3641
NSObject *ptr; // warn
3642
+
dispatch_queue_t queue; // warn
3642
3643
// ...
3643
3644
};
3644
3645
3645
3646
See `WebKit Guidelines for Safer C++ Programming <https://github.com/WebKit/WebKit/wiki/Safer-CPP-Guidelines>`_ for details.
3646
3647
3647
3648
alpha.webkit.UnretainedLambdaCapturesChecker
3648
3649
""""""""""""""""""""""""""""""""""""""""""""
3649
-
Raw pointers and references to NS or CF types can't be captured in lambdas. Only RetainPtr is allowed for CF types regardless of whether ARC is enabled or disabled, and only RetainPtr is allowed for NS types when ARC is disabled.
3650
+
Raw pointers and references to NS or CF types can't be captured in lambdas. Only RetainPtr is allowed for CF types regardless of whether ARC is enabled or disabled, and only RetainPtr or OSObjectPtr is allowed for NS types when ARC is disabled.
3650
3651
3651
3652
.. code-block:: cpp
3652
3653
3653
-
void foo(NSObject *a, NSObject *b) {
3654
+
void foo(NSObject *a, NSObject *b, dispatch_queue_t c) {
3654
3655
[&, a](){ // warn about 'a'
3655
3656
do_something(b); // warn about 'b'
3657
+
dispatch_queue_get_specific(c, "some"); // warn about 'c'
The goal of this rule is to make sure that lifetime of any dynamically allocated NS or CF objects passed as a call argument keeps its memory region past the end of the call. This applies to call to any function, method, lambda, function pointer or functor. NS or CF objects aren't supposed to be allocated on stack so we check arguments for parameters of raw pointers and references to unretained types.
3757
3759
3758
-
The rules of when to use and not to use RetainPtr are same as alpha.webkit.UncountedCallArgsChecker for ref-counted objects.
3760
+
The rules of when to use and not to use RetainPtr or OSObjectPtr are same as alpha.webkit.UncountedCallArgsChecker for ref-counted objects.
3759
3761
3760
3762
alpha.webkit.UncountedLocalVarsChecker
3761
3763
""""""""""""""""""""""""""""""""""""""
@@ -3845,9 +3847,9 @@ Here are some examples of situations that we warn about as they *might* be poten
3845
3847
3846
3848
alpha.webkit.UnretainedLocalVarsChecker
3847
3849
"""""""""""""""""""""""""""""""""""""""
3848
-
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.
3850
+
The goal of this rule is to make sure that any NS or CF local variable is backed by a RetainPtr or OSObjectPtr 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 or OSObjectPtr object that backs it.
3849
3851
3850
-
The rules of when to use and not to use RetainPtr are same as alpha.webkit.UncountedCallArgsChecker for ref-counted objects.
3852
+
The rules of when to use and not to use RetainPtr or OSObjectPtr are same as alpha.webkit.UncountedCallArgsChecker for ref-counted objects.
3851
3853
3852
3854
These are examples of cases that we consider safe:
3853
3855
@@ -3890,8 +3892,8 @@ Here are some examples of situations that we warn about as they *might* be poten
3890
3892
3891
3893
webkit.RetainPtrCtorAdoptChecker
3892
3894
""""""""""""""""""""""""""""""""
3893
-
The goal of this rule is to make sure the constructor of RetainPtr as well as adoptNSand adoptCF are used correctly.
3894
-
When creating a RetainPtr with +1 semantics, adoptNSor adoptCF should be used, and in +0 semantics, RetainPtr constructor should be used.
3895
+
The goal of this rule is to make sure the constructors of RetainPtr and OSObjectPtr as well as adoptNS, adoptCF, and adoptOSObject are used correctly.
3896
+
When creating a RetainPtr or OSObjectPtr with +1 semantics, adoptNS, adoptCF, or adoptOSObject should be used, and in +0 semantics, RetainPtr or OSObjectPtr constructor should be used.
3895
3897
Warn otherwise.
3896
3898
3897
3899
These are examples of cases that we consider correct:
@@ -3900,13 +3902,15 @@ These are examples of cases that we consider correct:
3900
3902
3901
3903
RetainPtr ptr = adoptNS([[NSObject alloc] init]); // ok
3902
3904
RetainPtr ptr = CGImageGetColorSpace(image); // ok
3905
+
OSObjectPtr ptr = adoptOSObject(dispatch_queue_create("some queue", nullptr)); // ok
3903
3906
3904
3907
Here are some examples of cases that we consider incorrect use of RetainPtr constructor and adoptCF
3905
3908
3906
3909
.. code-block:: cpp
3907
3910
3908
3911
RetainPtr ptr = [[NSObject alloc] init]; // warn
3909
3912
auto ptr = adoptCF(CGImageGetColorSpace(image)); // warn
0 commit comments