File tree Expand file tree Collapse file tree 3 files changed +11
-8
lines changed Expand file tree Collapse file tree 3 files changed +11
-8
lines changed Original file line number Diff line number Diff line change @@ -177,9 +177,8 @@ class SyntaxOnlyAction : public ASTFrontendAction {
177
177
// / Dump information about the given module file, to be used for
178
178
// / basic debugging and discovery.
179
179
class DumpModuleInfoAction : public ASTFrontendAction {
180
- public:
181
180
// Allow other tools (ex lldb) to direct output for their use.
182
- llvm::raw_ostream * OutputStream = nullptr ;
181
+ std::shared_ptr< llvm::raw_ostream> OutputStream;
183
182
184
183
protected:
185
184
std::unique_ptr<ASTConsumer> CreateASTConsumer (CompilerInstance &CI,
@@ -188,6 +187,9 @@ class DumpModuleInfoAction : public ASTFrontendAction {
188
187
void ExecuteAction () override ;
189
188
190
189
public:
190
+ DumpModuleInfoAction () = default ;
191
+ explicit DumpModuleInfoAction (std::shared_ptr<llvm::raw_ostream> Out)
192
+ : OutputStream(Out) {}
191
193
bool hasPCHSupport () const override { return false ; }
192
194
bool hasASTFileSupport () const override { return true ; }
193
195
bool hasIRSupport () const override { return false ; }
Original file line number Diff line number Diff line change @@ -780,14 +780,12 @@ static StringRef ModuleKindName(Module::ModuleKind MK) {
780
780
void DumpModuleInfoAction::ExecuteAction () {
781
781
assert (isCurrentFileAST () && " dumping non-AST?" );
782
782
// Set up the output file.
783
- std::unique_ptr<llvm::raw_fd_ostream> OutFile;
784
783
CompilerInstance &CI = getCompilerInstance ();
785
784
StringRef OutputFileName = CI.getFrontendOpts ().OutputFile ;
786
785
if (!OutputFileName.empty () && OutputFileName != " -" ) {
787
786
std::error_code EC;
788
- OutFile.reset (new llvm::raw_fd_ostream (OutputFileName.str (), EC,
789
- llvm::sys::fs::OF_TextWithCRLF));
790
- OutputStream = OutFile.get ();
787
+ OutputStream.reset (new llvm::raw_fd_ostream (
788
+ OutputFileName.str (), EC, llvm::sys::fs::OF_TextWithCRLF));
791
789
}
792
790
llvm::raw_ostream &Out = OutputStream ? *OutputStream : llvm::outs ();
793
791
Original file line number Diff line number Diff line change @@ -2179,8 +2179,11 @@ class CommandObjectTargetModulesDumpClangPCMInfo : public CommandObjectParsed {
2179
2179
const char *clang_args[] = {" clang" , pcm_path};
2180
2180
compiler.setInvocation (clang::createInvocation (clang_args));
2181
2181
2182
- clang::DumpModuleInfoAction dump_module_info;
2183
- dump_module_info.OutputStream = &result.GetOutputStream ().AsRawOstream ();
2182
+ // Pass empty deleter to not attempt to free memory that was allocated
2183
+ // outside of the current scope, possibly statically.
2184
+ std::shared_ptr<llvm::raw_ostream> Out (
2185
+ &result.GetOutputStream ().AsRawOstream (), [](llvm::raw_ostream *) {});
2186
+ clang::DumpModuleInfoAction dump_module_info (Out);
2184
2187
// DumpModuleInfoAction requires ObjectFilePCHContainerReader.
2185
2188
compiler.getPCHContainerOperations ()->registerReader (
2186
2189
std::make_unique<clang::ObjectFilePCHContainerReader>());
You can’t perform that action at this time.
0 commit comments