Commit 83ff94406e
Changed files (2)
src/zig_clang_cc1as_main.cpp
@@ -221,19 +221,13 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
// Any DebugInfoKind implies GenDwarfForAssembly.
Opts.GenDwarfForAssembly = Args.hasArg(OPT_debug_info_kind_EQ);
- if (const Arg *A = Args.getLastArg(OPT_compress_debug_sections,
- OPT_compress_debug_sections_EQ)) {
- if (A->getOption().getID() == OPT_compress_debug_sections) {
- // TODO: be more clever about the compression type auto-detection
- Opts.CompressDebugSections = llvm::DebugCompressionType::GNU;
- } else {
- Opts.CompressDebugSections =
- llvm::StringSwitch<llvm::DebugCompressionType>(A->getValue())
- .Case("none", llvm::DebugCompressionType::None)
- .Case("zlib", llvm::DebugCompressionType::Z)
- .Case("zlib-gnu", llvm::DebugCompressionType::GNU)
- .Default(llvm::DebugCompressionType::None);
- }
+ if (const Arg *A = Args.getLastArg(OPT_compress_debug_sections_EQ)) {
+ Opts.CompressDebugSections =
+ llvm::StringSwitch<llvm::DebugCompressionType>(A->getValue())
+ .Case("none", llvm::DebugCompressionType::None)
+ .Case("zlib", llvm::DebugCompressionType::Z)
+ .Case("zlib-gnu", llvm::DebugCompressionType::GNU)
+ .Default(llvm::DebugCompressionType::None);
}
Opts.RelaxELFRelocations = Args.hasArg(OPT_mrelax_relocations);
@@ -434,8 +428,11 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts,
std::unique_ptr<MCStreamer> Str;
std::unique_ptr<MCInstrInfo> MCII(TheTarget->createMCInstrInfo());
+ assert(MCII && "Unable to create instruction info!");
+
std::unique_ptr<MCSubtargetInfo> STI(
TheTarget->createMCSubtargetInfo(Opts.Triple, Opts.CPU, FS));
+ assert(STI && "Unable to create subtarget info!");
raw_pwrite_stream *Out = FDOS.get();
std::unique_ptr<buffer_ostream> BOS;
@@ -474,6 +471,8 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts,
TheTarget->createMCCodeEmitter(*MCII, *MRI, Ctx));
std::unique_ptr<MCAsmBackend> MAB(
TheTarget->createMCAsmBackend(*STI, *MRI, MCOptions));
+ assert(MAB && "Unable to create asm backend!");
+
std::unique_ptr<MCObjectWriter> OW =
DwoOS ? MAB->createDwoObjectWriter(*Out, *DwoOS)
: MAB->createObjectWriter(*Out);
@@ -526,8 +525,8 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts,
Failed = Parser->Run(Opts.NoInitialTextSection);
}
- // Close Streamer first.
- // It might have a reference to the output stream.
+ // Parser has a reference to the output stream (Str), so close Parser first.
+ Parser.reset();
Str.reset();
// Close the output stream early.
BOS.reset();
src/zig_clang_driver.cpp
@@ -528,6 +528,13 @@ int ZigClang_main(int argc_, const char **argv_) {
IsCrash = CommandRes < 0 || CommandRes == 70;
#ifdef _WIN32
IsCrash |= CommandRes == 3;
+#endif
+#if LLVM_ON_UNIX
+ // When running in integrated-cc1 mode, the CrashRecoveryContext returns
+ // the same codes as if the program crashed. See section "Exit Status for
+ // Commands":
+ // https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xcu_chap02.html
+ IsCrash |= CommandRes > 128;
#endif
if (IsCrash) {
TheDriver.generateCompilationDiagnostics(*C, *FailingCommand);