[clang] [alpha.webkit.RetainPtrCtorAdoptChecker] Don't treat calling (void)copy:(id) as a leak (PR #179713)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 4 09:40:27 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-static-analyzer-1
Author: Ryosuke Niwa (rniwa)
<details>
<summary>Changes</summary>
UIResponderStandardEditActions defines (void)copy:(id)sender but this selector should not be treated as a copy operation since it's a "copy" in the sense of application triggering copy & paste for the system pasteboard.
---
Full diff: https://github.com/llvm/llvm-project/pull/179713.diff
3 Files Affected:
- (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp (+8-1)
- (modified) clang/test/Analysis/Checkers/WebKit/retain-ptr-ctor-adopt-use-arc.mm (+14)
- (modified) clang/test/Analysis/Checkers/WebKit/retain-ptr-ctor-adopt-use.mm (+14)
``````````diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
index 15971168934b5..f9d35c595682b 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
@@ -337,8 +337,15 @@ bool isAllocInit(const Expr *E, const Expr **InnerExpr) {
auto NameForFirstSlot = Selector.getNameForSlot(0);
if (NameForFirstSlot.starts_with("alloc") ||
NameForFirstSlot.starts_with("copy") ||
- NameForFirstSlot.starts_with("mutableCopy"))
+ NameForFirstSlot.starts_with("mutableCopy")) {
+ if (auto *MD = ObjCMsgExpr->getMethodDecl()) {
+ if (auto *T = MD->getReturnType().getTypePtrOrNull()) {
+ if (T->isVoidType())
+ return false;
+ }
+ }
return true;
+ }
if (!NameForFirstSlot.starts_with("init") &&
!NameForFirstSlot.starts_with("_init"))
return false;
diff --git a/clang/test/Analysis/Checkers/WebKit/retain-ptr-ctor-adopt-use-arc.mm b/clang/test/Analysis/Checkers/WebKit/retain-ptr-ctor-adopt-use-arc.mm
index 47203cbd27355..609b274ce63b4 100644
--- a/clang/test/Analysis/Checkers/WebKit/retain-ptr-ctor-adopt-use-arc.mm
+++ b/clang/test/Analysis/Checkers/WebKit/retain-ptr-ctor-adopt-use-arc.mm
@@ -69,6 +69,9 @@ - (SomeObj *)copyWithValue:(int)value {
return copy;
}
+- (void)copy:(id)sender {
+}
+
- (void)doWork {
_number = [[NSNumber alloc] initWithInt:5];
}
@@ -99,6 +102,17 @@ - (void)setValue:(NSNumber *)value {
@end;
+ at interface SubObj : SomeObj
+ at end
+
+ at implementation SubObj
+
+- (void)copy:(id)sender {
+ [super copy:sender];
+}
+
+ at end
+
RetainPtr<CVPixelBufferRef> cf_out_argument() {
auto surface = adoptCF(IOSurfaceCreate(nullptr));
CVPixelBufferRef rawBuffer = nullptr;
diff --git a/clang/test/Analysis/Checkers/WebKit/retain-ptr-ctor-adopt-use.mm b/clang/test/Analysis/Checkers/WebKit/retain-ptr-ctor-adopt-use.mm
index 427affdbbd601..20f951b27a149 100644
--- a/clang/test/Analysis/Checkers/WebKit/retain-ptr-ctor-adopt-use.mm
+++ b/clang/test/Analysis/Checkers/WebKit/retain-ptr-ctor-adopt-use.mm
@@ -76,6 +76,9 @@ - (SomeObj *)copyWithValue:(int)value {
return copy;
}
+- (void)copy:(id)sender {
+}
+
- (void)doWork {
_number = [[NSNumber alloc] initWithInt:5];
}
@@ -114,6 +117,17 @@ - (id)copyWithZone:(NSZone *)zone {
@end;
+ at interface SubObj : SomeObj
+ at end
+
+ at implementation SubObj
+
+- (void)copy:(id)sender {
+ [super copy:sender];
+}
+
+ at end
+
RetainPtr<CVPixelBufferRef> cf_out_argument() {
auto surface = adoptCF(IOSurfaceCreate(nullptr));
CVPixelBufferRef rawBuffer = nullptr;
``````````
</details>
https://github.com/llvm/llvm-project/pull/179713
More information about the cfe-commits
mailing list