Backed out d952a7d6bfb4 (bug 1170388) on a CLOSED TREE for static analysis bustage. r=bustage
authorBotond Ballo <botond@mozilla.com>
Fri, 05 Jun 2015 00:14:14 -0400
changeset 247281 b0b9843b8654e121c1e0516c409c4b2e4cfbcaa5
parent 247280 0ed1ae70d92286c2006b29e954e6c8a14b0c94a8
child 247282 ca87dfad14cfb10a0025655f18dc2094c2884a7f
push id60662
push userbballo@mozilla.com
push dateFri, 05 Jun 2015 04:13:17 +0000
treeherdermozilla-inbound@b0b9843b8654 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbustage
bugs1170388
milestone41.0a1
backs outd952a7d6bfb450918806cfb22aa47e8eb05df3e6
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Backed out d952a7d6bfb4 (bug 1170388) on a CLOSED TREE for static analysis bustage. r=bustage
build/clang-plugin/clang-plugin.cpp
build/clang-plugin/tests/TestNoRefcountedInsideLambdas.cpp
--- a/build/clang-plugin/clang-plugin.cpp
+++ b/build/clang-plugin/clang-plugin.cpp
@@ -699,24 +699,18 @@ DiagnosticsMatcher::DiagnosticsMatcher()
   // Then, look for MemberExpr that need to be casted to the right type using
   // an intermediary CastExpr before we get to the CallExpr.
   astMatcher.addMatcher(callExpr(callee(functionDecl(hasNoAddRefReleaseOnReturnAttr()).bind("func")),
                                  hasParent(castExpr(hasParent(memberExpr(isAddRefOrRelease(),
                                                                          hasParent(callExpr())).bind("member"))))
       ).bind("node"),
     &noAddRefReleaseOnReturnChecker);
 
-  // Match declrefs with type "pointer to object of ref-counted type" inside a
-  // lambda, where the declaration they reference is not inside the lambda.
-  // This excludes arguments and local variables, leaving only captured
-  // variables.
   astMatcher.addMatcher(lambdaExpr(
-            hasDescendant(declRefExpr(hasType(pointerType(pointee(isRefCounted()))),
-                                      to(decl().bind("decl"))).bind("declref")),
-            unless(hasDescendant(decl(equalsBoundNode("decl"))))
+            hasDescendant(declRefExpr(hasType(pointerType(pointee(isRefCounted())))).bind("node"))
         ),
     &refCountedInsideLambdaChecker);
 
   // Older clang versions such as the ones used on the infra recognize these
   // conversions as 'operator _Bool', but newer clang versions recognize these
   // as 'operator bool'.
   astMatcher.addMatcher(methodDecl(anyOf(hasName("operator bool"),
                                          hasName("operator _Bool"))).bind("node"),
@@ -918,24 +912,24 @@ void DiagnosticsMatcher::NoAddRefRelease
 
   Diag.Report(node->getLocStart(), errorID) << func << method;
 }
 
 void DiagnosticsMatcher::RefCountedInsideLambdaChecker::run(
     const MatchFinder::MatchResult &Result) {
   DiagnosticsEngine &Diag = Result.Context->getDiagnostics();
   unsigned errorID = Diag.getDiagnosticIDs()->getCustomDiagID(
-      DiagnosticIDs::Error, "Refcounted variable %0 of type %1 cannot be captured by a lambda");
+      DiagnosticIDs::Error, "Refcounted variable %0 of type %1 cannot be used inside a lambda");
   unsigned noteID = Diag.getDiagnosticIDs()->getCustomDiagID(
       DiagnosticIDs::Note, "Please consider using a smart pointer");
-  const DeclRefExpr *declref = Result.Nodes.getNodeAs<DeclRefExpr>("declref");
+  const DeclRefExpr *node = Result.Nodes.getNodeAs<DeclRefExpr>("node");
 
-  Diag.Report(declref->getLocStart(), errorID) << declref->getFoundDecl() <<
-    declref->getType()->getPointeeType();
-  Diag.Report(declref->getLocStart(), noteID);
+  Diag.Report(node->getLocStart(), errorID) << node->getFoundDecl() <<
+    node->getType()->getPointeeType();
+  Diag.Report(node->getLocStart(), noteID);
 }
 
 void DiagnosticsMatcher::ExplicitOperatorBoolChecker::run(
     const MatchFinder::MatchResult &Result) {
   DiagnosticsEngine &Diag = Result.Context->getDiagnostics();
   unsigned errorID = Diag.getDiagnosticIDs()->getCustomDiagID(
       DiagnosticIDs::Error, "bad implicit conversion operator for %0");
   unsigned noteID = Diag.getDiagnosticIDs()->getCustomDiagID(
--- a/build/clang-plugin/tests/TestNoRefcountedInsideLambdas.cpp
+++ b/build/clang-plugin/tests/TestNoRefcountedInsideLambdas.cpp
@@ -14,81 +14,45 @@ struct SmartPtr {
 struct R : RefCountedBase {
   void method();
 };
 
 void take(...);
 void foo() {
   R* ptr;
   SmartPtr<R> sp;
-  take([&](R* argptr) {
-    R* localptr;
-    ptr->method(); // expected-error{{Refcounted variable 'ptr' of type 'R' cannot be captured by a lambda}} expected-note{{Please consider using a smart pointer}}
-    argptr->method();
-    localptr->method();
+  take([&]() {
+    ptr->method(); // expected-error{{Refcounted variable 'ptr' of type 'R' cannot be used inside a lambda}} expected-note{{Please consider using a smart pointer}}
   });
-  take([&](SmartPtr<R> argsp) {
-    SmartPtr<R> localsp;
+  take([&]() {
     sp->method();
-    argsp->method();
-    localsp->method();
   });
-  take([&](R* argptr) {
-    R* localptr;
-    take(ptr); // expected-error{{Refcounted variable 'ptr' of type 'R' cannot be captured by a lambda}} expected-note{{Please consider using a smart pointer}}
-    take(argptr);
-    take(localptr);
+  take([&]() {
+    take(ptr); // expected-error{{Refcounted variable 'ptr' of type 'R' cannot be used inside a lambda}} expected-note{{Please consider using a smart pointer}}
   });
-  take([&](SmartPtr<R> argsp) {
-    SmartPtr<R> localsp;
+  take([&]() {
     take(sp);
-    take(argsp);
-    take(localsp);
   });
-  take([=](R* argptr) {
-    R* localptr;
-    ptr->method(); // expected-error{{Refcounted variable 'ptr' of type 'R' cannot be captured by a lambda}} expected-note{{Please consider using a smart pointer}}
-    argptr->method();
-    localptr->method();
+  take([=]() {
+    ptr->method(); // expected-error{{Refcounted variable 'ptr' of type 'R' cannot be used inside a lambda}} expected-note{{Please consider using a smart pointer}}
   });
-  take([=](SmartPtr<R> argsp) {
-    SmartPtr<R> localsp;
+  take([=]() {
     sp->method();
-    argsp->method();
-    localsp->method();
   });
-  take([=](R* argptr) {
-    R* localptr;
-    take(ptr); // expected-error{{Refcounted variable 'ptr' of type 'R' cannot be captured by a lambda}} expected-note{{Please consider using a smart pointer}}
-    take(argptr);
-    take(localptr);
+  take([=]() {
+    take(ptr); // expected-error{{Refcounted variable 'ptr' of type 'R' cannot be used inside a lambda}} expected-note{{Please consider using a smart pointer}}
   });
-  take([=](SmartPtr<R> argsp) {
-    SmartPtr<R> localsp;
+  take([=]() {
     take(sp);
-    take(argsp);
-    take(localsp);
   });
-  take([ptr](R* argptr) {
-    R* localptr;
-    ptr->method(); // expected-error{{Refcounted variable 'ptr' of type 'R' cannot be captured by a lambda}} expected-note{{Please consider using a smart pointer}}
-    argptr->method();
-    localptr->method();
+  take([ptr]() {
+    ptr->method(); // expected-error{{Refcounted variable 'ptr' of type 'R' cannot be used inside a lambda}} expected-note{{Please consider using a smart pointer}}
   });
-  take([sp](SmartPtr<R> argsp) {
-    SmartPtr<R> localsp;
+  take([sp]() {
     sp->method();
-    argsp->method();
-    localsp->method();
   });
-  take([ptr](R* argptr) {
-    R* localptr;
-    take(ptr); // expected-error{{Refcounted variable 'ptr' of type 'R' cannot be captured by a lambda}} expected-note{{Please consider using a smart pointer}}
-    take(argptr);
-    take(localptr);
+  take([ptr]() {
+    take(ptr); // expected-error{{Refcounted variable 'ptr' of type 'R' cannot be used inside a lambda}} expected-note{{Please consider using a smart pointer}}
   });
-  take([sp](SmartPtr<R> argsp) {
-    SmartPtr<R> localsp;
+  take([sp]() {
     take(sp);
-    take(argsp);
-    take(localsp);
   });
 }