]> granicus.if.org Git - clang/commitdiff
[analyzer] ObjCDealloc: Fix a crash when a class attempts to deallocate a class.
authorArtem Dergachev <artem.dergachev@gmail.com>
Sat, 15 Dec 2018 02:09:02 +0000 (02:09 +0000)
committerArtem Dergachev <artem.dergachev@gmail.com>
Sat, 15 Dec 2018 02:09:02 +0000 (02:09 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349228 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
test/Analysis/MissingDealloc.m

index c330d7504b9489f58a68139dbd458b4e70051395..faee82895bf5f58dad4e520fd58c5647bec40712 100644 (file)
@@ -715,6 +715,10 @@ bool ObjCDeallocChecker::diagnoseExtraRelease(SymbolRef ReleasedValue,
 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.
index bedd1e7fc25a407bf4ab00b8e99bb914a84c0ed2..bdba93c8815a252f2a1cc9d1d2d3172ce2a70d13 100644 (file)
@@ -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