From: Benjamin Kramer Date: Fri, 9 Dec 2016 13:33:41 +0000 (+0000) Subject: Plug another leak in the DWARF unittests, DIEInlineStrings are never destroyed. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=366c08a1269394c847b48984e7445d062d0dad54;p=llvm Plug another leak in the DWARF unittests, DIEInlineStrings are never destroyed. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289208 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/CodeGen/DIE.h b/include/llvm/CodeGen/DIE.h index f1d7ecbfbf5..1e3476cd839 100644 --- a/include/llvm/CodeGen/DIE.h +++ b/include/llvm/CodeGen/DIE.h @@ -256,15 +256,16 @@ public: /// /// This class is used with the DW_FORM_string form. class DIEInlineString { - std::string S; + StringRef S; public: - explicit DIEInlineString(StringRef Str) : S(Str.str()) {} + template + explicit DIEInlineString(StringRef Str, Allocator &A) : S(Str.copy(A)) {} ~DIEInlineString() = default; /// Grab the string out of the object. - StringRef getString() const { return StringRef(S); } + StringRef getString() const { return S; } void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const; unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const; diff --git a/lib/CodeGen/AsmPrinter/DIE.cpp b/lib/CodeGen/AsmPrinter/DIE.cpp index 3fbb52f1380..622e4dc9258 100644 --- a/lib/CodeGen/AsmPrinter/DIE.cpp +++ b/lib/CodeGen/AsmPrinter/DIE.cpp @@ -606,7 +606,7 @@ unsigned DIEInlineString::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const { LLVM_DUMP_METHOD void DIEInlineString::print(raw_ostream &O) const { - O << "InlineString: " << S.c_str(); + O << "InlineString: " << S; } //===----------------------------------------------------------------------===// diff --git a/unittests/DebugInfo/DWARF/DwarfGenerator.cpp b/unittests/DebugInfo/DWARF/DwarfGenerator.cpp index 7510bc5415e..5640cece4ea 100644 --- a/unittests/DebugInfo/DWARF/DwarfGenerator.cpp +++ b/unittests/DebugInfo/DWARF/DwarfGenerator.cpp @@ -61,7 +61,8 @@ void dwarfgen::DIE::addAttribute(uint16_t A, dwarf::Form Form, auto &DG = CU->getGenerator(); if (Form == DW_FORM_string) { Die->addValue(DG.getAllocator(), static_cast(A), Form, - new (DG.getAllocator()) DIEInlineString(String)); + new (DG.getAllocator()) + DIEInlineString(String, DG.getAllocator())); } else { Die->addValue( DG.getAllocator(), static_cast(A), Form,