From 5dfb2d36c3180d3d3953022e3bbaf01db0012f3c Mon Sep 17 00:00:00 2001 From: Akira Hatanaka Date: Tue, 22 Mar 2016 05:00:21 +0000 Subject: [PATCH] [Objective-c] Do not set IsExact to true when the receiver is a class. IsExact shouldn't be set to true in WeakObjectProfileTy::getBaseInfo when the receiver is a class because having a class as the receiver doesn't guarantee that the Base is exact. This is a follow-up to r263818. rdar://problem/25208167 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@264025 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Sema/ScopeInfo.h | 1 + lib/Sema/ScopeInfo.cpp | 4 +--- test/SemaObjC/arc-repeated-weak.mm | 11 +++++++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/include/clang/Sema/ScopeInfo.h b/include/clang/Sema/ScopeInfo.h index 0ec59cd380..c57a59db8e 100644 --- a/include/clang/Sema/ScopeInfo.h +++ b/include/clang/Sema/ScopeInfo.h @@ -189,6 +189,7 @@ public: /// [self foo].prop | 0 (unknown) | prop (ObjCPropertyDecl) /// self.prop1.prop2 | prop1 (ObjCPropertyDecl) | prop2 (ObjCPropertyDecl) /// MyClass.prop | MyClass (ObjCInterfaceDecl) | -prop (ObjCMethodDecl) + /// MyClass.foo.prop | +foo (ObjCMethodDecl) | -prop (ObjCPropertyDecl) /// weakVar | 0 (known) | weakVar (VarDecl) /// self->weakIvar | self (VarDecl) | weakIvar (ObjCIvarDecl) /// diff --git a/lib/Sema/ScopeInfo.cpp b/lib/Sema/ScopeInfo.cpp index d18328878c..037ffd843b 100644 --- a/lib/Sema/ScopeInfo.cpp +++ b/lib/Sema/ScopeInfo.cpp @@ -86,9 +86,7 @@ FunctionScopeInfo::WeakObjectProfileTy::getBaseInfo(const Expr *E) { if (BaseProp) { D = getBestPropertyDecl(BaseProp); - if (BaseProp->isClassReceiver()) - IsExact = true; - else { + if (BaseProp->isObjectReceiver()) { const Expr *DoubleBase = BaseProp->getBase(); if (const OpaqueValueExpr *OVE = dyn_cast(DoubleBase)) DoubleBase = OVE->getSourceExpr(); diff --git a/test/SemaObjC/arc-repeated-weak.mm b/test/SemaObjC/arc-repeated-weak.mm index 7ac2313fa3..11161a0bf7 100644 --- a/test/SemaObjC/arc-repeated-weak.mm +++ b/test/SemaObjC/arc-repeated-weak.mm @@ -445,9 +445,20 @@ void doubleLevelAccessIvar(Test *a, Test *b) { @class NSString; @interface NSBundle +(NSBundle *)foo; +@property (class) NSBundle *foo2; @property NSString *prop; +@property(weak) NSString *weakProp; +@end + +@interface NSBundle2 : NSBundle @end void foo() { NSString * t = NSBundle.foo.prop; + use(NSBundle.foo.weakProp); // expected-warning{{weak property 'weakProp' may be accessed multiple times}} + use(NSBundle2.foo.weakProp); // expected-note{{also accessed here}} + + NSString * t2 = NSBundle.foo2.prop; + use(NSBundle.foo2.weakProp); // expected-warning{{weak property 'weakProp' may be accessed multiple times}} + use(NSBundle2.foo2.weakProp); // expected-note{{also accessed here}} } -- 2.50.1