]> granicus.if.org Git - clang/commitdiff
[analyzer] ObjCDeallocChecker: Only check for nil-out when type is retainable.
authorDevin Coughlin <dcoughlin@apple.com>
Thu, 3 Mar 2016 21:38:39 +0000 (21:38 +0000)
committerDevin Coughlin <dcoughlin@apple.com>
Thu, 3 Mar 2016 21:38:39 +0000 (21:38 +0000)
This fixes a crash when setting a property of struct type in -dealloc.

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

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

index c09924cfc2e40283a5cb55d89dc742f05cc3674e..f9fd9fcf957b113f5a2a40db43755319f5369dfc 100644 (file)
@@ -860,9 +860,13 @@ ObjCDeallocChecker::getValueReleasedByNillingOut(const ObjCMethodCall &M,
   if (!ReceiverVal.isValid())
     return nullptr;
 
-  // Is the first argument nil?
   if (M.getNumArgs() == 0)
     return nullptr;
+
+  if (!M.getArgExpr(0)->getType()->isObjCRetainableType())
+    return nullptr;
+
+  // Is the first argument nil?
   SVal Arg = M.getArgSVal(0);
   ProgramStateRef notNilState, nilState;
   std::tie(notNilState, nilState) =
index 383bacb539feae53ec254c3f1947c4773a56592c..75afd0e5f1b23cf2d0a39bb7e14c5065cb9ed52a 100644 (file)
@@ -664,6 +664,25 @@ void ReleaseMe(id arg);
 @end
 #endif
 
+struct SomeStruct {
+  int f;
+};
+@interface ZeroOutStructWithSetter : NSObject
+  @property(assign) struct SomeStruct s;
+@end
+
+@implementation ZeroOutStructWithSetter
+- (void)dealloc {
+  struct SomeStruct zeroedS;
+  zeroedS.f = 0;
+
+  self.s = zeroedS;
+#if NON_ARC
+  [super dealloc];
+#endif
+}
+@end
+
 #if NON_ARC
 @interface ReleaseIvarInArray : NSObject {
   NSObject *_array[3];