10 #include "clang/AST/ASTContext.h" 11 #include "clang/ASTMatchers/ASTMatchFinder.h" 20 AST_MATCHER(VarDecl, isAsm) {
return Node.hasAttr<clang::AsmLabelAttr>(); }
21 const ast_matchers::internal::VariadicDynCastAllOfMatcher<
Decl,
26 void NoAssemblerCheck::registerMatchers(MatchFinder *Finder) {
27 Finder->addMatcher(asmStmt().bind(
"asm-stmt"),
this);
28 Finder->addMatcher(fileScopeAsmDecl().bind(
"asm-file-scope"),
this);
29 Finder->addMatcher(varDecl(isAsm()).bind(
"asm-var"),
this);
32 void NoAssemblerCheck::check(
const MatchFinder::MatchResult &Result) {
33 SourceLocation ASMLocation;
34 if (
const auto *ASM = Result.Nodes.getNodeAs<AsmStmt>(
"asm-stmt"))
35 ASMLocation = ASM->getAsmLoc();
36 else if (
const auto *ASM =
37 Result.Nodes.getNodeAs<FileScopeAsmDecl>(
"asm-file-scope"))
38 ASMLocation = ASM->getAsmLoc();
39 else if (
const auto *ASM = Result.Nodes.getNodeAs<VarDecl>(
"asm-var"))
40 ASMLocation = ASM->getLocation();
42 llvm_unreachable(
"Unhandled case in matcher.");
44 diag(ASMLocation,
"do not use inline assembler in safety-critical code");
const FunctionDecl * Decl
AST_MATCHER(Expr, isMacroID)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//