[PATCH] D18268: [Objective-c] Fix a crash in WeakObjectProfileTy::getBaseInfo

Akira Hatanaka via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 18 08:15:16 PDT 2016


ahatanak created this revision.
ahatanak added a reviewer: jordan_rose.
ahatanak added a subscriber: cfe-commits.

The crash occurs in WeakObjectProfileTy::getBaseInfo when getBase() is called on an ObjCPropertyRefExpr object whose receiver is an interface. This patch fixes the crash by checking the type of the receiver and setting IsExact to true if it is an interface.

http://reviews.llvm.org/D18268

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

Index: test/SemaObjC/arc-repeated-weak.mm
===================================================================
--- test/SemaObjC/arc-repeated-weak.mm
+++ test/SemaObjC/arc-repeated-weak.mm
@@ -439,3 +439,15 @@
 }
 @end
 
+// This used to crash in WeakObjectProfileTy::getBaseInfo when getBase() was
+// called on an ObjCPropertyRefExpr object whose receiver was an interface.
+
+ at class NSString;
+ at interface NSBundle
++(NSBundle *)foo;
+ at property NSString *prop;
+ at end
+
+void foo() {
+  NSString * t = NSBundle.foo.prop;
+}
Index: lib/Sema/ScopeInfo.cpp
===================================================================
--- lib/Sema/ScopeInfo.cpp
+++ lib/Sema/ScopeInfo.cpp
@@ -86,11 +86,15 @@
     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;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18268.51025.patch
Type: text/x-patch
Size: 1331 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160318/024cd1f0/attachment.bin>


More information about the cfe-commits mailing list