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"
21const char DiagWording[] =
22 "do not call %0; consider using exception handling instead";
25 SetLongJmpCheck &Check;
28 explicit SetJmpMacroCallbacks(SetLongJmpCheck &Check) : Check(Check) {}
30 void MacroExpands(
const Token &MacroNameTok,
const MacroDefinition &MD,
31 SourceRange Range,
const MacroArgs *
Args)
override {
32 const auto *II = MacroNameTok.getIdentifierInfo();
36 if (II->getName() ==
"setjmp")
37 Check.diag(
Range.getBegin(), DiagWording) << II;
44 Preprocessor *ModuleExpanderPP) {
47 PP->addPPCallbacks(std::make_unique<SetJmpMacroCallbacks>(*
this));
55 callExpr(callee(functionDecl(hasAnyName(
"setjmp",
"longjmp"))))
61 const auto *
E = Result.Nodes.getNodeAs<CallExpr>(
"expr");
62 diag(
E->getExprLoc(), DiagWording) << cast<NamedDecl>(
E->getCalleeDecl());
CharSourceRange Range
SourceRange for the file name.
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) override
Override this to register PPCallbacks in the preprocessor.