]> granicus.if.org Git - clang/commitdiff
Objective-C arc: don't count use of __weak
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 21 May 2013 21:20:26 +0000 (21:20 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 21 May 2013 21:20:26 +0000 (21:20 +0000)
variables when they are used in such unevaluated
contexts as __typeof, etc. // rdar://13942025

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

include/clang/Sema/Sema.h
lib/Sema/SemaExpr.cpp
lib/Sema/SemaExprMember.cpp
lib/Sema/SemaPseudoObject.cpp
test/SemaObjC/arc-repeated-weak.mm

index 69ef5f9cc23abbb6bd7f4423297a2bbdc57163d1..f4e5cd468b3728a5a722e2020bc2ee0fa185d0c7 100644 (file)
@@ -957,7 +957,13 @@ public:
   sema::FunctionScopeInfo *getCurFunction() const {
     return FunctionScopes.back();
   }
-
+  
+  template <typename ExprT>
+  void recordUseOfEvaluatedWeak(const ExprT *E, bool IsRead=true) {
+    if (!isUnevaluatedContext())
+      getCurFunction()->recordUseOfWeak(E, IsRead);
+  }
+  
   void PushCompoundScope();
   void PopCompoundScope();
 
index 87bc673adff6321537c04a7f82f401d72e338836..9d6601af328b25f6c1288641b77c5197a217be08 100644 (file)
@@ -1550,7 +1550,7 @@ Sema::BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK,
       Diags.getDiagnosticLevel(diag::warn_arc_repeated_use_of_weak,
                                E->getLocStart());
     if (Level != DiagnosticsEngine::Ignored)
-      getCurFunction()->recordUseOfWeak(E);
+      recordUseOfEvaluatedWeak(E);
   }
 
   // Just in case we're building an illegal pointer-to-member.
@@ -2152,7 +2152,7 @@ Sema::LookupInObjCMethod(LookupResult &Lookup, Scope *S,
           DiagnosticsEngine::Level Level =
             Diags.getDiagnosticLevel(diag::warn_arc_repeated_use_of_weak, Loc);
           if (Level != DiagnosticsEngine::Ignored)
-            getCurFunction()->recordUseOfWeak(Result);
+            recordUseOfEvaluatedWeak(Result);
         }
         if (CurContext->isClosure())
           Diag(Loc, diag::warn_implicitly_retains_self)
index 0f65d3f50510cce7baa6bf4ab8b85d6e8c5985d9..6a31a362f0555be80ed7c276e2f97e408a0e4729 100644 (file)
@@ -1311,7 +1311,7 @@ Sema::LookupMemberExpr(LookupResult &R, ExprResult &BaseExpr,
           Diags.getDiagnosticLevel(diag::warn_arc_repeated_use_of_weak,
                                    MemberLoc);
         if (Level != DiagnosticsEngine::Ignored)
-          getCurFunction()->recordUseOfWeak(Result);
+          recordUseOfEvaluatedWeak(Result);
       }
     }
 
index 054d557e92d075bf6d6b5e7bfe660dcf24eb6007..fe11b37068878ccb7d89224d423a9756de369a38 100644 (file)
@@ -882,8 +882,8 @@ ExprResult ObjCPropertyOpBuilder::complete(Expr *SyntacticForm) {
       S.Diags.getDiagnosticLevel(diag::warn_arc_repeated_use_of_weak,
                                  SyntacticForm->getLocStart());
     if (Level != DiagnosticsEngine::Ignored)
-      S.getCurFunction()->recordUseOfWeak(SyntacticRefExpr,
-                                         SyntacticRefExpr->isMessagingGetter());
+      S.recordUseOfEvaluatedWeak(SyntacticRefExpr,
+                                 SyntacticRefExpr->isMessagingGetter());
   }
 
   return PseudoOpBuilder::complete(SyntacticForm);
index b5d9002130d216b5b2f16b4dc09ac61a54583992..64df92a9afa98a26e01fc6c002627a1ea1d675ec 100644 (file)
@@ -410,3 +410,18 @@ void doubleLevelAccessIvar(Test *a, Test *b) {
   use(a.strongProp.weakProp); // no-warning
 }
 
+// rdar://13942025
+@interface X
+@end
+
+@implementation X
+- (int) warningAboutWeakVariableInsideTypeof {
+    __typeof__(self) __weak weakSelf = self;
+    ^(){
+        __typeof__(weakSelf) blockSelf = weakSelf;
+        use(blockSelf);
+    }();
+    return sizeof(weakSelf);
+}
+@end
+