From 83ff94406e13e18c8826cd48a68c2c8d676feaac Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Wed, 16 Dec 2020 10:40:56 +0100 Subject: [PATCH] Update clang drivers llvm commit b2851aea80e5a8f0cfd6c3c5a56a6b00fb28c6b6 --- src/zig_clang_cc1as_main.cpp | 29 ++++++++++++++--------------- src/zig_clang_driver.cpp | 7 +++++++ 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/zig_clang_cc1as_main.cpp b/src/zig_clang_cc1as_main.cpp index 77b99b2013..de71026fbf 100644 --- a/src/zig_clang_cc1as_main.cpp +++ b/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(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(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 Str; std::unique_ptr MCII(TheTarget->createMCInstrInfo()); + assert(MCII && "Unable to create instruction info!"); + std::unique_ptr STI( TheTarget->createMCSubtargetInfo(Opts.Triple, Opts.CPU, FS)); + assert(STI && "Unable to create subtarget info!"); raw_pwrite_stream *Out = FDOS.get(); std::unique_ptr BOS; @@ -474,6 +471,8 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts, TheTarget->createMCCodeEmitter(*MCII, *MRI, Ctx)); std::unique_ptr MAB( TheTarget->createMCAsmBackend(*STI, *MRI, MCOptions)); + assert(MAB && "Unable to create asm backend!"); + std::unique_ptr 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(); diff --git a/src/zig_clang_driver.cpp b/src/zig_clang_driver.cpp index fbe407a06c..ac892f95e8 100644 --- a/src/zig_clang_driver.cpp +++ b/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);