mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-19 04:32:19 +00:00
Fix memory leak of MCSymbolData in MCAsmStreamer.
Leak identified by LSan and reported by Kostya Serebryany. Let's get a bit experimental here... in theory our minimum compiler versions support unordered_map. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207118 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
a05d37e1f4
commit
344569a651
@ -9,6 +9,7 @@
|
||||
|
||||
#include "llvm/MC/MCStreamer.h"
|
||||
#include "llvm/ADT/SmallString.h"
|
||||
#include "llvm/ADT/STLExtras.h"
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
#include "llvm/ADT/Twine.h"
|
||||
#include "llvm/MC/MCAsmBackend.h"
|
||||
@ -31,6 +32,7 @@
|
||||
#include "llvm/Support/MathExtras.h"
|
||||
#include "llvm/Support/Path.h"
|
||||
#include <cctype>
|
||||
#include <unordered_map>
|
||||
using namespace llvm;
|
||||
|
||||
namespace {
|
||||
@ -57,7 +59,9 @@ private:
|
||||
EHPrivateExtern = 1 << 2 };
|
||||
DenseMap<const MCSymbol*, unsigned> FlagMap;
|
||||
|
||||
DenseMap<const MCSymbol*, MCSymbolData*> SymbolMap;
|
||||
// Using std::unordered_map to ensure pointers to MCSymbolData remain valid
|
||||
// over insertions/removals from the SymbolMap.
|
||||
std::unordered_map<const MCSymbol*, MCSymbolData> SymbolMap;
|
||||
|
||||
void EmitRegisterName(int64_t Register);
|
||||
void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame) override;
|
||||
@ -76,7 +80,6 @@ public:
|
||||
if (InstPrinter && IsVerboseAsm)
|
||||
InstPrinter->setCommentStream(CommentStream);
|
||||
}
|
||||
~MCAsmStreamer() {}
|
||||
|
||||
inline void EmitEOL() {
|
||||
// If we don't have any comments, just emit a \n.
|
||||
@ -1470,12 +1473,11 @@ void MCAsmStreamer::FinishImpl() {
|
||||
}
|
||||
|
||||
MCSymbolData &MCAsmStreamer::getOrCreateSymbolData(const MCSymbol *Symbol) {
|
||||
MCSymbolData *&Entry = SymbolMap[Symbol];
|
||||
|
||||
if (!Entry)
|
||||
Entry = new MCSymbolData(*Symbol, nullptr, 0, nullptr);
|
||||
|
||||
return *Entry;
|
||||
auto Iter = SymbolMap.find(Symbol);
|
||||
if (Iter == SymbolMap.end())
|
||||
Iter = SymbolMap.insert(
|
||||
Iter, std::make_pair(Symbol, MCSymbolData(*Symbol, nullptr, 0)));
|
||||
return Iter->second;
|
||||
}
|
||||
|
||||
MCStreamer *llvm::createAsmStreamer(MCContext &Context,
|
||||
|
Loading…
x
Reference in New Issue
Block a user