]> granicus.if.org Git - clang/commitdiff
[Analyzer] Fix crash in ObjCPropertyChecker on protocol property
authorDevin Coughlin <dcoughlin@apple.com>
Wed, 1 Mar 2017 01:47:37 +0000 (01:47 +0000)
committerDevin Coughlin <dcoughlin@apple.com>
Wed, 1 Mar 2017 01:47:37 +0000 (01:47 +0000)
Fix a crash in the ObjCPropertyChecker when analyzing a 'copy' property of an
NSMutable* type in a protocol.

rdar://problem/30766684

Differential Revision: https://reviews.llvm.org/D30482

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

lib/StaticAnalyzer/Checkers/ObjCPropertyChecker.cpp
test/Analysis/ObjCPropertiesSyntaxChecks.m

index b9857e51f3eaac4494b7c5cd6c5e5d3917cba407..dfd2c9afe7fb055cb4ec4b563cd1a38c055cc06f 100644 (file)
@@ -58,8 +58,7 @@ void ObjCPropertyChecker::checkCopyMutable(const ObjCPropertyDecl *D,
   if (const ObjCInterfaceDecl *IntD =
           dyn_cast<ObjCInterfaceDecl>(D->getDeclContext())) {
     ImplD = IntD->getImplementation();
-  } else {
-    const ObjCCategoryDecl *CatD = cast<ObjCCategoryDecl>(D->getDeclContext());
+  } else if (auto *CatD = dyn_cast<ObjCCategoryDecl>(D->getDeclContext())) {
     ImplD = CatD->getClassInterface()->getImplementation();
   }
 
index 5c642c58173644bf80bbb765d41a99c337032d91..1c3ddbd1f6fb52d82f729793b36a459a1e2b0e6a 100644 (file)
 @interface IWithoutImpl : NSObject {}
 @property(copy) NSMutableString *mutableStr; // no-warning
 @end
+
+@protocol SomeProtocol
+// Don't warn on protocol properties because it is possible to
+// conform to them correctly; it is only synthesized setters that
+// that are definitely incorrect.
+@property (copy) NSMutableString *myProp; // no-crash // no-warning
+@end