authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-02-03 13:43:51-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-02-03 13:43:51-07:00
log3479294b6e7cae323f2e2f05dbc173e2b1a4b9e1
tree1427cfac72a0bc1e7036a04395dca876d910d02a
parent308f72701af0a44bdb2cb2893f3175b7d37f657b

update llvm and clang tools to release/14.x

upstream commit 91632c8ac97fa3daffe4ff8f1391735b5d6805e6

4 files changed, 62 insertions(+), 78 deletions(-)

src/zig_clang_cc1_main.cpp+5-3
......@@ -28,6 +28,7 @@
2828#include "llvm/ADT/Statistic.h"
2929#include "llvm/Config/llvm-config.h"
3030#include "llvm/LinkAllPasses.h"
31#include "llvm/MC/TargetRegistry.h"
3132#include "llvm/Option/Arg.h"
3233#include "llvm/Option/ArgList.h"
3334#include "llvm/Option/OptTable.h"
......@@ -38,7 +39,6 @@
3839#include "llvm/Support/Path.h"
3940#include "llvm/Support/Process.h"
4041#include "llvm/Support/Signals.h"
41#include "llvm/Support/TargetRegistry.h"
4242#include "llvm/Support/TargetSelect.h"
4343#include "llvm/Support/TimeProfiler.h"
4444#include "llvm/Support/Timer.h"
......@@ -57,7 +57,7 @@ using namespace llvm::opt;
5757// Main driver
5858//===----------------------------------------------------------------------===//
5959
60static void LLVMErrorHandler(void *UserData, const std::string &Message,
60static void LLVMErrorHandler(void *UserData, const char *Message,
6161 bool GenCrashDiag) {
6262 DiagnosticsEngine &Diags = *static_cast<DiagnosticsEngine*>(UserData);
6363
......@@ -237,8 +237,10 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
237237 static_cast<void*>(&Clang->getDiagnostics()));
238238
239239 DiagsBuffer->FlushDiagnostics(Clang->getDiagnostics());
240 if (!Success)
240 if (!Success) {
241 Clang->getDiagnosticClient().finish();
241242 return 1;
243 }
242244
243245 // Execute the frontend actions.
244246 {
src/zig_clang_cc1as_main.cpp+3-4
......@@ -36,6 +36,7 @@
3636#include "llvm/MC/MCStreamer.h"
3737#include "llvm/MC/MCSubtargetInfo.h"
3838#include "llvm/MC/MCTargetOptions.h"
39#include "llvm/MC/TargetRegistry.h"
3940#include "llvm/Option/Arg.h"
4041#include "llvm/Option/ArgList.h"
4142#include "llvm/Option/OptTable.h"
......@@ -49,7 +50,6 @@
4950#include "llvm/Support/Process.h"
5051#include "llvm/Support/Signals.h"
5152#include "llvm/Support/SourceMgr.h"
52#include "llvm/Support/TargetRegistry.h"
5353#include "llvm/Support/TargetSelect.h"
5454#include "llvm/Support/Timer.h"
5555#include "llvm/Support/raw_ostream.h"
......@@ -228,7 +228,6 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
228228 llvm::StringSwitch<llvm::DebugCompressionType>(A->getValue())
229229 .Case("none", llvm::DebugCompressionType::None)
230230 .Case("zlib", llvm::DebugCompressionType::Z)
231 .Case("zlib-gnu", llvm::DebugCompressionType::GNU)
232231 .Default(llvm::DebugCompressionType::None);
233232 }
234233
......@@ -490,7 +489,7 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
490489 T, Ctx, std::move(MAB), std::move(OW), std::move(CE), *STI,
491490 Opts.RelaxAll, Opts.IncrementalLinkerCompatible,
492491 /*DWARFMustBeAtTheEnd*/ true));
493 Str.get()->InitSections(Opts.NoExecStack);
492 Str.get()->initSections(Opts.NoExecStack, *STI);
494493 }
495494
496495 // When -fembed-bitcode is passed to clang_as, a 1-byte marker
......@@ -550,7 +549,7 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts,
550549 return Failed;
551550}
552551
553static void LLVMErrorHandler(void *UserData, const std::string &Message,
552static void LLVMErrorHandler(void *UserData, const char *Message,
554553 bool GenCrashDiag) {
555554 DiagnosticsEngine &Diags = *static_cast<DiagnosticsEngine*>(UserData);
556555
src/zig_clang_driver.cpp+22-44
......@@ -120,7 +120,7 @@ static void ApplyOneQAOverride(raw_ostream &OS,
120120 OS << "### Adding argument " << Str << " at end\n";
121121 Args.push_back(Str);
122122 } else if (Edit[0] == 's' && Edit[1] == '/' && Edit.endswith("/") &&
123 Edit.slice(2, Edit.size()-1).find('/') != StringRef::npos) {
123 Edit.slice(2, Edit.size() - 1).contains('/')) {
124124 StringRef MatchPattern = Edit.substr(2).split('/').first;
125125 StringRef ReplPattern = Edit.substr(2).split('/').second;
126126 ReplPattern = ReplPattern.slice(0, ReplPattern.size()-1);
......@@ -207,6 +207,8 @@ extern int cc1_main(ArrayRef<const char *> Argv, const char *Argv0,
207207 void *MainAddr);
208208extern int cc1as_main(ArrayRef<const char *> Argv, const char *Argv0,
209209 void *MainAddr);
210extern int cc1gen_reproducer_main(ArrayRef<const char *> Argv,
211 const char *Argv0, void *MainAddr);
210212
211213static void insertTargetAndModeArgs(const ParsedClangName &NameParts,
212214 SmallVectorImpl<const char *> &ArgVector,
......@@ -276,27 +278,6 @@ static void FixupDiagPrefixExeName(TextDiagnosticPrinter *DiagClient,
276278 DiagClient->setPrefix(std::string(ExeBasename));
277279}
278280
279// This lets us create the DiagnosticsEngine with a properly-filled-out
280// DiagnosticOptions instance.
281static DiagnosticOptions *
282CreateAndPopulateDiagOpts(ArrayRef<const char *> argv, bool &UseNewCC1Process) {
283 auto *DiagOpts = new DiagnosticOptions;
284 unsigned MissingArgIndex, MissingArgCount;
285 InputArgList Args = getDriverOptTable().ParseArgs(
286 argv.slice(1), MissingArgIndex, MissingArgCount);
287 // We ignore MissingArgCount and the return value of ParseDiagnosticArgs.
288 // Any errors that would be diagnosed here will also be diagnosed later,
289 // when the DiagnosticsEngine actually exists.
290 (void)ParseDiagnosticArgs(*DiagOpts, Args);
291
292 UseNewCC1Process =
293 Args.hasFlag(clang::driver::options::OPT_fno_integrated_cc1,
294 clang::driver::options::OPT_fintegrated_cc1,
295 /*Default=*/CLANG_SPAWN_CC1);
296
297 return DiagOpts;
298}
299
300281static void SetInstallDir(SmallVectorImpl<const char *> &argv,
301282 Driver &TheDriver, bool CanonicalPrefixes) {
302283 // Attempt to find the original path used to invoke the driver, to determine
......@@ -337,28 +318,22 @@ static int ExecuteCC1Tool(SmallVectorImpl<const char *> &ArgV) {
337318 if (Tool == "-cc1as")
338319 return cc1as_main(makeArrayRef(ArgV).slice(2), ArgV[0],
339320 GetExecutablePathVP);
321 if (Tool == "-cc1gen-reproducer")
322 return cc1gen_reproducer_main(makeArrayRef(ArgV).slice(2), ArgV[0],
323 GetExecutablePathVP);
340324 // Reject unknown tools.
341325 llvm::errs() << "error: unknown integrated tool '" << Tool << "'. "
342326 << "Valid tools include '-cc1' and '-cc1as'.\n";
343327 return 1;
344328}
345329
346extern "C" int ZigClang_main(int Argc, const char **Argv);
347int ZigClang_main(int Argc, const char **Argv) {
330int main(int Argc, const char **Argv) {
348331 noteBottomOfStack();
349 // ZIG PATCH: On Windows, InitLLVM calls GetCommandLineW(),
350 // and overwrites the args. We don't want it to do that,
351 // and we also don't need the signal handlers it installs
352 // (we have our own already), so we just use llvm_shutdown_obj
353 // instead.
354 // llvm::InitLLVM X(Argc, Argv);
355 llvm::llvm_shutdown_obj X;
356
332 llvm::InitLLVM X(Argc, Argv);
357333 llvm::setBugReportMsg("PLEASE submit a bug report to " BUG_REPORT_URL
358334 " and include the crash backtrace, preprocessed "
359335 "source, and associated run script.\n");
360 size_t argv_offset = (strcmp(Argv[1], "-cc1") == 0 || strcmp(Argv[1], "-cc1as") == 0) ? 0 : 1;
361 SmallVector<const char *, 256> Args(Argv + argv_offset, Argv + Argc);
336 SmallVector<const char *, 256> Args(Argv, Argv + Argc);
362337
363338 if (llvm::sys::Process::FixupStandardFileDescriptors())
364339 return 1;
......@@ -402,8 +377,8 @@ int ZigClang_main(int Argc, const char **Argv) {
402377
403378 // Handle -cc1 integrated tools, even if -cc1 was expanded from a response
404379 // file.
405 auto FirstArg = std::find_if(Args.begin() + 1, Args.end(),
406 [](const char *A) { return A != nullptr; });
380 auto FirstArg = llvm::find_if(llvm::drop_begin(Args),
381 [](const char *A) { return A != nullptr; });
407382 if (FirstArg != Args.end() && StringRef(*FirstArg).startswith("-cc1")) {
408383 // If -cc1 came from a response file, remove the EOL sentinels.
409384 if (MarkEOLs) {
......@@ -420,10 +395,10 @@ int ZigClang_main(int Argc, const char **Argv) {
420395 // Skip end-of-line response file markers
421396 if (Args[i] == nullptr)
422397 continue;
423 if (StringRef(Args[i]) == "-no-canonical-prefixes") {
398 if (StringRef(Args[i]) == "-canonical-prefixes")
399 CanonicalPrefixes = true;
400 else if (StringRef(Args[i]) == "-no-canonical-prefixes")
424401 CanonicalPrefixes = false;
425 break;
426 }
427402 }
428403
429404 // Handle CL and _CL_ which permits additional command line options to be
......@@ -457,18 +432,21 @@ int ZigClang_main(int Argc, const char **Argv) {
457432 ApplyQAOverride(Args, OverrideStr, SavedStrings);
458433 }
459434
460 // Pass local param `Argv[0]` as fallback.
461 // See https://github.com/ziglang/zig/pull/3292 .
462 std::string Path = GetExecutablePath(Argv[0], CanonicalPrefixes);
435 std::string Path = GetExecutablePath(Args[0], CanonicalPrefixes);
463436
464437 // Whether the cc1 tool should be called inside the current process, or if we
465438 // should spawn a new clang subprocess (old behavior).
466439 // Not having an additional process saves some execution time of Windows,
467440 // and makes debugging and profiling easier.
468 bool UseNewCC1Process;
441 bool UseNewCC1Process = CLANG_SPAWN_CC1;
442 for (const char *Arg : Args)
443 UseNewCC1Process = llvm::StringSwitch<bool>(Arg)
444 .Case("-fno-integrated-cc1", true)
445 .Case("-fintegrated-cc1", false)
446 .Default(UseNewCC1Process);
469447
470448 IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts =
471 CreateAndPopulateDiagOpts(Args, UseNewCC1Process);
449 CreateAndPopulateDiagOpts(Args);
472450
473451 TextDiagnosticPrinter *DiagClient
474452 = new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts);
src/zig_llvm-ar.cpp+32-27
......@@ -90,17 +90,18 @@ OPTIONS:
9090 --rsp-quoting - quoting style for response files
9191 =posix - posix
9292 =windows - windows
93 --thin - create a thin archive
9394 --version - print the version and exit
9495 @<file> - read options from <file>
9596
9697OPERATIONS:
9798 d - delete [files] from the archive
9899 m - move [files] in the archive
99 p - print [files] found in the archive
100 p - print contents of [files] found in the archive
100101 q - quick append [files] to the archive
101102 r - replace or insert [files] into the archive
102103 s - act as ranlib
103 t - display contents of archive
104 t - display list of files in archive
104105 x - extract [files] from the archive
105106
106107MODIFIERS:
......@@ -118,7 +119,7 @@ MODIFIERS:
118119 [P] - use full names when matching (implied for thin archives)
119120 [s] - create an archive index (cf. ranlib)
120121 [S] - do not build a symbol table
121 [T] - create a thin archive
122 [T] - deprecated, use --thin instead
122123 [u] - update only [files] newer than archive contents
123124 [U] - use actual timestamps and uids/gids
124125 [v] - be verbose about actions taken
......@@ -136,14 +137,14 @@ static unsigned MRILineNumber;
136137static bool ParsingMRIScript;
137138
138139// Show the error plus the usage message, and exit.
139LLVM_ATTRIBUTE_NORETURN static void badUsage(Twine Error) {
140[[noreturn]] static void badUsage(Twine Error) {
140141 WithColor::error(errs(), ToolName) << Error << "\n";
141142 printHelpMessage();
142143 exit(1);
143144}
144145
145146// Show the error message and exit.
146LLVM_ATTRIBUTE_NORETURN static void fail(Twine Error) {
147[[noreturn]] static void fail(Twine Error) {
147148 if (ParsingMRIScript) {
148149 WithColor::error(errs(), ToolName)
149150 << "script line " << MRILineNumber << ": " << Error << "\n";
......@@ -232,7 +233,7 @@ static std::string ArchiveName;
232233static std::vector<std::unique_ptr<MemoryBuffer>> ArchiveBuffers;
233234static std::vector<std::unique_ptr<object::Archive>> Archives;
234235
235// This variable holds the list of member files to process, as given
236// This variable holds the list of member files to proecess, as given
236237// on the command line.
237238static std::vector<StringRef> Members;
238239
......@@ -390,8 +391,6 @@ static ArchiveOperation parseCommandLine() {
390391 break;
391392 case 'T':
392393 Thin = true;
393 // Thin archives store path names, so P should be forced.
394 CompareFullPath = true;
395394 break;
396395 case 'L':
397396 AddLibrary = true;
......@@ -407,6 +406,10 @@ static ArchiveOperation parseCommandLine() {
407406 }
408407 }
409408
409 // Thin archives store path names, so P should be forced.
410 if (Thin)
411 CompareFullPath = true;
412
410413 // At this point, the next thing on the command line must be
411414 // the archive name.
412415 getArchive();
......@@ -965,6 +968,8 @@ static void createSymbolTable(object::Archive *OldArchive) {
965968 if (OldArchive->hasSymbolTable())
966969 return;
967970
971 if (OldArchive->isThin())
972 Thin = true;
968973 performWriteOperation(CreateSymTab, OldArchive, nullptr, nullptr);
969974}
970975
......@@ -1003,12 +1008,17 @@ static int performOperation(ArchiveOperation Operation,
10031008 fail("unable to open '" + ArchiveName + "': " + EC.message());
10041009
10051010 if (!EC) {
1006 Error Err = Error::success();
1007 object::Archive Archive(Buf.get()->getMemBufferRef(), Err);
1008 failIfError(std::move(Err), "unable to load '" + ArchiveName + "'");
1009 if (Archive.isThin())
1011 Expected<std::unique_ptr<object::Archive>> ArchiveOrError =
1012 object::Archive::create(Buf.get()->getMemBufferRef());
1013 if (!ArchiveOrError)
1014 failIfError(ArchiveOrError.takeError(),
1015 "unable to load '" + ArchiveName + "'");
1016
1017 std::unique_ptr<object::Archive> Archive = std::move(ArchiveOrError.get());
1018 if (Archive->isThin())
10101019 CompareFullPath = true;
1011 performOperation(Operation, &Archive, std::move(Buf.get()), NewMembers);
1020 performOperation(Operation, Archive.get(), std::move(Buf.get()),
1021 NewMembers);
10121022 return 0;
10131023 }
10141024
......@@ -1111,11 +1121,11 @@ static void runMRIScript() {
11111121}
11121122
11131123static bool handleGenericOption(StringRef arg) {
1114 if (arg == "-help" || arg == "--help" || arg == "-h") {
1124 if (arg == "--help" || arg == "-h") {
11151125 printHelpMessage();
11161126 return true;
11171127 }
1118 if (arg == "-version" || arg == "--version") {
1128 if (arg == "--version") {
11191129 cl::PrintVersionMessage();
11201130 return true;
11211131 }
......@@ -1129,8 +1139,6 @@ static const char *matchFlagWithArg(StringRef Expected,
11291139
11301140 if (Arg.startswith("--"))
11311141 Arg = Arg.substr(2);
1132 else if (Arg.startswith("-"))
1133 Arg = Arg.substr(1);
11341142
11351143 size_t len = Expected.size();
11361144 if (Arg == Expected) {
......@@ -1199,6 +1207,11 @@ static int ar_main(int argc, char **argv) {
11991207 continue;
12001208 }
12011209
1210 if (strcmp(*ArgIt, "--thin") == 0) {
1211 Thin = true;
1212 continue;
1213 }
1214
12021215 Match = matchFlagWithArg("format", ArgIt, Argv);
12031216 if (Match) {
12041217 FormatType = StringSwitch<Format>(Match)
......@@ -1261,16 +1274,8 @@ static int ranlib_main(int argc, char **argv) {
12611274 return performOperation(CreateSymTab, nullptr);
12621275}
12631276
1264extern "C" int ZigLlvmAr_main(int argc, char **argv);
1265int ZigLlvmAr_main(int argc, char **argv) {
1266 // ZIG PATCH: On Windows, InitLLVM calls GetCommandLineW(),
1267 // and overwrites the args. We don't want it to do that,
1268 // and we also don't need the signal handlers it installs
1269 // (we have our own already), so we just use llvm_shutdown_obj
1270 // instead.
1271 // InitLLVM X(argc, argv);
1272 llvm::llvm_shutdown_obj X;
1273
1277int main(int argc, char **argv) {
1278 InitLLVM X(argc, argv);
12741279 ToolName = argv[0];
12751280
12761281 llvm::InitializeAllTargetInfos();