Skip to content

Commit 268ead1

Browse files
rafaelaulermemfrob
authored andcommitted
[BOLT] Fix ASAN bugs
Summary: Fix a leak in DEBUGRewriter.cpp and an address out of bounds issue in edit distance calculation. (cherry picked from FBD6290026)
1 parent 6046d1d commit 268ead1

File tree

3 files changed

+8
-31
lines changed

3 files changed

+8
-31
lines changed

bolt/BinaryFunction.cpp

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "BinaryFunction.h"
1515
#include "DataReader.h"
1616
#include "Passes/MCF.h"
17+
#include "llvm/ADT/edit_distance.h"
1718
#include "llvm/ADT/StringRef.h"
1819
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
1920
#include "llvm/MC/MCAsmInfo.h"
@@ -2510,32 +2511,8 @@ bool BinaryFunction::hasLayoutChanged() const {
25102511
}
25112512

25122513
uint64_t BinaryFunction::getEditDistance() const {
2513-
const auto LayoutSize = BasicBlocksPreviousLayout.size();
2514-
if (LayoutSize < 2) {
2515-
return 0;
2516-
}
2517-
2518-
std::vector<std::vector<uint64_t>> ChangeMatrix(
2519-
LayoutSize + 1, std::vector<uint64_t>(LayoutSize + 1));
2520-
2521-
for (uint64_t I = 0; I <= LayoutSize; ++I) {
2522-
ChangeMatrix[I][0] = I;
2523-
ChangeMatrix[0][I] = I;
2524-
}
2525-
2526-
for (uint64_t I = 1; I <= LayoutSize; ++I) {
2527-
for (uint64_t J = 1; J <= LayoutSize; ++J) {
2528-
if (BasicBlocksPreviousLayout[I] != BasicBlocksLayout[J]) {
2529-
ChangeMatrix[I][J] =
2530-
std::min(std::min(ChangeMatrix[I - 1][J], ChangeMatrix[I][J - 1]),
2531-
ChangeMatrix[I - 1][J - 1]) + 1;
2532-
} else {
2533-
ChangeMatrix[I][J] = ChangeMatrix[I - 1][J - 1];
2534-
}
2535-
}
2536-
}
2537-
2538-
return ChangeMatrix[LayoutSize][LayoutSize];
2514+
return ComputeEditDistance<BinaryBasicBlock *>(BasicBlocksPreviousLayout,
2515+
BasicBlocksLayout);
25392516
}
25402517

25412518
void BinaryFunction::emitBody(MCStreamer &Streamer, bool EmitColdPart) {

bolt/DWARFRewriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ void RewriteInstance::updateGdbIndexSection() {
552552

553553
OffsetToIndexMap[Offset] = Index;
554554
}
555-
555+
556556
// Ignore old address table.
557557
const auto OldAddressTableSize = SymbolTableOffset - AddressTableOffset;
558558
Data += OldAddressTableSize;

bolt/DebugData.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ class DebugRangesSectionsWriter {
113113
return CUAddressRanges;
114114
}
115115

116-
SmallVectorImpl<char> *finalize() {
117-
return RangesBuffer.release();
116+
std::unique_ptr<SmallVectorImpl<char>> finalize() {
117+
return std::unique_ptr<SmallVectorImpl<char>>(RangesBuffer.release());
118118
}
119119

120120
private:
@@ -149,8 +149,8 @@ class DebugLocWriter {
149149

150150
uint64_t getEmptyListOffset() const { return EmptyListOffset; }
151151

152-
SmallVectorImpl<char> *finalize() {
153-
return LocBuffer.release();
152+
std::unique_ptr<SmallVectorImpl<char>> finalize() {
153+
return std::unique_ptr<SmallVectorImpl<char>>(LocBuffer.release());
154154
}
155155

156156
private:

0 commit comments

Comments
 (0)