forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check the type of Objective-C++ instance variables in WebKit member v…
…ariable checkers. (llvm#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.
- Loading branch information
Showing
3 changed files
with
107 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
clang/test/Analysis/Checkers/WebKit/unchecked-members-objc.mm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.NoUncheckedPtrMemberChecker -verify %s | ||
|
||
#include "mock-types.h" | ||
|
||
__attribute__((objc_root_class)) | ||
@interface NSObject | ||
+ (instancetype) alloc; | ||
- (instancetype) init; | ||
- (instancetype)retain; | ||
- (void)release; | ||
@end | ||
|
||
void doSomeWork(); | ||
|
||
@interface SomeObjC : NSObject { | ||
CheckedObj* _unchecked1; | ||
// expected-warning@-1{{Instance variable '_unchecked1' in 'SomeObjC' is a raw pointer to CheckedPtr capable type 'CheckedObj'}} | ||
CheckedPtr<CheckedObj> _counted1; | ||
[[clang::suppress]] CheckedObj* _unchecked2; | ||
} | ||
- (void)doWork; | ||
@end | ||
|
||
@implementation SomeObjC { | ||
CheckedObj* _unchecked3; | ||
// expected-warning@-1{{Instance variable '_unchecked3' in 'SomeObjC' is a raw pointer to CheckedPtr capable type 'CheckedObj'}} | ||
CheckedPtr<CheckedObj> _counted2; | ||
[[clang::suppress]] CheckedObj* _unchecked4; | ||
} | ||
|
||
- (void)doWork { | ||
doSomeWork(); | ||
} | ||
|
||
@end |
35 changes: 35 additions & 0 deletions
35
clang/test/Analysis/Checkers/WebKit/uncounted-members-objc.mm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// RUN: %clang_analyze_cc1 -analyzer-checker=webkit.NoUncountedMemberChecker -verify %s | ||
|
||
#include "mock-types.h" | ||
|
||
__attribute__((objc_root_class)) | ||
@interface NSObject | ||
+ (instancetype) alloc; | ||
- (instancetype) init; | ||
- (instancetype)retain; | ||
- (void)release; | ||
@end | ||
|
||
void doSomeWork(); | ||
|
||
@interface SomeObjC : NSObject { | ||
RefCountable* _uncounted1; | ||
// expected-warning@-1{{Instance variable '_uncounted1' in 'SomeObjC' is a raw pointer to ref-countable type 'RefCountable'}} | ||
RefPtr<RefCountable> _counted1; | ||
[[clang::suppress]] RefCountable* _uncounted2; | ||
} | ||
- (void)doWork; | ||
@end | ||
|
||
@implementation SomeObjC { | ||
RefCountable* _uncounted3; | ||
// expected-warning@-1{{Instance variable '_uncounted3' in 'SomeObjC' is a raw pointer to ref-countable type 'RefCountable'}} | ||
RefPtr<RefCountable> _counted2; | ||
[[clang::suppress]] RefCountable* _uncounted4; | ||
} | ||
|
||
- (void)doWork { | ||
doSomeWork(); | ||
} | ||
|
||
@end |