https://github.com/rniwa created https://github.com/llvm/llvm-project/pull/179713
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. >From a27e3e30f6774f3f350250ac4221df26e1b8b874 Mon Sep 17 00:00:00 2001 From: Ryosuke Niwa <[email protected]> Date: Wed, 4 Feb 2026 09:36:34 -0800 Subject: [PATCH] [alpha.webkit.RetainPtrCtorAdoptChecker] Don't treat calling (void)copy:(id) as a leak 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. --- .../StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp | 9 ++++++++- .../WebKit/retain-ptr-ctor-adopt-use-arc.mm | 14 ++++++++++++++ .../Checkers/WebKit/retain-ptr-ctor-adopt-use.mm | 14 ++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp index 15971168934b58..f9d35c595682b0 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 47203cbd273554..609b274ce63b43 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; +@interface SubObj : SomeObj +@end + +@implementation SubObj + +- (void)copy:(id)sender { + [super copy:sender]; +} + +@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 427affdbbd6010..20f951b27a149a 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; +@interface SubObj : SomeObj +@end + +@implementation SubObj + +- (void)copy:(id)sender { + [super copy:sender]; +} + +@end + RetainPtr<CVPixelBufferRef> cf_out_argument() { auto surface = adoptCF(IOSurfaceCreate(nullptr)); CVPixelBufferRef rawBuffer = nullptr; _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
