authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-07-24 17:01:52-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-07-24 17:01:52-07:00
logbd121f3af46bc22a25ac0495e8d83461510c77d4
treedc8013ed1400e8726253649618ccf35f986b8293
parentc8ea8cf5df8261995b1e451085e39cd612c9e038

update clang drivers from llvm 10 to 11


4 files changed, 55 insertions(+), 34 deletions(-)

CMakeLists.txt+1-1
...@@ -359,7 +359,7 @@ endif()...@@ -359,7 +359,7 @@ endif()
359if(MSVC)359if(MSVC)
360 set(EXE_CFLAGS "${EXE_CFLAGS}")360 set(EXE_CFLAGS "${EXE_CFLAGS}")
361else()361else()
362 set(EXE_CFLAGS "${EXE_CFLAGS} -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D_GNU_SOURCE -fvisibility-inlines-hidden -fno-exceptions -fno-rtti -Werror=type-limits -Wno-missing-braces")362 set(EXE_CFLAGS "${EXE_CFLAGS} -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D_GNU_SOURCE -fvisibility-inlines-hidden -fno-exceptions -fno-rtti -Werror=type-limits -Wno-missing-braces -Wno-comment")
363 if(MINGW)363 if(MINGW)
364 set(EXE_CFLAGS "${EXE_CFLAGS} -Wno-format")364 set(EXE_CFLAGS "${EXE_CFLAGS} -Wno-format")
365 endif()365 endif()
src/zig_clang_cc1_main.cpp+4-3
...@@ -177,7 +177,7 @@ static int PrintSupportedCPUs(std::string TargetStr) {...@@ -177,7 +177,7 @@ static int PrintSupportedCPUs(std::string TargetStr) {
177 // the target machine will handle the mcpu printing177 // the target machine will handle the mcpu printing
178 llvm::TargetOptions Options;178 llvm::TargetOptions Options;
179 std::unique_ptr<llvm::TargetMachine> TheTargetMachine(179 std::unique_ptr<llvm::TargetMachine> TheTargetMachine(
180 TheTarget->createTargetMachine(TargetStr, "", "+cpuHelp", Options, None));180 TheTarget->createTargetMachine(TargetStr, "", "+cpuhelp", Options, None));
181 return 0;181 return 0;
182}182}
183183
...@@ -203,8 +203,8 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {...@@ -203,8 +203,8 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
203 IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();203 IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
204 TextDiagnosticBuffer *DiagsBuffer = new TextDiagnosticBuffer;204 TextDiagnosticBuffer *DiagsBuffer = new TextDiagnosticBuffer;
205 DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagsBuffer);205 DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagsBuffer);
206 bool Success =206 bool Success = CompilerInvocation::CreateFromArgs(Clang->getInvocation(),
207 CompilerInvocation::CreateFromArgs(Clang->getInvocation(), Argv, Diags);207 Argv, Diags, Argv0);
208208
209 if (Clang->getFrontendOpts().TimeTrace) {209 if (Clang->getFrontendOpts().TimeTrace) {
210 llvm::timeTraceProfilerInitialize(210 llvm::timeTraceProfilerInitialize(
...@@ -259,6 +259,7 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {...@@ -259,6 +259,7 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
259 // FIXME(ibiryukov): make profilerOutput flush in destructor instead.259 // FIXME(ibiryukov): make profilerOutput flush in destructor instead.
260 profilerOutput->flush();260 profilerOutput->flush();
261 llvm::timeTraceProfilerCleanup();261 llvm::timeTraceProfilerCleanup();
262 Clang->clearOutputFiles(false);
262 }263 }
263 }264 }
264265
src/zig_clang_cc1as_main.cpp+22-19
...@@ -207,7 +207,7 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,...@@ -207,7 +207,7 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
207207
208 // Target Options208 // Target Options
209 Opts.Triple = llvm::Triple::normalize(Args.getLastArgValue(OPT_triple));209 Opts.Triple = llvm::Triple::normalize(Args.getLastArgValue(OPT_triple));
210 Opts.CPU = Args.getLastArgValue(OPT_target_cpu);210 Opts.CPU = std::string(Args.getLastArgValue(OPT_target_cpu));
211 Opts.Features = Args.getAllArgValues(OPT_target_feature);211 Opts.Features = Args.getAllArgValues(OPT_target_feature);
212212
213 // Use the default target triple if unspecified.213 // Use the default target triple if unspecified.
...@@ -238,13 +238,19 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,...@@ -238,13 +238,19 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
238238
239 Opts.RelaxELFRelocations = Args.hasArg(OPT_mrelax_relocations);239 Opts.RelaxELFRelocations = Args.hasArg(OPT_mrelax_relocations);
240 Opts.DwarfVersion = getLastArgIntValue(Args, OPT_dwarf_version_EQ, 2, Diags);240 Opts.DwarfVersion = getLastArgIntValue(Args, OPT_dwarf_version_EQ, 2, Diags);
241 Opts.DwarfDebugFlags = Args.getLastArgValue(OPT_dwarf_debug_flags);241 Opts.DwarfDebugFlags =
242 Opts.DwarfDebugProducer = Args.getLastArgValue(OPT_dwarf_debug_producer);242 std::string(Args.getLastArgValue(OPT_dwarf_debug_flags));
243 Opts.DebugCompilationDir = Args.getLastArgValue(OPT_fdebug_compilation_dir);243 Opts.DwarfDebugProducer =
244 Opts.MainFileName = Args.getLastArgValue(OPT_main_file_name);244 std::string(Args.getLastArgValue(OPT_dwarf_debug_producer));
245245 Opts.DebugCompilationDir =
246 for (const auto &Arg : Args.getAllArgValues(OPT_fdebug_prefix_map_EQ))246 std::string(Args.getLastArgValue(OPT_fdebug_compilation_dir));
247 Opts.DebugPrefixMap.insert(StringRef(Arg).split('='));247 Opts.MainFileName = std::string(Args.getLastArgValue(OPT_main_file_name));
248
249 for (const auto &Arg : Args.getAllArgValues(OPT_fdebug_prefix_map_EQ)) {
250 auto Split = StringRef(Arg).split('=');
251 Opts.DebugPrefixMap.insert(
252 {std::string(Split.first), std::string(Split.second)});
253 }
248254
249 // Frontend Options255 // Frontend Options
250 if (Args.hasArg(OPT_INPUT)) {256 if (Args.hasArg(OPT_INPUT)) {
...@@ -260,8 +266,9 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,...@@ -260,8 +266,9 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
260 }266 }
261 }267 }
262 Opts.LLVMArgs = Args.getAllArgValues(OPT_mllvm);268 Opts.LLVMArgs = Args.getAllArgValues(OPT_mllvm);
263 Opts.OutputPath = Args.getLastArgValue(OPT_o);269 Opts.OutputPath = std::string(Args.getLastArgValue(OPT_o));
264 Opts.SplitDwarfOutput = Args.getLastArgValue(OPT_split_dwarf_output);270 Opts.SplitDwarfOutput =
271 std::string(Args.getLastArgValue(OPT_split_dwarf_output));
265 if (Arg *A = Args.getLastArg(OPT_filetype)) {272 if (Arg *A = Args.getLastArg(OPT_filetype)) {
266 StringRef Name = A->getValue();273 StringRef Name = A->getValue();
267 unsigned OutputType = StringSwitch<unsigned>(Name)274 unsigned OutputType = StringSwitch<unsigned>(Name)
...@@ -289,8 +296,9 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,...@@ -289,8 +296,9 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
289 Opts.NoExecStack = Args.hasArg(OPT_mno_exec_stack);296 Opts.NoExecStack = Args.hasArg(OPT_mno_exec_stack);
290 Opts.FatalWarnings = Args.hasArg(OPT_massembler_fatal_warnings);297 Opts.FatalWarnings = Args.hasArg(OPT_massembler_fatal_warnings);
291 Opts.NoWarn = Args.hasArg(OPT_massembler_no_warn);298 Opts.NoWarn = Args.hasArg(OPT_massembler_no_warn);
292 Opts.RelocationModel = Args.getLastArgValue(OPT_mrelocation_model, "pic");299 Opts.RelocationModel =
293 Opts.TargetABI = Args.getLastArgValue(OPT_target_abi);300 std::string(Args.getLastArgValue(OPT_mrelocation_model, "pic"));
301 Opts.TargetABI = std::string(Args.getLastArgValue(OPT_target_abi));
294 Opts.IncrementalLinkerCompatible =302 Opts.IncrementalLinkerCompatible =
295 Args.hasArg(OPT_mincremental_linker_compatible);303 Args.hasArg(OPT_mincremental_linker_compatible);
296 Opts.SymbolDefs = Args.getAllArgValues(OPT_defsym);304 Opts.SymbolDefs = Args.getAllArgValues(OPT_defsym);
...@@ -421,12 +429,7 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts,...@@ -421,12 +429,7 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts,
421 SrcMgr.getMemoryBuffer(BufferIndex)->getBuffer());429 SrcMgr.getMemoryBuffer(BufferIndex)->getBuffer());
422430
423 // Build up the feature string from the target feature list.431 // Build up the feature string from the target feature list.
424 std::string FS;432 std::string FS = llvm::join(Opts.Features, ",");
425 if (!Opts.Features.empty()) {
426 FS = Opts.Features[0];
427 for (unsigned i = 1, e = Opts.Features.size(); i != e; ++i)
428 FS += "," + Opts.Features[i];
429 }
430433
431 std::unique_ptr<MCStreamer> Str;434 std::unique_ptr<MCStreamer> Str;
432435
...@@ -490,7 +493,7 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts,...@@ -490,7 +493,7 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts,
490 MCSection *AsmLabel = Ctx.getMachOSection(493 MCSection *AsmLabel = Ctx.getMachOSection(
491 "__LLVM", "__asm", MachO::S_REGULAR, 4, SectionKind::getReadOnly());494 "__LLVM", "__asm", MachO::S_REGULAR, 4, SectionKind::getReadOnly());
492 Str.get()->SwitchSection(AsmLabel);495 Str.get()->SwitchSection(AsmLabel);
493 Str.get()->EmitZeros(1);496 Str.get()->emitZeros(1);
494 }497 }
495498
496 // Assembly to object compilation should leverage assembly info.499 // Assembly to object compilation should leverage assembly info.
src/zig_clang_driver.cpp+28-11
...@@ -30,6 +30,7 @@...@@ -30,6 +30,7 @@
30#include "llvm/Option/ArgList.h"30#include "llvm/Option/ArgList.h"
31#include "llvm/Option/OptTable.h"31#include "llvm/Option/OptTable.h"
32#include "llvm/Option/Option.h"32#include "llvm/Option/Option.h"
33#include "llvm/Support/BuryPointer.h"
33#include "llvm/Support/CommandLine.h"34#include "llvm/Support/CommandLine.h"
34#include "llvm/Support/CrashRecoveryContext.h"35#include "llvm/Support/CrashRecoveryContext.h"
35#include "llvm/Support/ErrorHandling.h"36#include "llvm/Support/ErrorHandling.h"
...@@ -37,6 +38,7 @@...@@ -37,6 +38,7 @@
37#include "llvm/Support/Host.h"38#include "llvm/Support/Host.h"
38#include "llvm/Support/InitLLVM.h"39#include "llvm/Support/InitLLVM.h"
39#include "llvm/Support/Path.h"40#include "llvm/Support/Path.h"
41#include "llvm/Support/PrettyStackTrace.h"
40#include "llvm/Support/Process.h"42#include "llvm/Support/Process.h"
41#include "llvm/Support/Program.h"43#include "llvm/Support/Program.h"
42#include "llvm/Support/Regex.h"44#include "llvm/Support/Regex.h"
...@@ -60,7 +62,7 @@ std::string GetExecutablePath(const char *Argv0, bool CanonicalPrefixes) {...@@ -60,7 +62,7 @@ std::string GetExecutablePath(const char *Argv0, bool CanonicalPrefixes) {
60 if (llvm::ErrorOr<std::string> P =62 if (llvm::ErrorOr<std::string> P =
61 llvm::sys::findProgramByName(ExecutablePath))63 llvm::sys::findProgramByName(ExecutablePath))
62 ExecutablePath = *P;64 ExecutablePath = *P;
63 return ExecutablePath.str();65 return std::string(ExecutablePath.str());
64 }66 }
6567
66 // This just needs to be some symbol in the binary; C++ doesn't68 // This just needs to be some symbol in the binary; C++ doesn't
...@@ -71,7 +73,7 @@ std::string GetExecutablePath(const char *Argv0, bool CanonicalPrefixes) {...@@ -71,7 +73,7 @@ std::string GetExecutablePath(const char *Argv0, bool CanonicalPrefixes) {
7173
72static const char *GetStableCStr(std::set<std::string> &SavedStrings,74static const char *GetStableCStr(std::set<std::string> &SavedStrings,
73 StringRef S) {75 StringRef S) {
74 return SavedStrings.insert(S).first->c_str();76 return SavedStrings.insert(std::string(S)).first->c_str();
75}77}
7678
77/// ApplyQAOverride - Apply a list of edits to the input argument lists.79/// ApplyQAOverride - Apply a list of edits to the input argument lists.
...@@ -263,7 +265,7 @@ static void FixupDiagPrefixExeName(TextDiagnosticPrinter *DiagClient,...@@ -263,7 +265,7 @@ static void FixupDiagPrefixExeName(TextDiagnosticPrinter *DiagClient,
263 StringRef ExeBasename(llvm::sys::path::stem(Path));265 StringRef ExeBasename(llvm::sys::path::stem(Path));
264 if (ExeBasename.equals_lower("cl"))266 if (ExeBasename.equals_lower("cl"))
265 ExeBasename = "clang-cl";267 ExeBasename = "clang-cl";
266 DiagClient->setPrefix(ExeBasename);268 DiagClient->setPrefix(std::string(ExeBasename));
267}269}
268270
269// This lets us create the DiagnosticsEngine with a properly-filled-out271// This lets us create the DiagnosticsEngine with a properly-filled-out
...@@ -323,7 +325,7 @@ static int ExecuteCC1Tool(SmallVectorImpl<const char *> &ArgV) {...@@ -323,7 +325,7 @@ static int ExecuteCC1Tool(SmallVectorImpl<const char *> &ArgV) {
323 StringRef Tool = ArgV[1];325 StringRef Tool = ArgV[1];
324 void *GetExecutablePathVP = (void *)(intptr_t)GetExecutablePath;326 void *GetExecutablePathVP = (void *)(intptr_t)GetExecutablePath;
325 if (Tool == "-cc1")327 if (Tool == "-cc1")
326 return cc1_main(makeArrayRef(ArgV).slice(2), ArgV[0], GetExecutablePathVP);328 return cc1_main(makeArrayRef(ArgV).slice(1), ArgV[0], GetExecutablePathVP);
327 if (Tool == "-cc1as")329 if (Tool == "-cc1as")
328 return cc1as_main(makeArrayRef(ArgV).slice(2), ArgV[0],330 return cc1as_main(makeArrayRef(ArgV).slice(2), ArgV[0],
329 GetExecutablePathVP);331 GetExecutablePathVP);
...@@ -337,6 +339,9 @@ extern "C" int ZigClang_main(int argc_, const char **argv_);...@@ -337,6 +339,9 @@ extern "C" int ZigClang_main(int argc_, const char **argv_);
337int ZigClang_main(int argc_, const char **argv_) {339int ZigClang_main(int argc_, const char **argv_) {
338 noteBottomOfStack();340 noteBottomOfStack();
339 llvm::InitLLVM X(argc_, argv_);341 llvm::InitLLVM X(argc_, argv_);
342 llvm::setBugReportMsg("PLEASE submit a bug report to " BUG_REPORT_URL
343 " and include the crash backtrace, preprocessed "
344 "source, and associated run script.\n");
340 size_t argv_offset = (strcmp(argv_[1], "-cc1") == 0 || strcmp(argv_[1], "-cc1as") == 0) ? 0 : 1;345 size_t argv_offset = (strcmp(argv_[1], "-cc1") == 0 || strcmp(argv_[1], "-cc1as") == 0) ? 0 : 1;
341 SmallVector<const char *, 256> argv(argv_ + argv_offset, argv_ + argc_);346 SmallVector<const char *, 256> argv(argv_ + argv_offset, argv_ + argc_);
342347
...@@ -488,6 +493,7 @@ int ZigClang_main(int argc_, const char **argv_) {...@@ -488,6 +493,7 @@ int ZigClang_main(int argc_, const char **argv_) {
488493
489 std::unique_ptr<Compilation> C(TheDriver.BuildCompilation(argv));494 std::unique_ptr<Compilation> C(TheDriver.BuildCompilation(argv));
490 int Res = 1;495 int Res = 1;
496 bool IsCrash = false;
491 if (C && !C->containsError()) {497 if (C && !C->containsError()) {
492 SmallVector<std::pair<int, const Command *>, 4> FailingCommands;498 SmallVector<std::pair<int, const Command *>, 4> FailingCommands;
493 Res = TheDriver.ExecuteCompilation(*C, FailingCommands);499 Res = TheDriver.ExecuteCompilation(*C, FailingCommands);
...@@ -502,6 +508,11 @@ int ZigClang_main(int argc_, const char **argv_) {...@@ -502,6 +508,11 @@ int ZigClang_main(int argc_, const char **argv_) {
502 for (const auto &J : C->getJobs())508 for (const auto &J : C->getJobs())
503 if (const Command *C = dyn_cast<Command>(&J))509 if (const Command *C = dyn_cast<Command>(&J))
504 FailingCommands.push_back(std::make_pair(-1, C));510 FailingCommands.push_back(std::make_pair(-1, C));
511
512 // Print the bug report message that would be printed if we did actually
513 // crash, but only if we're crashing due to FORCE_CLANG_DIAGNOSTICS_CRASH.
514 if (::getenv("FORCE_CLANG_DIAGNOSTICS_CRASH"))
515 llvm::dbgs() << llvm::getBugReportMsg();
505 }516 }
506517
507 for (const auto &P : FailingCommands) {518 for (const auto &P : FailingCommands) {
...@@ -514,11 +525,11 @@ int ZigClang_main(int argc_, const char **argv_) {...@@ -514,11 +525,11 @@ int ZigClang_main(int argc_, const char **argv_) {
514 // If result status is 70, then the driver command reported a fatal error.525 // If result status is 70, then the driver command reported a fatal error.
515 // On Windows, abort will return an exit code of 3. In these cases,526 // On Windows, abort will return an exit code of 3. In these cases,
516 // generate additional diagnostic information if possible.527 // generate additional diagnostic information if possible.
517 bool DiagnoseCrash = CommandRes < 0 || CommandRes == 70;528 IsCrash = CommandRes < 0 || CommandRes == 70;
518#ifdef _WIN32529#ifdef _WIN32
519 DiagnoseCrash |= CommandRes == 3;530 IsCrash |= CommandRes == 3;
520#endif531#endif
521 if (DiagnoseCrash) {532 if (IsCrash) {
522 TheDriver.generateCompilationDiagnostics(*C, *FailingCommand);533 TheDriver.generateCompilationDiagnostics(*C, *FailingCommand);
523 break;534 break;
524 }535 }
...@@ -527,10 +538,16 @@ int ZigClang_main(int argc_, const char **argv_) {...@@ -527,10 +538,16 @@ int ZigClang_main(int argc_, const char **argv_) {
527538
528 Diags.getClient()->finish();539 Diags.getClient()->finish();
529540
530 // If any timers were active but haven't been destroyed yet, print their541 if (!UseNewCC1Process && IsCrash) {
531 // results now. This happens in -disable-free mode.542 // When crashing in -fintegrated-cc1 mode, bury the timer pointers, because
532 llvm::TimerGroup::printAll(llvm::errs());543 // the internal linked list might point to already released stack frames.
533 llvm::TimerGroup::clearAll();544 llvm::BuryPointer(llvm::TimerGroup::aquireDefaultGroup());
545 } else {
546 // If any timers were active but haven't been destroyed yet, print their
547 // results now. This happens in -disable-free mode.
548 llvm::TimerGroup::printAll(llvm::errs());
549 llvm::TimerGroup::clearAll();
550 }
534551
535#ifdef _WIN32552#ifdef _WIN32
536 // Exit status should not be negative on Win32, unless abnormal termination.553 // Exit status should not be negative on Win32, unless abnormal termination.