[clang] cbae0d8 - BugReporter::StrBugTypes: Use unique_ptr to simplify memory management
David Blaikie via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 28 22:39:08 PDT 2020
Author: David Blaikie
Date: 2020-04-28T22:31:16-07:00
New Revision: cbae0d8221c7a5de229913754d4a6bf562a7db67
URL: https://github.com/llvm/llvm-project/commit/cbae0d8221c7a5de229913754d4a6bf562a7db67
DIFF: https://github.com/llvm/llvm-project/commit/cbae0d8221c7a5de229913754d4a6bf562a7db67.diff
LOG: BugReporter::StrBugTypes: Use unique_ptr to simplify memory management
Added:
Modified:
clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
clang/lib/StaticAnalyzer/Core/BugReporter.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
index d45c4b71e780..51565524db1e 100644
--- a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
+++ b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
@@ -589,7 +589,7 @@ class BugReporter {
std::vector<BugReportEquivClass *> EQClassesVector;
public:
- BugReporter(BugReporterData &d) : D(d) {}
+ BugReporter(BugReporterData &d);
virtual ~BugReporter();
/// Generate and flush diagnostics for all bug reports.
@@ -632,7 +632,7 @@ class BugReporter {
ArrayRef<FixItHint> Fixits = None);
private:
- llvm::StringMap<BugType *> StrBugTypes;
+ llvm::StringMap<std::unique_ptr<BugType>> StrBugTypes;
/// Returns a BugType that is associated with the given name and
/// category.
diff --git a/clang/lib/StaticAnalyzer/Core/BugReporter.cpp b/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
index 0848d6a6ec61..efae511da83b 100644
--- a/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -2390,6 +2390,7 @@ ProgramStateManager &PathSensitiveBugReporter::getStateManager() const {
return Eng.getStateManager();
}
+BugReporter::BugReporter(BugReporterData &d) : D(d) {}
BugReporter::~BugReporter() {
// Make sure reports are flushed.
assert(StrBugTypes.empty() &&
@@ -2410,7 +2411,7 @@ void BugReporter::FlushReports() {
// EmitBasicReport.
// FIXME: There are leaks from checkers that assume that the BugTypes they
// create will be destroyed by the BugReporter.
- llvm::DeleteContainerSeconds(StrBugTypes);
+ StrBugTypes.clear();
}
//===----------------------------------------------------------------------===//
@@ -3263,8 +3264,8 @@ BugType *BugReporter::getBugTypeForName(CheckerNameRef CheckName,
SmallString<136> fullDesc;
llvm::raw_svector_ostream(fullDesc) << CheckName.getName() << ":" << name
<< ":" << category;
- BugType *&BT = StrBugTypes[fullDesc];
+ std::unique_ptr<BugType> &BT = StrBugTypes[fullDesc];
if (!BT)
- BT = new BugType(CheckName, name, category);
- return BT;
+ BT = std::make_unique<BugType>(CheckName, name, category);
+ return BT.get();
}
More information about the cfe-commits
mailing list