tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

KnownLiveChecker.cpp (1399B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 #include "KnownLiveChecker.h"
      6 #include "CustomMatchers.h"
      7 
      8 void KnownLiveChecker::registerMatchers(MatchFinder *AstMatcher) {
      9  // Note that this cannot catch mutations after pass-by-reference, and thus no
     10  // error for cycle collection macros.
     11 
     12  auto KnownLiveLHS = hasLHS(memberExpr(hasKnownLiveAnnotation()).bind("lhs"));
     13  auto ForGeneralFunctions = forFunction(
     14      functionDecl(unless(anyOf(cxxConstructorDecl(), cxxDestructorDecl())))
     15          .bind("func"));
     16 
     17  auto Matcher =
     18      allOf(isAssignmentOperator(), KnownLiveLHS, ForGeneralFunctions);
     19 
     20  AstMatcher->addMatcher(binaryOperator(Matcher), this);
     21  AstMatcher->addMatcher(cxxOperatorCallExpr(Matcher), this);
     22 }
     23 
     24 void KnownLiveChecker::check(const MatchFinder::MatchResult &Result) {
     25  const char *Error = "MOZ_KNOWN_LIVE members can only be modified by "
     26                      "constructors and destructors";
     27 
     28  if (const MemberExpr *Expr = Result.Nodes.getNodeAs<MemberExpr>("lhs")) {
     29    diag(Expr->getBeginLoc(), Error, DiagnosticIDs::Error);
     30  }
     31  if (const CXXOperatorCallExpr *Expr =
     32          Result.Nodes.getNodeAs<CXXOperatorCallExpr>("lhs")) {
     33    diag(Expr->getBeginLoc(), Error, DiagnosticIDs::Error);
     34  }
     35 }