brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · e7d97b2 Raw
38 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "NoAssemblerCheck.h"10#include "clang/ASTMatchers/ASTMatchFinder.h"11 12using namespace clang::ast_matchers;13 14namespace clang::tidy::hicpp {15 16void NoAssemblerCheck::registerMatchers(MatchFinder *Finder) {17  Finder->addMatcher(asmStmt().bind("asm-stmt"), this);18  Finder->addMatcher(fileScopeAsmDecl().bind("asm-file-scope"), this);19  Finder->addMatcher(varDecl(hasAttr(attr::AsmLabel)).bind("asm-var"), this);20}21 22void NoAssemblerCheck::check(const MatchFinder::MatchResult &Result) {23  SourceLocation ASMLocation;24  if (const auto *ASM = Result.Nodes.getNodeAs<AsmStmt>("asm-stmt"))25    ASMLocation = ASM->getAsmLoc();26  else if (const auto *ASM =27               Result.Nodes.getNodeAs<FileScopeAsmDecl>("asm-file-scope"))28    ASMLocation = ASM->getAsmLoc();29  else if (const auto *ASM = Result.Nodes.getNodeAs<VarDecl>("asm-var"))30    ASMLocation = ASM->getLocation();31  else32    llvm_unreachable("Unhandled case in matcher.");33 34  diag(ASMLocation, "do not use inline assembler in safety-critical code");35}36 37} // namespace clang::tidy::hicpp38