]> granicus.if.org Git - llvm/commitdiff
Plug another leak in the DWARF unittests, DIEInlineStrings are never destroyed.
authorBenjamin Kramer <benny.kra@googlemail.com>
Fri, 9 Dec 2016 13:33:41 +0000 (13:33 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Fri, 9 Dec 2016 13:33:41 +0000 (13:33 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289208 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/DIE.h
lib/CodeGen/AsmPrinter/DIE.cpp
unittests/DebugInfo/DWARF/DwarfGenerator.cpp

index f1d7ecbfbf5a5d617e7b300e27c98a6cd65e4ad4..1e3476cd83953078a5937876760ab47e60ff0a2b 100644 (file)
@@ -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 <typename Allocator>
+  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;
index 3fbb52f13806493dc35a70bd9a00dfa4e23424f6..622e4dc92586596fd025c063a8cad523a485e892 100644 (file)
@@ -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;
 }
 
 //===----------------------------------------------------------------------===//
index 7510bc5415e62c86d2c3ba31c611d5d20372462a..5640cece4ea3c941fa8505f86e6fc46f39d1ad60 100644 (file)
@@ -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<dwarf::Attribute>(A), Form,
-                  new (DG.getAllocator()) DIEInlineString(String));
+                  new (DG.getAllocator())
+                      DIEInlineString(String, DG.getAllocator()));
   } else {
     Die->addValue(
         DG.getAllocator(), static_cast<dwarf::Attribute>(A), Form,