10 #include "clang/AST/ASTContext.h" 11 #include "clang/ASTMatchers/ASTMatchFinder.h" 19 void BadSignalToKillThreadCheck::registerMatchers(MatchFinder *Finder) {
21 callExpr(allOf(callee(functionDecl(hasName(
"::pthread_kill"))),
23 hasArgument(1, integerLiteral().bind(
"integer-literal")))
28 static Preprocessor *
PP;
30 void BadSignalToKillThreadCheck::check(
const MatchFinder::MatchResult &Result) {
31 const auto IsSigterm = [](
const auto &KeyValue) ->
bool {
32 return KeyValue.first->getName() ==
"SIGTERM";
34 const auto TryExpandAsInteger =
35 [](Preprocessor::macro_iterator It) -> Optional<unsigned> {
36 if (It == PP->macro_end())
38 const MacroInfo *MI = PP->getMacroInfo(It->first);
39 const Token &T = MI->tokens().back();
40 StringRef ValueStr = StringRef(T.getLiteralData(), T.getLength());
43 constexpr
unsigned AutoSenseRadix = 0;
44 if (ValueStr.getAsInteger(AutoSenseRadix, IntValue))
46 return IntValue.getZExtValue();
49 const auto SigtermMacro = llvm::find_if(PP->macros(), IsSigterm);
51 if (!SigtermValue && !(SigtermValue = TryExpandAsInteger(SigtermMacro)))
54 const auto *MatchedExpr = Result.Nodes.getNodeAs<Expr>(
"thread-kill");
55 const auto *MatchedIntLiteral =
56 Result.Nodes.getNodeAs<IntegerLiteral>(
"integer-literal");
57 if (MatchedIntLiteral->getValue() == *SigtermValue) {
58 diag(MatchedExpr->getBeginLoc(),
59 "thread should not be terminated by raising the 'SIGTERM' signal");
63 void BadSignalToKillThreadCheck::registerPPCallbacks(
64 const SourceManager &SM, Preprocessor *pp, Preprocessor *ModuleExpanderPP) {
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//