Bug 1514801 - refactor clang based checker - KungFuDeathGripChecker. r=glandium

Differential Revision: https://phabricator.services.mozilla.com/D38187

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andi-Bogdan Postelnicu 2019-07-17 05:05:30 +00:00
Родитель c897fe1404
Коммит 782c64d21c
1 изменённых файлов: 12 добавлений и 2 удалений

Просмотреть файл

@ -6,7 +6,11 @@
#include "CustomMatchers.h"
void KungFuDeathGripChecker::registerMatchers(MatchFinder *AstMatcher) {
AstMatcher->addMatcher(varDecl(hasType(isRefPtr())).bind("decl"), this);
AstMatcher->addMatcher(varDecl(allOf(hasType(isRefPtr()),
hasLocalStorage(),
hasInitializer(anything())))
.bind("decl"),
this);
}
void KungFuDeathGripChecker::check(const MatchFinder::MatchResult &Result) {
@ -16,7 +20,7 @@ void KungFuDeathGripChecker::check(const MatchFinder::MatchResult &Result) {
"'%1', or explicitly pass '%1' to `mozilla::Unused`";
const VarDecl *D = Result.Nodes.getNodeAs<VarDecl>("decl");
if (D->isReferenced() || !D->hasLocalStorage() || !D->hasInit()) {
if (D->isReferenced()) {
return;
}
@ -44,6 +48,12 @@ void KungFuDeathGripChecker::check(const MatchFinder::MatchResult &Result) {
E = IgnoreTrivials(CE->getArg(0));
}
// It is possible that the QualType doesn't point to a type yet so we are
// not interested.
if (E->getType().isNull()) {
return;
}
// We allow taking a kungFuDeathGrip of `this` because it cannot change
// beneath us, so calling directly through `this` is OK. This is the same
// for local variable declarations.