diff --git a/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp b/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp --- a/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp @@ -372,9 +372,9 @@ if (!AppendNonCUDies) break; // The average bytes per DIE entry has been seen to be - // around 14-20 so let's pre-reserve the needed memory for + // around 6-12 so let's pre-reserve the needed memory for // our DIE entries accordingly. - Dies.reserve(Dies.size() + getDebugInfoSize() / 14); + Dies.reserve(Dies.size() + getDebugInfoSize() / 6); IsCUDie = false; } else { Dies.push_back(DIE); @@ -394,6 +394,8 @@ } } + Dies.shrink_to_fit(); + // Give a little bit of info if we encounter corrupt DWARF (our offset // should always terminate at or before the start of the next compilation // unit header).