10 #include "clang/AST/ASTContext.h" 11 #include "clang/ASTMatchers/ASTMatchFinder.h" 12 #include "clang/Frontend/CompilerInstance.h" 13 #include "clang/Lex/PPCallbacks.h" 14 #include "clang/Lex/Preprocessor.h" 23 const char DiagWording[] =
24 "do not call %0; consider using exception handling instead";
26 class SetJmpMacroCallbacks :
public PPCallbacks {
27 SetLongJmpCheck &Check;
30 explicit SetJmpMacroCallbacks(SetLongJmpCheck &Check) : Check(Check) {}
32 void MacroExpands(
const Token &MacroNameTok,
const MacroDefinition &
MD,
33 SourceRange
Range,
const MacroArgs *Args)
override {
34 const auto *II = MacroNameTok.getIdentifierInfo();
38 if (II->getName() ==
"setjmp")
39 Check.diag(Range.getBegin(), DiagWording) << II;
44 void SetLongJmpCheck::registerPPCallbacks(
const SourceManager &SM,
46 Preprocessor *ModuleExpanderPP) {
49 if (!getLangOpts().CPlusPlus)
54 PP->addPPCallbacks(llvm::make_unique<SetJmpMacroCallbacks>(*
this));
57 void SetLongJmpCheck::registerMatchers(MatchFinder *Finder) {
60 if (!getLangOpts().CPlusPlus)
67 callExpr(callee(functionDecl(hasAnyName(
"setjmp",
"longjmp"))))
72 void SetLongJmpCheck::check(
const MatchFinder::MatchResult &
Result) {
73 const auto *E = Result.Nodes.getNodeAs<CallExpr>(
"expr");
74 diag(E->getExprLoc(), DiagWording) << cast<NamedDecl>(E->getCalleeDecl());
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
static GeneratorRegistry::Add< MDGenerator > MD(MDGenerator::Format, "Generator for MD output.")
CharSourceRange Range
SourceRange for the file name.
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result