[Flang] remove whole-archive option for AIX linker (#76039)
[llvm-project.git] / clang / lib / Analysis / plugins / SampleAnalyzer / MainCallChecker.cpp
blobfd210d733fd0a9e4d2355749f4968525386b18f3
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"
6 using namespace clang;
7 using namespace ento;
9 namespace {
10 class MainCallChecker : public Checker<check::PreStmt<CallExpr>> {
11 mutable std::unique_ptr<BugType> BT;
13 public:
14 void checkPreStmt(const CallExpr *CE, CheckerContext &C) const;
16 } // end anonymous namespace
18 void MainCallChecker::checkPreStmt(const CallExpr *CE,
19 CheckerContext &C) const {
20 const Expr *Callee = CE->getCallee();
21 const FunctionDecl *FD = C.getSVal(Callee).getAsFunctionDecl();
23 if (!FD)
24 return;
26 // Get the name of the callee.
27 IdentifierInfo *II = FD->getIdentifier();
28 if (!II) // if no identifier, not a simple C function
29 return;
31 if (II->isStr("main")) {
32 ExplodedNode *N = C.generateErrorNode();
33 if (!N)
34 return;
36 if (!BT)
37 BT.reset(new BugType(this, "call to main", "example analyzer plugin"));
39 auto report =
40 std::make_unique<PathSensitiveBugReport>(*BT, BT->getDescription(), N);
41 report->addRange(Callee->getSourceRange());
42 C.emitReport(std::move(report));
46 // Register plugin!
47 extern "C" void clang_registerCheckers(CheckerRegistry &registry) {
48 registry.addChecker<MainCallChecker>(
49 "example.MainCallChecker", "Disallows calls to functions called main",
50 "");
53 extern "C" const char clang_analyzerAPIVersionString[] =
54 CLANG_ANALYZER_API_VERSION_STRING;