]> granicus.if.org Git - clang/commitdiff
[analyzer] Add a check for IvarRegion in getExtraInvalidatedValues
authorAlexander Shaposhnikov <shal1t712@gmail.com>
Wed, 12 Apr 2017 22:00:13 +0000 (22:00 +0000)
committerAlexander Shaposhnikov <shal1t712@gmail.com>
Wed, 12 Apr 2017 22:00:13 +0000 (22:00 +0000)
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

lib/StaticAnalyzer/Core/CallEvent.cpp
test/Analysis/properties.m

index ef824b8a3b11c4cb753faf155261fc526a79a105..ee761689f479b30f75ba7af9ad56fd4708ae1de3 100644 (file)
@@ -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;
     }
   }
index 542a339cd6b2cc00f3f03e7c4cb9aa4afe1c0c04..e792bb2e6bada0e45d50115167ed15f2bd1c5457 100644 (file)
@@ -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