10 #include "clang/AST/ASTContext.h"
11 #include "clang/ASTMatchers/ASTMatchFinder.h"
28 void CalleeNamespaceCheck::registerMatchers(MatchFinder *Finder) {
30 declRefExpr(to(functionDecl().bind(
"func"))).bind(
"use-site"),
this);
33 void CalleeNamespaceCheck::check(
const MatchFinder::MatchResult &Result) {
34 const auto *UsageSiteExpr = Result.Nodes.getNodeAs<DeclRefExpr>(
"use-site");
35 const auto *FuncDecl = Result.Nodes.getNodeAs<FunctionDecl>(
"func");
38 if (FuncDecl->getBuiltinID() != 0)
43 if (NS && NS->getName() ==
"__llvm_libc")
46 diag(UsageSiteExpr->getBeginLoc(),
"%0 must resolve to a function declared "
47 "within the '__llvm_libc' namespace")
50 diag(FuncDecl->getLocation(),
"resolves to this declaration",
51 clang::DiagnosticIDs::Note);