[clang] Adding optin.taint.TaintedDiv checker (PR #106389)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 28 06:48:06 PDT 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff c992690179eb5de6efe47d5c8f3a23f2302723f2 adf8f04eac4ff6e71c985bb991f68c2238a3462f --extensions cpp,c,h -- clang/include/clang/StaticAnalyzer/Core/CheckerManager.h clang/lib/StaticAnalyzer/Checkers/DivZeroChecker.cpp clang/test/Analysis/taint-diagnostic-visitor.c clang/test/Analysis/taint-generic.c
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h b/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
index e900ef0c17..e47c0c310e 100644
--- a/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
+++ b/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
@@ -223,9 +223,7 @@ public:
return static_cast<CHECKER *>(CheckerTags[tag]);
}
-
- template <typename CHECKER>
- bool isRegisteredChecker() {
+ template <typename CHECKER> bool isRegisteredChecker() {
CheckerTag tag = getTag<CHECKER>();
return (CheckerTags.count(tag) != 0);
}
diff --git a/clang/lib/StaticAnalyzer/Checkers/DivZeroChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/DivZeroChecker.cpp
index 60e06ad699..da160f1330 100644
--- a/clang/lib/StaticAnalyzer/Checkers/DivZeroChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/DivZeroChecker.cpp
@@ -25,7 +25,7 @@ using namespace ento;
using namespace taint;
namespace {
-class DivZeroChecker : public Checker< check::PreStmt<BinaryOperator> > {
+class DivZeroChecker : public Checker<check::PreStmt<BinaryOperator>> {
void reportBug(StringRef Msg, ProgramStateRef StateZero,
CheckerContext &C) const;
void reportTaintBug(StringRef Msg, ProgramStateRef StateZero,
@@ -34,11 +34,7 @@ class DivZeroChecker : public Checker< check::PreStmt<BinaryOperator> > {
public:
/// This checker class implements multiple user facing checker
- enum CheckKind {
- CK_DivZeroChecker,
- CK_TaintedDivChecker,
- CK_NumCheckKinds
- };
+ enum CheckKind { CK_DivZeroChecker, CK_TaintedDivChecker, CK_NumCheckKinds };
bool ChecksEnabled[CK_NumCheckKinds] = {false};
CheckerNameRef CheckNames[CK_NumCheckKinds];
mutable std::unique_ptr<BugType> BugTypes[CK_NumCheckKinds];
@@ -59,11 +55,11 @@ void DivZeroChecker::reportBug(StringRef Msg, ProgramStateRef StateZero,
if (!ChecksEnabled[CK_DivZeroChecker])
return;
if (!BugTypes[CK_DivZeroChecker])
- BugTypes[CK_DivZeroChecker].reset(new BugType(
- CheckNames[CK_DivZeroChecker],
- "Division by zero"));
+ BugTypes[CK_DivZeroChecker].reset(
+ new BugType(CheckNames[CK_DivZeroChecker], "Division by zero"));
if (ExplodedNode *N = C.generateErrorNode(StateZero)) {
- auto R = std::make_unique<PathSensitiveBugReport>(*BugTypes[CK_DivZeroChecker], Msg, N);
+ auto R = std::make_unique<PathSensitiveBugReport>(
+ *BugTypes[CK_DivZeroChecker], Msg, N);
bugreporter::trackExpressionValue(N, getDenomExpr(N), *R);
C.emitReport(std::move(R));
}
@@ -75,10 +71,9 @@ void DivZeroChecker::reportTaintBug(
if (!ChecksEnabled[CK_TaintedDivChecker])
return;
if (!BugTypes[CK_TaintedDivChecker])
- BugTypes[CK_TaintedDivChecker].reset(new BugType(
- CheckNames[CK_TaintedDivChecker],
- "Division by zero",
- categories::TaintedData));
+ BugTypes[CK_TaintedDivChecker].reset(
+ new BugType(CheckNames[CK_TaintedDivChecker], "Division by zero",
+ categories::TaintedData));
if (ExplodedNode *N = C.generateErrorNode(StateZero)) {
auto R = std::make_unique<PathSensitiveBugReport>(
*BugTypes[CK_TaintedDivChecker], Msg, N);
@@ -135,10 +130,11 @@ void DivZeroChecker::checkPreStmt(const BinaryOperator *B,
}
void ento::registerDivZeroChecker(CheckerManager &mgr) {
- DivZeroChecker *checker = mgr.registerChecker<DivZeroChecker>();;
+ DivZeroChecker *checker = mgr.registerChecker<DivZeroChecker>();
+ ;
checker->ChecksEnabled[DivZeroChecker::CK_DivZeroChecker] = true;
checker->CheckNames[DivZeroChecker::CK_DivZeroChecker] =
- mgr.getCurrentCheckerName();
+ mgr.getCurrentCheckerName();
}
bool ento::shouldRegisterDivZeroChecker(const CheckerManager &mgr) {
@@ -148,12 +144,12 @@ bool ento::shouldRegisterDivZeroChecker(const CheckerManager &mgr) {
void ento::registerTaintedDivChecker(CheckerManager &mgr) {
DivZeroChecker *checker;
if (!mgr.isRegisteredChecker<DivZeroChecker>())
- checker = mgr.registerChecker<DivZeroChecker>();
+ checker = mgr.registerChecker<DivZeroChecker>();
else
checker = mgr.getChecker<DivZeroChecker>();
checker->ChecksEnabled[DivZeroChecker::CK_TaintedDivChecker] = true;
checker->CheckNames[DivZeroChecker::CK_TaintedDivChecker] =
- mgr.getCurrentCheckerName();
+ mgr.getCurrentCheckerName();
}
bool ento::shouldRegisterTaintedDivChecker(const CheckerManager &mgr) {
``````````
</details>
https://github.com/llvm/llvm-project/pull/106389
More information about the cfe-commits
mailing list