ソースを参照

Fix leak from r210059

Also revert r210096 which temporarily disabled the test while this was being
investigated.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@210115 91177308-0d34-0410-b5e6-96231b3b80d8
Alp Toker 11 年 前
コミット
b830eaf3e0

+ 2 - 0
include/clang/Frontend/CompilerInstance.h

@@ -663,6 +663,8 @@ public:
                    std::string *ResultPathName,
                    std::string *TempPathName);
 
+  llvm::raw_null_ostream *createNullOutputFile();
+
   /// }
   /// @name Initialization Utility Methods
   /// {

+ 1 - 1
lib/CodeGen/CodeGenAction.cpp

@@ -568,7 +568,7 @@ static raw_ostream *GetOutputStream(CompilerInstance &CI,
   case Backend_EmitNothing:
     return nullptr;
   case Backend_EmitMCNull:
-    return new raw_null_ostream();
+    return CI.createNullOutputFile();
   case Backend_EmitObj:
     return CI.createDefaultOutputFile(true, InFile, "o");
   }

+ 6 - 0
lib/Frontend/CompilerInstance.cpp

@@ -478,6 +478,12 @@ CompilerInstance::createDefaultOutputFile(bool Binary,
                           /*UseTemporary=*/true);
 }
 
+llvm::raw_null_ostream *CompilerInstance::createNullOutputFile() {
+  llvm::raw_null_ostream *OS = new llvm::raw_null_ostream();
+  addOutputFile(OutputFile("", "", OS));
+  return OS;
+}
+
 llvm::raw_fd_ostream *
 CompilerInstance::createOutputFile(StringRef OutputPath,
                                    bool Binary, bool RemoveFileOnSignal,

+ 2 - 3
test/Frontend/disable-output.c

@@ -1,8 +1,7 @@
-// FIXME: this test produces a leak report in clang.
 // REQUIRES: x86-registered-target
 // RUN: %clang_cc1 %s -emit-llvm-only -triple=i386-apple-darwin -o %t
 // RUN: not rm %t
-// FIXME: %clang_cc1 %s -emit-codegen-only -triple=i386-apple-darwin -o %t
-// FIXME: not rm %t
+// RUN: %clang_cc1 %s -emit-codegen-only -triple=i386-apple-darwin -o %t
+// RUN: not rm %t
 
 // Test that output is not generated when emission is disabled.