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()
359359if(MSVC)
360360 set(EXE_CFLAGS "${EXE_CFLAGS}")
361361else()
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")
363363 if(MINGW)
364364 set(EXE_CFLAGS "${EXE_CFLAGS} -Wno-format")
365365 endif()
src/zig_clang_cc1_main.cpp+4-3
......@@ -177,7 +177,7 @@ static int PrintSupportedCPUs(std::string TargetStr) {
177177 // the target machine will handle the mcpu printing
178178 llvm::TargetOptions Options;
179179 std::unique_ptr<llvm::TargetMachine> TheTargetMachine(
180 TheTarget->createTargetMachine(TargetStr, "", "+cpuHelp", Options, None));
180 TheTarget->createTargetMachine(TargetStr, "", "+cpuhelp", Options, None));
181181 return 0;
182182}
183183
......@@ -203,8 +203,8 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
203203 IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
204204 TextDiagnosticBuffer *DiagsBuffer = new TextDiagnosticBuffer;
205205 DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagsBuffer);
206 bool Success =
207 CompilerInvocation::CreateFromArgs(Clang->getInvocation(), Argv, Diags);
206 bool Success = CompilerInvocation::CreateFromArgs(Clang->getInvocation(),
207 Argv, Diags, Argv0);
208208
209209 if (Clang->getFrontendOpts().TimeTrace) {
210210 llvm::timeTraceProfilerInitialize(
......@@ -259,6 +259,7 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
259259 // FIXME(ibiryukov): make profilerOutput flush in destructor instead.
260260 profilerOutput->flush();
261261 llvm::timeTraceProfilerCleanup();
262 Clang->clearOutputFiles(false);
262263 }
263264 }
264265
src/zig_clang_cc1as_main.cpp+22-19
......@@ -207,7 +207,7 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
207207
208208 // Target Options
209209 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));
211211 Opts.Features = Args.getAllArgValues(OPT_target_feature);
212212
213213 // Use the default target triple if unspecified.
......@@ -238,13 +238,19 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
238238
239239 Opts.RelaxELFRelocations = Args.hasArg(OPT_mrelax_relocations);
240240 Opts.DwarfVersion = getLastArgIntValue(Args, OPT_dwarf_version_EQ, 2, Diags);
241 Opts.DwarfDebugFlags = Args.getLastArgValue(OPT_dwarf_debug_flags);
242 Opts.DwarfDebugProducer = Args.getLastArgValue(OPT_dwarf_debug_producer);
243 Opts.DebugCompilationDir = Args.getLastArgValue(OPT_fdebug_compilation_dir);
244 Opts.MainFileName = Args.getLastArgValue(OPT_main_file_name);
245
246 for (const auto &Arg : Args.getAllArgValues(OPT_fdebug_prefix_map_EQ))
247 Opts.DebugPrefixMap.insert(StringRef(Arg).split('='));
241 Opts.DwarfDebugFlags =
242 std::string(Args.getLastArgValue(OPT_dwarf_debug_flags));
243 Opts.DwarfDebugProducer =
244 std::string(Args.getLastArgValue(OPT_dwarf_debug_producer));
245 Opts.DebugCompilationDir =
246 std::string(Args.getLastArgValue(OPT_fdebug_compilation_dir));
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
249255 // Frontend Options
250256 if (Args.hasArg(OPT_INPUT)) {
......@@ -260,8 +266,9 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
260266 }
261267 }
262268 Opts.LLVMArgs = Args.getAllArgValues(OPT_mllvm);
263 Opts.OutputPath = Args.getLastArgValue(OPT_o);
264 Opts.SplitDwarfOutput = Args.getLastArgValue(OPT_split_dwarf_output);
269 Opts.OutputPath = std::string(Args.getLastArgValue(OPT_o));
270 Opts.SplitDwarfOutput =
271 std::string(Args.getLastArgValue(OPT_split_dwarf_output));
265272 if (Arg *A = Args.getLastArg(OPT_filetype)) {
266273 StringRef Name = A->getValue();
267274 unsigned OutputType = StringSwitch<unsigned>(Name)
......@@ -289,8 +296,9 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
289296 Opts.NoExecStack = Args.hasArg(OPT_mno_exec_stack);
290297 Opts.FatalWarnings = Args.hasArg(OPT_massembler_fatal_warnings);
291298 Opts.NoWarn = Args.hasArg(OPT_massembler_no_warn);
292 Opts.RelocationModel = Args.getLastArgValue(OPT_mrelocation_model, "pic");
293 Opts.TargetABI = Args.getLastArgValue(OPT_target_abi);
299 Opts.RelocationModel =
300 std::string(Args.getLastArgValue(OPT_mrelocation_model, "pic"));
301 Opts.TargetABI = std::string(Args.getLastArgValue(OPT_target_abi));
294302 Opts.IncrementalLinkerCompatible =
295303 Args.hasArg(OPT_mincremental_linker_compatible);
296304 Opts.SymbolDefs = Args.getAllArgValues(OPT_defsym);
......@@ -421,12 +429,7 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts,
421429 SrcMgr.getMemoryBuffer(BufferIndex)->getBuffer());
422430
423431 // Build up the feature string from the target feature list.
424 std::string FS;
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 }
432 std::string FS = llvm::join(Opts.Features, ",");
430433
431434 std::unique_ptr<MCStreamer> Str;
432435
......@@ -490,7 +493,7 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts,
490493 MCSection *AsmLabel = Ctx.getMachOSection(
491494 "__LLVM", "__asm", MachO::S_REGULAR, 4, SectionKind::getReadOnly());
492495 Str.get()->SwitchSection(AsmLabel);
493 Str.get()->EmitZeros(1);
496 Str.get()->emitZeros(1);
494497 }
495498
496499 // Assembly to object compilation should leverage assembly info.
src/zig_clang_driver.cpp+28-11
......@@ -30,6 +30,7 @@
3030#include "llvm/Option/ArgList.h"
3131#include "llvm/Option/OptTable.h"
3232#include "llvm/Option/Option.h"
33#include "llvm/Support/BuryPointer.h"
3334#include "llvm/Support/CommandLine.h"
3435#include "llvm/Support/CrashRecoveryContext.h"
3536#include "llvm/Support/ErrorHandling.h"
......@@ -37,6 +38,7 @@
3738#include "llvm/Support/Host.h"
3839#include "llvm/Support/InitLLVM.h"
3940#include "llvm/Support/Path.h"
41#include "llvm/Support/PrettyStackTrace.h"
4042#include "llvm/Support/Process.h"
4143#include "llvm/Support/Program.h"
4244#include "llvm/Support/Regex.h"
......@@ -60,7 +62,7 @@ std::string GetExecutablePath(const char *Argv0, bool CanonicalPrefixes) {
6062 if (llvm::ErrorOr<std::string> P =
6163 llvm::sys::findProgramByName(ExecutablePath))
6264 ExecutablePath = *P;
63 return ExecutablePath.str();
65 return std::string(ExecutablePath.str());
6466 }
6567
6668 // 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) {
7173
7274static const char *GetStableCStr(std::set<std::string> &SavedStrings,
7375 StringRef S) {
74 return SavedStrings.insert(S).first->c_str();
76 return SavedStrings.insert(std::string(S)).first->c_str();
7577}
7678
7779/// ApplyQAOverride - Apply a list of edits to the input argument lists.
......@@ -263,7 +265,7 @@ static void FixupDiagPrefixExeName(TextDiagnosticPrinter *DiagClient,
263265 StringRef ExeBasename(llvm::sys::path::stem(Path));
264266 if (ExeBasename.equals_lower("cl"))
265267 ExeBasename = "clang-cl";
266 DiagClient->setPrefix(ExeBasename);
268 DiagClient->setPrefix(std::string(ExeBasename));
267269}
268270
269271// This lets us create the DiagnosticsEngine with a properly-filled-out
......@@ -323,7 +325,7 @@ static int ExecuteCC1Tool(SmallVectorImpl<const char *> &ArgV) {
323325 StringRef Tool = ArgV[1];
324326 void *GetExecutablePathVP = (void *)(intptr_t)GetExecutablePath;
325327 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);
327329 if (Tool == "-cc1as")
328330 return cc1as_main(makeArrayRef(ArgV).slice(2), ArgV[0],
329331 GetExecutablePathVP);
......@@ -337,6 +339,9 @@ extern "C" int ZigClang_main(int argc_, const char **argv_);
337339int ZigClang_main(int argc_, const char **argv_) {
338340 noteBottomOfStack();
339341 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");
340345 size_t argv_offset = (strcmp(argv_[1], "-cc1") == 0 || strcmp(argv_[1], "-cc1as") == 0) ? 0 : 1;
341346 SmallVector<const char *, 256> argv(argv_ + argv_offset, argv_ + argc_);
342347
......@@ -488,6 +493,7 @@ int ZigClang_main(int argc_, const char **argv_) {
488493
489494 std::unique_ptr<Compilation> C(TheDriver.BuildCompilation(argv));
490495 int Res = 1;
496 bool IsCrash = false;
491497 if (C && !C->containsError()) {
492498 SmallVector<std::pair<int, const Command *>, 4> FailingCommands;
493499 Res = TheDriver.ExecuteCompilation(*C, FailingCommands);
......@@ -502,6 +508,11 @@ int ZigClang_main(int argc_, const char **argv_) {
502508 for (const auto &J : C->getJobs())
503509 if (const Command *C = dyn_cast<Command>(&J))
504510 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();
505516 }
506517
507518 for (const auto &P : FailingCommands) {
......@@ -514,11 +525,11 @@ int ZigClang_main(int argc_, const char **argv_) {
514525 // If result status is 70, then the driver command reported a fatal error.
515526 // On Windows, abort will return an exit code of 3. In these cases,
516527 // generate additional diagnostic information if possible.
517 bool DiagnoseCrash = CommandRes < 0 || CommandRes == 70;
528 IsCrash = CommandRes < 0 || CommandRes == 70;
518529#ifdef _WIN32
519 DiagnoseCrash |= CommandRes == 3;
530 IsCrash |= CommandRes == 3;
520531#endif
521 if (DiagnoseCrash) {
532 if (IsCrash) {
522533 TheDriver.generateCompilationDiagnostics(*C, *FailingCommand);
523534 break;
524535 }
......@@ -527,10 +538,16 @@ int ZigClang_main(int argc_, const char **argv_) {
527538
528539 Diags.getClient()->finish();
529540
530 // If any timers were active but haven't been destroyed yet, print their
531 // results now. This happens in -disable-free mode.
532 llvm::TimerGroup::printAll(llvm::errs());
533 llvm::TimerGroup::clearAll();
541 if (!UseNewCC1Process && IsCrash) {
542 // When crashing in -fintegrated-cc1 mode, bury the timer pointers, because
543 // the internal linked list might point to already released stack frames.
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
535552#ifdef _WIN32
536553 // Exit status should not be negative on Win32, unless abnormal termination.