mardi 24 mai 2016

Clang-tidy : Run an added check - Failed

I have to write some new checks with clang-tidy (Release 270030).

I'm trying to run a check I added in a new module.

First, I installed llvm, clang and clang-tidy with the help of this tutorial : http://ift.tt/1adsSaC

Then, I added my own module, my own checks and the checks' tests thanks to this article : http://ift.tt/25dG0L5

I can run the tests without any problem (make check-clang-tools) and I installed clang-tidy (make install).

So far, everything is ok. But when I try to use my checks

clang-tidy '-checks=-,myModule-' test.cpp

it return this error :

clang-llvm/llvm/tools/clang/include/clang/AST/Decl.h:238: llvm::StringRef clang::NamedDecl::getName() const: Assertion `Name.isIdentifier() && "Name is not a simple identifier"' failed.
Abandon

It's the same thing if I run the default check and the default test add with the script "add_new_check.py"

Do you know how to fix it ? I'm running out of ideas...

Here the default check :

#include "MyCheckCheck.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"

using namespace clang::ast_matchers;

namespace clang {
namespace tidy {
namespace myModule{

void myCheckCheck::registerMatchers(MatchFinder *Finder) {
  // FIXME: Add matchers.
  Finder->addMatcher(functionDecl().bind("function"), this);
}

void myCheckCheck::check(const MatchFinder::MatchResult &Result) {
  // FIXME: Add callback implementation.
  const auto *MatchedDecl = Result.Nodes.getNodeAs<FunctionDecl>("function");
  if (MatchedDecl->getName().startswith("awesome_"))
    return;
  diag(MatchedDecl->getLocation(), "function '%0' is insufficiently awesome")
      << MatchedDecl->getName();
      // << FixItHint::CreateInsertion(MatchedDecl->getLocation(), "awesome_");
}

} // namespace myModule
} // namespace tidy
} // namespace clang

Aucun commentaire:

Enregistrer un commentaire