From: Akira Hatanaka Date: Wed, 1 Feb 2017 20:22:26 +0000 (+0000) Subject: [Sema][ObjC] Don't pass a DeclRefExpr that doesn't reference a VarDecl X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0129955a1d3995778d63850048d79196b124fcf5;p=clang [Sema][ObjC] Don't pass a DeclRefExpr that doesn't reference a VarDecl 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 --- diff --git a/lib/Sema/ScopeInfo.cpp b/lib/Sema/ScopeInfo.cpp index 3970b41369..58d44bacea 100644 --- a/lib/Sema/ScopeInfo.cpp +++ b/lib/Sema/ScopeInfo.cpp @@ -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(E)) { if (!RefExpr->isObjectReceiver()) return; @@ -197,10 +197,10 @@ void FunctionScopeInfo::markSafeWeakUse(const Expr *E) { } else if (const ObjCIvarRefExpr *IvarE = dyn_cast(E)) Uses = WeakObjectUses.find(WeakObjectProfileTy(IvarE)); - else if (const DeclRefExpr *DRE = dyn_cast(E)) - Uses = WeakObjectUses.find(WeakObjectProfileTy(DRE)); - else if (const ObjCMessageExpr *MsgE = dyn_cast(E)) { - Uses = WeakObjectUses.end(); + else if (const DeclRefExpr *DRE = dyn_cast(E)) { + if (isa(DRE->getDecl())) + Uses = WeakObjectUses.find(WeakObjectProfileTy(DRE)); + } else if (const ObjCMessageExpr *MsgE = dyn_cast(E)) { if (const ObjCMethodDecl *MD = MsgE->getMethodDecl()) { if (const ObjCPropertyDecl *Prop = MD->findPropertyDecl()) { Uses = diff --git a/test/SemaObjC/arc-repeated-weak.mm b/test/SemaObjC/arc-repeated-weak.mm index 11161a0bf7..8e2828fcac 100644 --- a/test/SemaObjC/arc-repeated-weak.mm +++ b/test/SemaObjC/arc-repeated-weak.mm @@ -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}} +}