dexonsmith created this revision.
dexonsmith added a reviewer: erik.pilkington.
Herald added a subscriber: ributzka.
dexonsmith requested review of this revision.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D93249

Files:
  clang/lib/Frontend/CompilerInstance.cpp
  clang/unittests/Frontend/OutputStreamTest.cpp


Index: clang/unittests/Frontend/OutputStreamTest.cpp
===================================================================
--- clang/unittests/Frontend/OutputStreamTest.cpp
+++ clang/unittests/Frontend/OutputStreamTest.cpp
@@ -101,4 +101,12 @@
   EXPECT_TRUE(StringRef(VerboseBuffer.data()).contains("errors generated"));
 }
 
+TEST(FrontendOutputTests, TestVerboseOutputStreamOwnedNotLeaked) {
+  CompilerInstance Compiler;
+  Compiler.setVerboseOutputStream(std::make_unique<raw_null_ostream>());
+
+  // Trust leak sanitizer bots to catch a leak here.
+  Compiler.setVerboseOutputStream(llvm::nulls());
+}
+
 } // anonymous namespace
Index: clang/lib/Frontend/CompilerInstance.cpp
===================================================================
--- clang/lib/Frontend/CompilerInstance.cpp
+++ clang/lib/Frontend/CompilerInstance.cpp
@@ -85,7 +85,7 @@
 }
 
 void CompilerInstance::setVerboseOutputStream(raw_ostream &Value) {
-  OwnedVerboseOutputStream.release();
+  OwnedVerboseOutputStream.reset();
   VerboseOutputStream = &Value;
 }
 


Index: clang/unittests/Frontend/OutputStreamTest.cpp
===================================================================
--- clang/unittests/Frontend/OutputStreamTest.cpp
+++ clang/unittests/Frontend/OutputStreamTest.cpp
@@ -101,4 +101,12 @@
   EXPECT_TRUE(StringRef(VerboseBuffer.data()).contains("errors generated"));
 }
 
+TEST(FrontendOutputTests, TestVerboseOutputStreamOwnedNotLeaked) {
+  CompilerInstance Compiler;
+  Compiler.setVerboseOutputStream(std::make_unique<raw_null_ostream>());
+
+  // Trust leak sanitizer bots to catch a leak here.
+  Compiler.setVerboseOutputStream(llvm::nulls());
+}
+
 } // anonymous namespace
Index: clang/lib/Frontend/CompilerInstance.cpp
===================================================================
--- clang/lib/Frontend/CompilerInstance.cpp
+++ clang/lib/Frontend/CompilerInstance.cpp
@@ -85,7 +85,7 @@
 }
 
 void CompilerInstance::setVerboseOutputStream(raw_ostream &Value) {
-  OwnedVerboseOutputStream.release();
+  OwnedVerboseOutputStream.reset();
   VerboseOutputStream = &Value;
 }
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to