[llvm] r327665 - [codeview] Delete FunctionInfo copy ctor and move out of DenseMap
Reid Kleckner via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 15 14:12:21 PDT 2018
Author: rnk
Date: Thu Mar 15 14:12:21 2018
New Revision: 327665
URL: http://llvm.org/viewvc/llvm-project?rev=327665&view=rev
Log:
[codeview] Delete FunctionInfo copy ctor and move out of DenseMap
We were unnecessarily copying a bunch of these FunctionInfo objects
around when rehashing the DenseMap.
Furthermore, r327620 introduced pointers referring to objects owned by
FunctionInfo, and the default copy ctor did the wrong thing in this
case, leading to use-after-free when the DenseMap gets rehashed.
I will rebase r327620 on this next and recommit it.
Modified:
llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.h
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp?rev=327665&r1=327664&r2=327665&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp Thu Mar 15 14:12:21 2018
@@ -470,7 +470,7 @@ void CodeViewDebug::endModule() {
// Emit per-function debug information.
for (auto &P : FnDebugInfo)
if (!P.first->isDeclarationForLinker())
- emitDebugInfoForFunction(P.first, P.second);
+ emitDebugInfoForFunction(P.first, *P.second);
// Emit global variable debug information.
setCurrentSubprogram(nullptr);
@@ -1162,8 +1162,9 @@ void CodeViewDebug::collectVariableInfo(
void CodeViewDebug::beginFunctionImpl(const MachineFunction *MF) {
const Function &GV = MF->getFunction();
- assert(FnDebugInfo.count(&GV) == false);
- CurFn = &FnDebugInfo[&GV];
+ auto Insertion = FnDebugInfo.insert({&GV, llvm::make_unique<FunctionInfo>()});
+ assert(!Insertion.second && "emitting function twice");
+ CurFn = Insertion.first->second.get();
CurFn->FuncId = NextFuncId++;
CurFn->Begin = Asm->getFunctionBegin();
@@ -2365,7 +2366,7 @@ void CodeViewDebug::emitLocalVariable(co
void CodeViewDebug::endFunctionImpl(const MachineFunction *MF) {
const Function &GV = MF->getFunction();
assert(FnDebugInfo.count(&GV));
- assert(CurFn == &FnDebugInfo[&GV]);
+ assert(CurFn == FnDebugInfo[&GV].get());
collectVariableInfo(GV.getSubprogram());
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.h?rev=327665&r1=327664&r2=327665&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.h (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.h Thu Mar 15 14:12:21 2018
@@ -110,6 +110,11 @@ class LLVM_LIBRARY_VISIBILITY CodeViewDe
// For each function, store a vector of labels to its instructions, as well as
// to the end of the function.
struct FunctionInfo {
+ FunctionInfo() = default;
+
+ // Uncopyable.
+ FunctionInfo(const FunctionInfo &FI) = delete;
+
/// Map from inlined call site to inlined instructions and child inlined
/// call sites. Listed in program order.
std::unordered_map<const DILocation *, InlineSite> InlineSites;
@@ -159,7 +164,7 @@ class LLVM_LIBRARY_VISIBILITY CodeViewDe
/// Remember some debug info about each function. Keep it in a stable order to
/// emit at the end of the TU.
- MapVector<const Function *, FunctionInfo> FnDebugInfo;
+ MapVector<const Function *, std::unique_ptr<FunctionInfo>> FnDebugInfo;
/// Map from full file path to .cv_file id. Full paths are built from DIFiles
/// and are stored in FileToFilepathMap;
More information about the llvm-commits
mailing list