Coverage Report

Created: 2020-11-24 06:42

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Analysis/plugins/SampleAnalyzer/MainCallChecker.cpp
Line
Count
Source (jump to first uncovered line)
1
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
2
#include "clang/StaticAnalyzer/Core/Checker.h"
3
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
4
#include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
5
6
using namespace clang;
7
using namespace ento;
8
9
namespace {
10
class MainCallChecker : public Checker<check::PreStmt<CallExpr>> {
11
  mutable std::unique_ptr<BugType> BT;
12
13
public:
14
  void checkPreStmt(const CallExpr *CE, CheckerContext &C) const;
15
};
16
} // end anonymous namespace
17
18
void MainCallChecker::checkPreStmt(const CallExpr *CE,
19
0
                                   CheckerContext &C) const {
20
0
  const Expr *Callee = CE->getCallee();
21
0
  const FunctionDecl *FD = C.getSVal(Callee).getAsFunctionDecl();
22
23
0
  if (!FD)
24
0
    return;
25
26
  // Get the name of the callee.
27
0
  IdentifierInfo *II = FD->getIdentifier();
28
0
  if (!II) // if no identifier, not a simple C function
29
0
    return;
30
31
0
  if (II->isStr("main")) {
32
0
    ExplodedNode *N = C.generateErrorNode();
33
0
    if (!N)
34
0
      return;
35
36
0
    if (!BT)
37
0
      BT.reset(new BugType(this, "call to main", "example analyzer plugin"));
38
39
0
    auto report =
40
0
        std::make_unique<PathSensitiveBugReport>(*BT, BT->getDescription(), N);
41
0
    report->addRange(Callee->getSourceRange());
42
0
    C.emitReport(std::move(report));
43
0
  }
44
0
}
45
46
// Register plugin!
47
0
extern "C" void clang_registerCheckers(CheckerRegistry &registry) {
48
0
  registry.addChecker<MainCallChecker>(
49
0
      "example.MainCallChecker", "Disallows calls to functions called main",
50
0
      "");
51
0
}
52
53
extern "C" const char clang_analyzerAPIVersionString[] =
54
    CLANG_ANALYZER_API_VERSION_STRING;