Skip to content

Conversation

rniwa
Copy link
Contributor

@rniwa rniwa commented Oct 9, 2025

Don't emit a warning when an Objective-C property is defined using copy or strong semantics.

…ynthesis Don't emit a warning when an Objective-C property is defined using copy or strong semantics.
@rniwa rniwa requested a review from t-rasmud October 9, 2025 00:37
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:static analyzer labels Oct 9, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 9, 2025

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-static-analyzer-1

Author: Ryosuke Niwa (rniwa)

Changes

Don't emit a warning when an Objective-C property is defined using copy or strong semantics.


Full diff: https://github.com/llvm/llvm-project/pull/162576.diff

2 Files Affected:

  • (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp (+1-1)
  • (modified) clang/test/Analysis/Checkers/WebKit/unretained-members.mm (+3-4)
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp index 15a0c5a7fd9dc..ace639ce7ab18 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp @@ -232,7 +232,7 @@ class RawPtrRefMemberChecker bool ignoreARC = !PD->isReadOnly() && PD->getSetterKind() == ObjCPropertyDecl::Assign; auto IsUnsafePtr = isUnsafePtr(QT, ignoreARC); - return {IsUnsafePtr && *IsUnsafePtr, PropType}; + return {IsUnsafePtr && *IsUnsafePtr && !PD->isRetaining(), PropType}; } bool shouldSkipDecl(const RecordDecl *RD) const { diff --git a/clang/test/Analysis/Checkers/WebKit/unretained-members.mm b/clang/test/Analysis/Checkers/WebKit/unretained-members.mm index adf1d8aef9d7d..2b120b9b1385c 100644 --- a/clang/test/Analysis/Checkers/WebKit/unretained-members.mm +++ b/clang/test/Analysis/Checkers/WebKit/unretained-members.mm @@ -113,7 +113,6 @@ @interface AnotherObject : NSObject { // expected-warning@-1{{Instance variable 'dispatch' in 'AnotherObject' is a retainable type 'dispatch_queue_t'}} } @property(nonatomic, readonly, strong) NSString *prop_string; -// expected-warning@-1{{Property 'prop_string' in 'AnotherObject' is a raw pointer to retainable type 'NSString'; member variables must be a RetainPtr}} @property(nonatomic, readonly) NSString *prop_safe; @end @@ -132,7 +131,6 @@ @interface DerivedObject : AnotherObject { // expected-warning@-1{{Instance variable 'os_dispatch' in 'DerivedObject' is a retainable type 'dispatch_queue_t'}} } @property(nonatomic, strong) NSNumber *prop_number; -// expected-warning@-1{{Property 'prop_number' in 'DerivedObject' is a raw pointer to retainable type 'NSNumber'; member variables must be a RetainPtr}} @property(nonatomic, readonly) NSString *prop_string; @end @@ -178,12 +176,12 @@ @interface NoSynthObject : NSObject { } @property(nonatomic, readonly, strong) NSString *prop_string1; @property(nonatomic, readonly, strong) NSString *prop_string2; -// expected-warning@-1{{Property 'prop_string2' in 'NoSynthObject' is a raw pointer to retainable type 'NSString'}} @property(nonatomic, assign) NSString *prop_string3; // expected-warning@-1{{Property 'prop_string3' in 'NoSynthObject' is a raw pointer to retainable type 'NSString'; member variables must be a RetainPtr}} @property(nonatomic, unsafe_unretained) NSString *prop_string4; // expected-warning@-1{{Property 'prop_string4' in 'NoSynthObject' is a raw pointer to retainable type 'NSString'; member variables must be a RetainPtr}} -@property(nonatomic, readonly, strong) NSString *dispatch; +@property(nonatomic, copy) NSString *prop_string5; +@property(nonatomic, readonly, strong) dispatch_queue_t dispatch; @end @implementation NoSynthObject @@ -193,6 +191,7 @@ - (NSString *)prop_string1 { @synthesize prop_string2; @synthesize prop_string3; @synthesize prop_string4; +@synthesize prop_string5; - (dispatch_queue_t)dispatch { return nil; } 
Copy link
Contributor

@t-rasmud t-rasmud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@rniwa
Copy link
Contributor Author

rniwa commented Oct 9, 2025

Thanks for the review!

@rniwa rniwa merged commit b7e256d into llvm:main Oct 9, 2025
12 checks passed
@rniwa rniwa deleted the fix-webkit-retaining-objc-prop branch October 9, 2025 21:28
rniwa added a commit to rniwa/llvm-project that referenced this pull request Oct 9, 2025
…ynthesis (llvm#162576) Don't emit a warning when an Objective-C property is defined using copy or strong semantics.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:static analyzer clang Clang issues not falling into any other category
3 participants