aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/clang/lib/StaticAnalyzer/Checkers/PointerArithChecker.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/clang/lib/StaticAnalyzer/Checkers/PointerArithChecker.cpp')
-rw-r--r--contrib/llvm-project/clang/lib/StaticAnalyzer/Checkers/PointerArithChecker.cpp36
1 files changed, 15 insertions, 21 deletions
diff --git a/contrib/llvm-project/clang/lib/StaticAnalyzer/Checkers/PointerArithChecker.cpp b/contrib/llvm-project/clang/lib/StaticAnalyzer/Checkers/PointerArithChecker.cpp
index d3e2849a0ce6..1141f07428b4 100644
--- a/contrib/llvm-project/clang/lib/StaticAnalyzer/Checkers/PointerArithChecker.cpp
+++ b/contrib/llvm-project/clang/lib/StaticAnalyzer/Checkers/PointerArithChecker.cpp
@@ -11,13 +11,14 @@
//
//===----------------------------------------------------------------------===//
-#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/ExprCXX.h"
+#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
#include "clang/StaticAnalyzer/Core/Checker.h"
#include "clang/StaticAnalyzer/Core/CheckerManager.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+#include "llvm/ADT/StringRef.h"
using namespace clang;
using namespace ento;
@@ -55,8 +56,8 @@ class PointerArithChecker
bool PointedNeeded = false) const;
void initAllocIdentifiers(ASTContext &C) const;
- mutable std::unique_ptr<BuiltinBug> BT_pointerArith;
- mutable std::unique_ptr<BuiltinBug> BT_polyArray;
+ const BugType BT_pointerArith{this, "Dangerous pointer arithmetic"};
+ const BugType BT_polyArray{this, "Dangerous pointer arithmetic"};
mutable llvm::SmallSet<IdentifierInfo *, 8> AllocFunctions;
public:
@@ -79,10 +80,9 @@ void PointerArithChecker::checkDeadSymbols(SymbolReaper &SR,
// see http://reviews.llvm.org/D14203 for further information.
/*ProgramStateRef State = C.getState();
RegionStateTy RegionStates = State->get<RegionState>();
- for (RegionStateTy::iterator I = RegionStates.begin(), E = RegionStates.end();
- I != E; ++I) {
- if (!SR.isLiveRegion(I->first))
- State = State->remove<RegionState>(I->first);
+ for (const MemRegion *Reg: llvm::make_first_range(RegionStates)) {
+ if (!SR.isLiveRegion(Reg))
+ State = State->remove<RegionState>(Reg);
}
C.addTransition(State);*/
}
@@ -168,13 +168,10 @@ void PointerArithChecker::reportPointerArithMisuse(const Expr *E,
if (!IsPolymorphic)
return;
if (ExplodedNode *N = C.generateNonFatalErrorNode()) {
- if (!BT_polyArray)
- BT_polyArray.reset(new BuiltinBug(
- this, "Dangerous pointer arithmetic",
- "Pointer arithmetic on a pointer to base class is dangerous "
- "because derived and base class may have different size."));
- auto R = std::make_unique<PathSensitiveBugReport>(
- *BT_polyArray, BT_polyArray->getDescription(), N);
+ constexpr llvm::StringLiteral Msg =
+ "Pointer arithmetic on a pointer to base class is dangerous "
+ "because derived and base class may have different size.";
+ auto R = std::make_unique<PathSensitiveBugReport>(BT_polyArray, Msg, N);
R->addRange(E->getSourceRange());
R->markInteresting(ArrayRegion);
C.emitReport(std::move(R));
@@ -191,13 +188,10 @@ void PointerArithChecker::reportPointerArithMisuse(const Expr *E,
return;
if (ExplodedNode *N = C.generateNonFatalErrorNode()) {
- if (!BT_pointerArith)
- BT_pointerArith.reset(new BuiltinBug(this, "Dangerous pointer arithmetic",
- "Pointer arithmetic on non-array "
- "variables relies on memory layout, "
- "which is dangerous."));
- auto R = std::make_unique<PathSensitiveBugReport>(
- *BT_pointerArith, BT_pointerArith->getDescription(), N);
+ constexpr llvm::StringLiteral Msg =
+ "Pointer arithmetic on non-array variables relies on memory layout, "
+ "which is dangerous.";
+ auto R = std::make_unique<PathSensitiveBugReport>(BT_pointerArith, Msg, N);
R->addRange(SR);
R->markInteresting(Region);
C.emitReport(std::move(R));