Bug 1324315 - Refactor the clang plugin to use a framework similar to clang-tidy's; r=mystor
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
|
||||
RefCountedMap RefCountedClasses;
|
||||
|
||||
void RefCountedInsideLambdaChecker::registerMatcher(MatchFinder& AstMatcher) {
|
||||
void RefCountedInsideLambdaChecker::registerMatchers(MatchFinder* AstMatcher) {
|
||||
// We want to reject any code which captures a pointer to an object of a
|
||||
// refcounted type, and then lets that value escape. As a primitive analysis,
|
||||
// we reject any occurances of the lambda as a template parameter to a class
|
||||
@@ -15,29 +15,27 @@ void RefCountedInsideLambdaChecker::registerMatcher(MatchFinder& AstMatcher) {
|
||||
// in a return value (either from lambdas, or in c++14, auto functions).
|
||||
//
|
||||
// We check these lambdas' capture lists for raw pointers to refcounted types.
|
||||
AstMatcher.addMatcher(
|
||||
AstMatcher->addMatcher(
|
||||
functionDecl(returns(recordType(hasDeclaration(cxxRecordDecl(
|
||||
isLambdaDecl()).bind("decl"))))),
|
||||
this);
|
||||
AstMatcher.addMatcher(lambdaExpr().bind("lambdaExpr"),
|
||||
AstMatcher->addMatcher(lambdaExpr().bind("lambdaExpr"),
|
||||
this);
|
||||
AstMatcher.addMatcher(
|
||||
AstMatcher->addMatcher(
|
||||
classTemplateSpecializationDecl(hasAnyTemplateArgument(refersToType(
|
||||
recordType(hasDeclaration(cxxRecordDecl(
|
||||
isLambdaDecl()).bind("decl")))))),
|
||||
this);
|
||||
}
|
||||
|
||||
void RefCountedInsideLambdaChecker::run(
|
||||
void RefCountedInsideLambdaChecker::check(
|
||||
const MatchFinder::MatchResult &Result) {
|
||||
static DenseSet<const CXXRecordDecl*> CheckedDecls;
|
||||
|
||||
DiagnosticsEngine &Diag = Result.Context->getDiagnostics();
|
||||
unsigned ErrorID = Diag.getDiagnosticIDs()->getCustomDiagID(
|
||||
DiagnosticIDs::Error,
|
||||
"Refcounted variable %0 of type %1 cannot be captured by a lambda");
|
||||
unsigned NoteID = Diag.getDiagnosticIDs()->getCustomDiagID(
|
||||
DiagnosticIDs::Note, "Please consider using a smart pointer");
|
||||
const char* Error =
|
||||
"Refcounted variable %0 of type %1 cannot be captured by a lambda";
|
||||
const char* Note =
|
||||
"Please consider using a smart pointer";
|
||||
|
||||
const CXXRecordDecl *Lambda = Result.Nodes.getNodeAs<CXXRecordDecl>("decl");
|
||||
|
||||
@@ -65,9 +63,11 @@ void RefCountedInsideLambdaChecker::run(
|
||||
QualType Pointee = Capture.getCapturedVar()->getType()->getPointeeType();
|
||||
|
||||
if (!Pointee.isNull() && isClassRefCounted(Pointee)) {
|
||||
Diag.Report(Capture.getLocation(), ErrorID) << Capture.getCapturedVar()
|
||||
<< Pointee;
|
||||
Diag.Report(Capture.getLocation(), NoteID);
|
||||
diag(Capture.getLocation(), Error,
|
||||
DiagnosticIDs::Error) << Capture.getCapturedVar()
|
||||
<< Pointee;
|
||||
diag(Capture.getLocation(), Note,
|
||||
DiagnosticIDs::Note);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user