Просмотр исходного кода

[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
Akira Hatanaka 9 лет назад
Родитель
Сommit
5dfb2d36c3
3 измененных файлов с 13 добавлено и 3 удалено
  1. 1 0
      include/clang/Sema/ScopeInfo.h
  2. 1 3
      lib/Sema/ScopeInfo.cpp
  3. 11 0
      test/SemaObjC/arc-repeated-weak.mm

+ 1 - 0
include/clang/Sema/ScopeInfo.h

@@ -189,6 +189,7 @@ public:
   /// [self foo].prop   | 0 (unknown)         | prop (ObjCPropertyDecl)
   /// [self foo].prop   | 0 (unknown)         | prop (ObjCPropertyDecl)
   /// self.prop1.prop2  | prop1 (ObjCPropertyDecl)    | prop2 (ObjCPropertyDecl)
   /// self.prop1.prop2  | prop1 (ObjCPropertyDecl)    | prop2 (ObjCPropertyDecl)
   /// MyClass.prop      | MyClass (ObjCInterfaceDecl) | -prop (ObjCMethodDecl)
   /// MyClass.prop      | MyClass (ObjCInterfaceDecl) | -prop (ObjCMethodDecl)
+  /// MyClass.foo.prop  | +foo (ObjCMethodDecl)       | -prop (ObjCPropertyDecl)
   /// weakVar           | 0 (known)           | weakVar (VarDecl)
   /// weakVar           | 0 (known)           | weakVar (VarDecl)
   /// self->weakIvar    | self (VarDecl)      | weakIvar (ObjCIvarDecl)
   /// self->weakIvar    | self (VarDecl)      | weakIvar (ObjCIvarDecl)
   ///
   ///

+ 1 - 3
lib/Sema/ScopeInfo.cpp

@@ -86,9 +86,7 @@ FunctionScopeInfo::WeakObjectProfileTy::getBaseInfo(const Expr *E) {
     if (BaseProp) {
     if (BaseProp) {
       D = getBestPropertyDecl(BaseProp);
       D = getBestPropertyDecl(BaseProp);
 
 
-      if (BaseProp->isClassReceiver())
-        IsExact = true;
-      else {
+      if (BaseProp->isObjectReceiver()) {
         const Expr *DoubleBase = BaseProp->getBase();
         const Expr *DoubleBase = BaseProp->getBase();
         if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(DoubleBase))
         if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(DoubleBase))
           DoubleBase = OVE->getSourceExpr();
           DoubleBase = OVE->getSourceExpr();

+ 11 - 0
test/SemaObjC/arc-repeated-weak.mm

@@ -445,9 +445,20 @@ void doubleLevelAccessIvar(Test *a, Test *b) {
 @class NSString;
 @class NSString;
 @interface NSBundle
 @interface NSBundle
 +(NSBundle *)foo;
 +(NSBundle *)foo;
+@property (class) NSBundle *foo2;
 @property NSString *prop;
 @property NSString *prop;
+@property(weak) NSString *weakProp;
+@end
+
+@interface NSBundle2 : NSBundle
 @end
 @end
 
 
 void foo() {
 void foo() {
   NSString * t = NSBundle.foo.prop;
   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}}
 }
 }