From ae480ecaec4e4ead2f93954fa052483d254228b9 Mon Sep 17 00:00:00 2001 From: Steven Wu Date: Fri, 24 Jul 2015 02:12:43 +0000 Subject: [PATCH] Fix the cc1as crash when it outputs assembly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In clang cc1as_main, when the output file type is “asm”, AsmStreamer owns a formatted_raw_ostream which has a reference to FDOS (raw_ostream), so AsmStreamer must be closed before FDOS is closed. llvm-svn: 243085 --- clang/test/Misc/cc1as-asm.s | 3 +++ clang/tools/driver/cc1as_main.cpp | 3 +++ 2 files changed, 6 insertions(+) create mode 100644 clang/test/Misc/cc1as-asm.s diff --git a/clang/test/Misc/cc1as-asm.s b/clang/test/Misc/cc1as-asm.s new file mode 100644 index 000000000000..af92644073ac --- /dev/null +++ b/clang/test/Misc/cc1as-asm.s @@ -0,0 +1,3 @@ +// Run cc1as asm output path just to make sure it works +// REQUIRES: x86-registered-target +// RUN: %clang -cc1as -triple x86_64-apple-macosx10.10.0 -filetype asm %s -o /dev/null diff --git a/clang/tools/driver/cc1as_main.cpp b/clang/tools/driver/cc1as_main.cpp index aa92541953fa..fd0fbb4c5a26 100644 --- a/clang/tools/driver/cc1as_main.cpp +++ b/clang/tools/driver/cc1as_main.cpp @@ -406,6 +406,9 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts, Failed = Parser->Run(Opts.NoInitialTextSection); } + // Close Streamer first. + // It might have a reference to the output stream. + Str.reset(); // Close the output stream early. BOS.reset(); FDOS.reset();