Author: dergachev Date: Fri Dec 14 18:09:02 2018 New Revision: 349228 URL: http://llvm.org/viewvc/llvm-project?rev=349228&view=rev Log: [analyzer] ObjCDealloc: Fix a crash when a class attempts to deallocate a class.
The checker wasn't prepared to see the dealloc message sent to the class itself rather than to an instance, as if it was +dealloc. Additionally, it wasn't prepared for pure-unknown or undefined self values. The new guard covers that as well, but it is annoying to test because both kinds of values shouldn't really appear and we generally want to get rid of all of them (by modeling unknown values with symbols and by warning on use of undefined values before they are used). The CHECK: directive for FileCheck at the end of the test looks useless, so i removed it. Differential Revision: https://reviews.llvm.org/D55680 Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp cfe/trunk/test/Analysis/MissingDealloc.m Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp?rev=349228&r1=349227&r2=349228&view=diff ============================================================================== --- cfe/trunk/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp (original) +++ cfe/trunk/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp Fri Dec 14 18:09:02 2018 @@ -715,6 +715,10 @@ bool ObjCDeallocChecker::diagnoseExtraRe bool ObjCDeallocChecker::diagnoseMistakenDealloc(SymbolRef DeallocedValue, const ObjCMethodCall &M, CheckerContext &C) const { + // TODO: Apart from unknown/undefined receivers, this may happen when + // dealloc is called as a class method. Should we warn? + if (!DeallocedValue) + return false; // Find the property backing the instance variable that M // is dealloc'ing. Modified: cfe/trunk/test/Analysis/MissingDealloc.m URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/MissingDealloc.m?rev=349228&r1=349227&r2=349228&view=diff ============================================================================== --- cfe/trunk/test/Analysis/MissingDealloc.m (original) +++ cfe/trunk/test/Analysis/MissingDealloc.m Fri Dec 14 18:09:02 2018 @@ -183,4 +183,17 @@ __attribute__((objc_root_class)) @implementation NonNSObjectMissingDealloc @end -// CHECK: 4 warnings generated. + +//===------------------------------------------------------------------------=== +// Don't crash on calls to dealloc as a class method. + +@interface DeallocingClass : NSObject {} +@end +@implementation DeallocingClass +- (void)dealloc { + [DeallocingClass dealloc]; // FIXME: Should we warn on this specifically? +} +#if NON_ARC +// expected-warning@-2{{method possibly missing a [super dealloc] call}} +#endif +@end _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits