Author: Ryosuke Niwa Date: 2026-02-05T02:10:36-08:00 New Revision: e9e714f43afbe375f64e9b5e03679a44f1853035
URL: https://github.com/llvm/llvm-project/commit/e9e714f43afbe375f64e9b5e03679a44f1853035 DIFF: https://github.com/llvm/llvm-project/commit/e9e714f43afbe375f64e9b5e03679a44f1853035.diff LOG: [alpha.webkit.RetainPtrCtorAdoptChecker] Don't treat calling (void)copy:(id) as a leak (#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. --------- Co-authored-by: Balázs Benics <[email protected]> Added: Modified: clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp clang/test/Analysis/Checkers/WebKit/retain-ptr-ctor-adopt-use-arc.mm clang/test/Analysis/Checkers/WebKit/retain-ptr-ctor-adopt-use.mm Removed: ################################################################################ diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp index 15971168934b5..4a9a3be2b6614 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp @@ -337,8 +337,13 @@ 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 (MD->getReturnType()->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..79ea95b088167 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]; // no-warning: a void copy does not actually copy anything +} + +@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; +@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
