]> granicus.if.org Git - clang/commitdiff
[Objective-c] Fix a crash in WeakObjectProfileTy::getBaseInfo.
authorAkira Hatanaka <ahatanaka@apple.com>
Fri, 18 Mar 2016 19:03:50 +0000 (19:03 +0000)
committerAkira Hatanaka <ahatanaka@apple.com>
Fri, 18 Mar 2016 19:03:50 +0000 (19:03 +0000)
The crash occurs in WeakObjectProfileTy::getBaseInfo when getBase() is
called on an ObjCPropertyRefExpr object whose receiver is an interface.
This commit fixes the crash by checking the type of the receiver and
setting IsExact to true if it is an interface.

rdar://problem/25208167

Differential Revision: http://reviews.llvm.org/D18268

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

lib/Sema/ScopeInfo.cpp
test/SemaObjC/arc-repeated-weak.mm

index ef9eed65ebc5900a612e648a3b31d159f7d9155d..d18328878c73314a6a47db7401f07953a6875811 100644 (file)
@@ -86,11 +86,15 @@ FunctionScopeInfo::WeakObjectProfileTy::getBaseInfo(const Expr *E) {
     if (BaseProp) {
       D = getBestPropertyDecl(BaseProp);
 
-      const Expr *DoubleBase = BaseProp->getBase();
-      if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(DoubleBase))
-        DoubleBase = OVE->getSourceExpr();
-
-      IsExact = DoubleBase->isObjCSelfExpr();
+      if (BaseProp->isClassReceiver())
+        IsExact = true;
+      else {
+        const Expr *DoubleBase = BaseProp->getBase();
+        if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(DoubleBase))
+          DoubleBase = OVE->getSourceExpr();
+
+        IsExact = DoubleBase->isObjCSelfExpr();
+      }
     }
     break;
   }
index 264c598942aec4ed62971aa0a57f4c7933c6f18c..7ac2313fa318a3caf770e43cb2373cacbe629219 100644 (file)
@@ -439,3 +439,15 @@ void doubleLevelAccessIvar(Test *a, Test *b) {
 }
 @end
 
+// This used to crash in WeakObjectProfileTy::getBaseInfo when getBase() was
+// called on an ObjCPropertyRefExpr object whose receiver was an interface.
+
+@class NSString;
+@interface NSBundle
++(NSBundle *)foo;
+@property NSString *prop;
+@end
+
+void foo() {
+  NSString * t = NSBundle.foo.prop;
+}