From: Alexander Shaposhnikov Date: Wed, 12 Apr 2017 22:00:13 +0000 (+0000) Subject: [analyzer] Add a check for IvarRegion in getExtraInvalidatedValues X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=57860dbd4fd152259f53426e0f55658ad4e85e10;p=clang [analyzer] Add a check for IvarRegion in getExtraInvalidatedValues This diff adds a defensive check in getExtraInvalidatedValues for the case when there are no regions for the ivar associated with a property. Corresponding test case added. Test plan: make check-clang make check-clang-analysis git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@300114 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/StaticAnalyzer/Core/CallEvent.cpp b/lib/StaticAnalyzer/Core/CallEvent.cpp index ef824b8a3b..ee761689f4 100644 --- a/lib/StaticAnalyzer/Core/CallEvent.cpp +++ b/lib/StaticAnalyzer/Core/CallEvent.cpp @@ -695,13 +695,15 @@ void ObjCMethodCall::getExtraInvalidatedValues( if (const ObjCPropertyDecl *PropDecl = getAccessedProperty()) { if (const ObjCIvarDecl *PropIvar = PropDecl->getPropertyIvarDecl()) { SVal IvarLVal = getState()->getLValue(PropIvar, getReceiverSVal()); - const MemRegion *IvarRegion = IvarLVal.getAsRegion(); - ETraits->setTrait( + if (const MemRegion *IvarRegion = IvarLVal.getAsRegion()) { + ETraits->setTrait( IvarRegion, RegionAndSymbolInvalidationTraits::TK_DoNotInvalidateSuperRegion); - ETraits->setTrait(IvarRegion, - RegionAndSymbolInvalidationTraits::TK_SuppressEscape); - Values.push_back(IvarLVal); + ETraits->setTrait( + IvarRegion, + RegionAndSymbolInvalidationTraits::TK_SuppressEscape); + Values.push_back(IvarLVal); + } return; } } diff --git a/test/Analysis/properties.m b/test/Analysis/properties.m index 542a339cd6..e792bb2e6b 100644 --- a/test/Analysis/properties.m +++ b/test/Analysis/properties.m @@ -987,5 +987,21 @@ void testOpaqueConsistency(OpaqueIntWrapper *w) { } @end + +@interface Wrapper +@property(nonatomic, readonly) int value; +@end + +@implementation Wrapper +@synthesize value; +@end + +void testNoCrashWhenAccessPropertyAndThereAreNoDirectBindingsAtAll() { + union { + Wrapper *wrapper; + } u = { 0 }; + [u.wrapper value]; +} + #endif // non-ARC