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())))
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
);