11 #include "clang/AST/ASTContext.h" 12 #include "clang/ASTMatchers/ASTMatchFinder.h" 17 namespace ast_matchers {
18 AST_MATCHER(VarDecl, isAsm) {
return Node.hasAttr<clang::AsmLabelAttr>(); }
19 const internal::VariadicDynCastAllOfMatcher<Decl, FileScopeAsmDecl>
28 void NoAssemblerCheck::registerMatchers(MatchFinder *Finder) {
29 Finder->addMatcher(asmStmt().bind(
"asm-stmt"),
this);
31 Finder->addMatcher(varDecl(isAsm()).bind(
"asm-var"),
this);
34 void NoAssemblerCheck::check(
const MatchFinder::MatchResult &Result) {
35 SourceLocation ASMLocation;
36 if (
const auto *ASM = Result.Nodes.getNodeAs<AsmStmt>(
"asm-stmt"))
37 ASMLocation = ASM->getAsmLoc();
38 else if (
const auto *ASM =
39 Result.Nodes.getNodeAs<FileScopeAsmDecl>(
"asm-file-scope"))
40 ASMLocation = ASM->getAsmLoc();
41 else if (
const auto *ASM = Result.Nodes.getNodeAs<VarDecl>(
"asm-var"))
42 ASMLocation = ASM->getLocation();
44 llvm_unreachable(
"Unhandled case in matcher.");
46 diag(ASMLocation,
"do not use inline assembler in safety-critical code");
const internal::VariadicDynCastAllOfMatcher< Decl, FileScopeAsmDecl > fileScopeAsmDecl
AST_MATCHER(VarDecl, isAsm)