[llvm] r315080 - [MC] Use unique_ptr to manage WinFrameInfos, NFC
Reid Kleckner via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 6 10:21:50 PDT 2017
Author: rnk
Date: Fri Oct 6 10:21:49 2017
New Revision: 315080
URL: http://llvm.org/viewvc/llvm-project?rev=315080&view=rev
Log:
[MC] Use unique_ptr to manage WinFrameInfos, NFC
The FrameInfo cannot be stored directly in the vector because chained
frames may refer to parent frames, so we need pointers that are stable
across a vector resize.
Modified:
llvm/trunk/include/llvm/MC/MCStreamer.h
llvm/trunk/lib/MC/MCStreamer.cpp
llvm/trunk/lib/MC/MCWin64EH.cpp
Modified: llvm/trunk/include/llvm/MC/MCStreamer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCStreamer.h?rev=315080&r1=315079&r2=315080&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCStreamer.h (original)
+++ llvm/trunk/include/llvm/MC/MCStreamer.h Fri Oct 6 10:21:49 2017
@@ -176,7 +176,10 @@ class MCStreamer {
MCSymbol *EmitCFILabel();
MCSymbol *EmitCFICommon();
- std::vector<WinEH::FrameInfo *> WinFrameInfos;
+ /// Similar to DwarfFrameInfos, but for SEH unwind info. Chained frames may
+ /// refer to each other, so use std::unique_ptr to provide pointer stability.
+ std::vector<std::unique_ptr<WinEH::FrameInfo>> WinFrameInfos;
+
WinEH::FrameInfo *CurrentWinFrameInfo;
void EnsureValidWinFrameInfo();
@@ -238,7 +241,7 @@ public:
bool hasUnfinishedDwarfFrameInfo();
unsigned getNumWinFrameInfos() { return WinFrameInfos.size(); }
- ArrayRef<WinEH::FrameInfo *> getWinFrameInfos() const {
+ ArrayRef<std::unique_ptr<WinEH::FrameInfo>> getWinFrameInfos() const {
return WinFrameInfos;
}
Modified: llvm/trunk/lib/MC/MCStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCStreamer.cpp?rev=315080&r1=315079&r2=315080&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCStreamer.cpp Fri Oct 6 10:21:49 2017
@@ -56,17 +56,12 @@ MCStreamer::MCStreamer(MCContext &Ctx)
SectionStack.push_back(std::pair<MCSectionSubPair, MCSectionSubPair>());
}
-MCStreamer::~MCStreamer() {
- for (unsigned i = 0; i < getNumWinFrameInfos(); ++i)
- delete WinFrameInfos[i];
-}
+MCStreamer::~MCStreamer() {}
void MCStreamer::reset() {
DwarfFrameInfos.clear();
- for (unsigned i = 0; i < getNumWinFrameInfos(); ++i)
- delete WinFrameInfos[i];
- WinFrameInfos.clear();
CurrentWinFrameInfo = nullptr;
+ WinFrameInfos.clear();
SymbolOrdering.clear();
SectionStack.clear();
SectionStack.push_back(std::pair<MCSectionSubPair, MCSectionSubPair>());
@@ -538,8 +533,9 @@ void MCStreamer::EmitWinCFIStartProc(con
MCSymbol *StartProc = EmitCFILabel();
- WinFrameInfos.push_back(new WinEH::FrameInfo(Symbol, StartProc));
- CurrentWinFrameInfo = WinFrameInfos.back();
+ WinFrameInfos.emplace_back(
+ llvm::make_unique<WinEH::FrameInfo>(Symbol, StartProc));
+ CurrentWinFrameInfo = WinFrameInfos.back().get();
CurrentWinFrameInfo->TextSection = getCurrentSectionOnly();
}
@@ -557,9 +553,9 @@ void MCStreamer::EmitWinCFIStartChained(
MCSymbol *StartProc = EmitCFILabel();
- WinFrameInfos.push_back(new WinEH::FrameInfo(CurrentWinFrameInfo->Function,
- StartProc, CurrentWinFrameInfo));
- CurrentWinFrameInfo = WinFrameInfos.back();
+ WinFrameInfos.emplace_back(llvm::make_unique<WinEH::FrameInfo>(
+ CurrentWinFrameInfo->Function, StartProc, CurrentWinFrameInfo));
+ CurrentWinFrameInfo = WinFrameInfos.back().get();
CurrentWinFrameInfo->TextSection = getCurrentSectionOnly();
}
Modified: llvm/trunk/lib/MC/MCWin64EH.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCWin64EH.cpp?rev=315080&r1=315079&r2=315080&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCWin64EH.cpp (original)
+++ llvm/trunk/lib/MC/MCWin64EH.cpp Fri Oct 6 10:21:49 2017
@@ -220,17 +220,17 @@ static void EmitUnwindInfo(MCStreamer &s
void llvm::Win64EH::UnwindEmitter::Emit(MCStreamer &Streamer) const {
// Emit the unwind info structs first.
- for (WinEH::FrameInfo *CFI : Streamer.getWinFrameInfos()) {
+ for (const auto &CFI : Streamer.getWinFrameInfos()) {
MCSection *XData = Streamer.getAssociatedXDataSection(CFI->TextSection);
Streamer.SwitchSection(XData);
- ::EmitUnwindInfo(Streamer, CFI);
+ ::EmitUnwindInfo(Streamer, CFI.get());
}
// Now emit RUNTIME_FUNCTION entries.
- for (WinEH::FrameInfo *CFI : Streamer.getWinFrameInfos()) {
+ for (const auto &CFI : Streamer.getWinFrameInfos()) {
MCSection *PData = Streamer.getAssociatedPDataSection(CFI->TextSection);
Streamer.SwitchSection(PData);
- EmitRuntimeFunction(Streamer, CFI);
+ EmitRuntimeFunction(Streamer, CFI.get());
}
}
More information about the llvm-commits
mailing list