10#include "clang/AST/ASTContext.h"
11#include "clang/ASTMatchers/ASTMatchFinder.h"
13#include "llvm/ADT/StringSet.h"
23 if (
Parent->isTranslationUnit())
30 declRefExpr(to(functionDecl().bind(
"func"))).bind(
"use-site"),
this);
38 "__errno_location",
"malloc",
"calloc",
"realloc",
"free",
"aligned_alloc"};
41 const auto *UsageSiteExpr = Result.Nodes.getNodeAs<DeclRefExpr>(
"use-site");
42 const auto *FuncDecl = Result.Nodes.getNodeAs<FunctionDecl>(
"func");
45 if (FuncDecl->getBuiltinID() != 0)
50 if (NS && NS->getName() ==
"__llvm_libc")
53 const DeclarationName &
Name = FuncDecl->getDeclName();
54 if (
Name.isIdentifier() &&
58 diag(UsageSiteExpr->getBeginLoc(),
"%0 must resolve to a function declared "
59 "within the '__llvm_libc' namespace")
62 diag(FuncDecl->getLocation(),
"resolves to this declaration",
63 clang::DiagnosticIDs::Note);
const FunctionDecl * Decl
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
const DeclContext * getOutermostNamespace(const DeclContext *Decl)
static const llvm::StringSet IgnoredFunctions