no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / build / clang-plugin / KnownLiveChecker.cpp
blobbe0c3739ec40cc6010af6e5da7ac028ebfe2a835
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/. */
5 #include "KnownLiveChecker.h"
6 #include "CustomMatchers.h"
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.
12 auto KnownLiveLHS = hasLHS(memberExpr(hasKnownLiveAnnotation()).bind("lhs"));
13 auto ForGeneralFunctions = forFunction(
14 functionDecl(unless(anyOf(cxxConstructorDecl(), cxxDestructorDecl())))
15 .bind("func"));
17 auto Matcher =
18 allOf(isAssignmentOperator(), KnownLiveLHS, ForGeneralFunctions);
20 AstMatcher->addMatcher(binaryOperator(Matcher), this);
21 AstMatcher->addMatcher(cxxOperatorCallExpr(Matcher), this);
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";
28 if (const MemberExpr *Expr = Result.Nodes.getNodeAs<MemberExpr>("lhs")) {
29 diag(Expr->getBeginLoc(), Error, DiagnosticIDs::Error);
31 if (const CXXOperatorCallExpr *Expr =
32 Result.Nodes.getNodeAs<CXXOperatorCallExpr>("lhs")) {
33 diag(Expr->getBeginLoc(), Error, DiagnosticIDs::Error);