From 8acf4ef934c61633e907154eacfcf15baeb0eed2 Mon Sep 17 00:00:00 2001 From: Devin Coughlin Date: Wed, 1 Mar 2017 01:47:37 +0000 Subject: [PATCH] [Analyzer] Fix crash in ObjCPropertyChecker on protocol property 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 | 3 +-- test/Analysis/ObjCPropertiesSyntaxChecks.m | 7 +++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/StaticAnalyzer/Checkers/ObjCPropertyChecker.cpp b/lib/StaticAnalyzer/Checkers/ObjCPropertyChecker.cpp index b9857e51f3..dfd2c9afe7 100644 --- a/lib/StaticAnalyzer/Checkers/ObjCPropertyChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/ObjCPropertyChecker.cpp @@ -58,8 +58,7 @@ void ObjCPropertyChecker::checkCopyMutable(const ObjCPropertyDecl *D, if (const ObjCInterfaceDecl *IntD = dyn_cast(D->getDeclContext())) { ImplD = IntD->getImplementation(); - } else { - const ObjCCategoryDecl *CatD = cast(D->getDeclContext()); + } else if (auto *CatD = dyn_cast(D->getDeclContext())) { ImplD = CatD->getClassInterface()->getImplementation(); } diff --git a/test/Analysis/ObjCPropertiesSyntaxChecks.m b/test/Analysis/ObjCPropertiesSyntaxChecks.m index 5c642c5817..1c3ddbd1f6 100644 --- a/test/Analysis/ObjCPropertiesSyntaxChecks.m +++ b/test/Analysis/ObjCPropertiesSyntaxChecks.m @@ -59,3 +59,10 @@ @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 -- 2.40.0