10#include "clang/AST/ASTContext.h"
11#include "clang/ASTMatchers/ASTMatchFinder.h"
18AST_MATCHER(VarDecl, isAsm) {
return Node.hasAttr<clang::AsmLabelAttr>(); }
19const ast_matchers::internal::VariadicDynCastAllOfMatcher<
Decl,
25 Finder->addMatcher(asmStmt().bind(
"asm-stmt"),
this);
26 Finder->addMatcher(fileScopeAsmDecl().bind(
"asm-file-scope"),
this);
27 Finder->addMatcher(varDecl(isAsm()).bind(
"asm-var"),
this);
31 SourceLocation ASMLocation;
32 if (
const auto *ASM = Result.Nodes.getNodeAs<AsmStmt>(
"asm-stmt"))
33 ASMLocation = ASM->getAsmLoc();
34 else if (
const auto *ASM =
35 Result.Nodes.getNodeAs<FileScopeAsmDecl>(
"asm-file-scope"))
36 ASMLocation = ASM->getAsmLoc();
37 else if (
const auto *ASM = Result.Nodes.getNodeAs<VarDecl>(
"asm-var"))
38 ASMLocation = ASM->getLocation();
40 llvm_unreachable(
"Unhandled case in matcher.");
42 diag(ASMLocation,
"do not use inline assembler in safety-critical code");
const FunctionDecl * Decl
::clang::DynTypedNode Node
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
AST_MATCHER(Decl, declHasNoReturnAttr)
matches a Decl if it has a "no return" attribute of any kind