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