]> granicus.if.org Git - clang/commitdiff
[Sema][ObjC] Don't pass a DeclRefExpr that doesn't reference a VarDecl
authorAkira Hatanaka <ahatanaka@apple.com>
Wed, 1 Feb 2017 20:22:26 +0000 (20:22 +0000)
committerAkira Hatanaka <ahatanaka@apple.com>
Wed, 1 Feb 2017 20:22:26 +0000 (20:22 +0000)
to WeakObjectProfileTy's constructor.

This fixes an assertion failure in WeakObjectProfileTy's constructor.

rdar://problem/30112633

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

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

index 3970b4136982f6ea57aa2754117475544da4691d..58d44bacea97ff3423acc14cfb0b3e5fe112a707 100644 (file)
@@ -184,7 +184,7 @@ void FunctionScopeInfo::markSafeWeakUse(const Expr *E) {
   }
 
   // Has this weak object been seen before?
-  FunctionScopeInfo::WeakObjectUseMap::iterator Uses;
+  FunctionScopeInfo::WeakObjectUseMap::iterator Uses = WeakObjectUses.end();
   if (const ObjCPropertyRefExpr *RefExpr = dyn_cast<ObjCPropertyRefExpr>(E)) {
     if (!RefExpr->isObjectReceiver())
       return;
@@ -197,10 +197,10 @@ void FunctionScopeInfo::markSafeWeakUse(const Expr *E) {
   }
   else if (const ObjCIvarRefExpr *IvarE = dyn_cast<ObjCIvarRefExpr>(E))
     Uses = WeakObjectUses.find(WeakObjectProfileTy(IvarE));
-  else if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E))
-    Uses = WeakObjectUses.find(WeakObjectProfileTy(DRE));
-  else if (const ObjCMessageExpr *MsgE = dyn_cast<ObjCMessageExpr>(E)) {
-    Uses = WeakObjectUses.end();
+  else if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) {
+    if (isa<VarDecl>(DRE->getDecl()))
+      Uses = WeakObjectUses.find(WeakObjectProfileTy(DRE));
+  } else if (const ObjCMessageExpr *MsgE = dyn_cast<ObjCMessageExpr>(E)) {
     if (const ObjCMethodDecl *MD = MsgE->getMethodDecl()) {
       if (const ObjCPropertyDecl *Prop = MD->findPropertyDecl()) {
         Uses =
index 11161a0bf7fc0cf0bcbaaf64df33a48d85e26d94..8e2828fcaceaf36aba780e975fa16fb9811849a3 100644 (file)
@@ -462,3 +462,16 @@ void foo() {
   use(NSBundle.foo2.weakProp); // expected-warning{{weak property 'weakProp' may be accessed multiple times}}
   use(NSBundle2.foo2.weakProp); // expected-note{{also accessed here}}
 }
+
+// This used to crash in the constructor of WeakObjectProfileTy when a
+// DeclRefExpr was passed that didn't reference a VarDecl.
+
+typedef INTF * INTFPtrTy;
+
+enum E {
+  e1
+};
+
+void foo1() {
+  INTFPtrTy tmp = (INTFPtrTy)e1; // expected-error{{cast of 'E' to 'INTFPtrTy' (aka 'INTF *') is disallowed with ARC}}
+}