-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimpleChecker.cpp
67 lines (56 loc) · 1.91 KB
/
SimpleChecker.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "clang/StaticAnalyzer/Core/Checker.h"
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
#include "clang/StaticAnalyzer/Frontend/CheckerRegistration.h"
#include "clang/StaticAnalyzer/Core/CheckerRegistry.h"
#include "clang/AST/Decl.h"
using namespace clang;
using namespace ento;
namespace
{
// Rule A3-3-2 (required, implementation, automated)
// Non-POD type objects with static storage duration shall not be used.
class SimpleChecker : public Checker<check::ASTDecl<VarDecl>>
{
private:
std::unique_ptr<BugType> m_bugType{
std::make_unique<BugType>(
this,
"Non-POD type objects with static storage duration shall not be used.",
"Autosar required")};
public:
void checkASTDecl(const VarDecl *varDecl, AnalysisManager &analysisManager, BugReporter &bugReporter) const
{
if (!varDecl)
{
return;
}
const bool isConstexpr = varDecl->isConstexpr();
if (isConstexpr)
{
return;
}
const bool hasStaticStorageDuration = varDecl->isStaticLocal() || varDecl->isStaticDataMember() || varDecl->hasGlobalStorage();
ASTContext &astContext = varDecl->getASTContext();
const bool isPOD = varDecl->getType().isPODType(astContext);
if (hasStaticStorageDuration && !isPOD)
{
PathDiagnosticLocation pathDiagnosticLocation =
PathDiagnosticLocation::create(varDecl, bugReporter.getSourceManager());
bugReporter.emitReport(
std::make_unique<BugReport>(
*m_bugType,
m_bugType->getName(),
pathDiagnosticLocation));
}
}
};
} // namespace
extern "C" void clang_registerCheckers(CheckerRegistry ®istry)
{
registry.addChecker<SimpleChecker>(
"autosar.A3-3-2",
"Non-POD type objects with static storage duration shall not be used.");
}
extern "C" const char clang_analyzerAPIVersionString[] = CLANG_ANALYZER_API_VERSION_STRING;