git: 4f2bdef80e8e - stable/14 - Merge llvm-project release/17.x llvmorg-17.0.2-0-gb2417f51dbbd

From: Dimitry Andric <dim_at_FreeBSD.org>
Date: Sun, 07 Jan 2024 17:50:26 UTC
The branch stable/14 has been updated by dim:

URL: https://cgit.FreeBSD.org/src/commit/?id=4f2bdef80e8ef59a7d4c8e32ab895613cf73ba22

commit 4f2bdef80e8ef59a7d4c8e32ab895613cf73ba22
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2023-10-04 18:24:05 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2024-01-07 17:46:18 +0000

    Merge llvm-project release/17.x llvmorg-17.0.2-0-gb2417f51dbbd
    
    This updates llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and
    openmp to llvmorg-17.0.2-0-gb2417f51dbbd.
    
    PR:             273753
    MFC after:      1 month
    
    (cherry picked from commit 3bd749dbd90cc3b95719b65393df5ca8a0fe919d)
---
 .../clang/lib/Driver/ToolChains/MinGW.cpp          |  7 ++--
 .../llvm-project/libcxx/include/__utility/pair.h   |  4 +--
 contrib/llvm-project/lld/COFF/Driver.cpp           | 42 +++++++++++-----------
 contrib/llvm-project/lld/Common/Filesystem.cpp     |  2 +-
 .../lib/CodeGen/TargetLoweringObjectFileImpl.cpp   |  2 +-
 lib/clang/include/VCSVersion.inc                   |  6 ++--
 lib/clang/include/lld/Common/Version.inc           |  2 +-
 lib/clang/include/llvm/Support/VCSRevision.h       |  2 +-
 8 files changed, 36 insertions(+), 31 deletions(-)

diff --git a/contrib/llvm-project/clang/lib/Driver/ToolChains/MinGW.cpp b/contrib/llvm-project/clang/lib/Driver/ToolChains/MinGW.cpp
index b47041dcca70..eaec1d22e6e5 100644
--- a/contrib/llvm-project/clang/lib/Driver/ToolChains/MinGW.cpp
+++ b/contrib/llvm-project/clang/lib/Driver/ToolChains/MinGW.cpp
@@ -699,8 +699,11 @@ void toolchains::MinGW::addClangTargetOptions(
     }
   }
 
-  if (Arg *A = DriverArgs.getLastArgNoClaim(options::OPT_mthreads))
-    A->ignoreTargetSpecific();
+  for (auto Opt : {options::OPT_mthreads, options::OPT_mwindows,
+                   options::OPT_mconsole, options::OPT_mdll}) {
+    if (Arg *A = DriverArgs.getLastArgNoClaim(Opt))
+      A->ignoreTargetSpecific();
+  }
 }
 
 void toolchains::MinGW::AddClangCXXStdlibIncludeArgs(
diff --git a/contrib/llvm-project/libcxx/include/__utility/pair.h b/contrib/llvm-project/libcxx/include/__utility/pair.h
index 43c9dbec737b..6b8c43dbe6e4 100644
--- a/contrib/llvm-project/libcxx/include/__utility/pair.h
+++ b/contrib/llvm-project/libcxx/include/__utility/pair.h
@@ -288,9 +288,9 @@ struct _LIBCPP_TEMPLATE_VIS pair
 
 #  if _LIBCPP_STD_VER >= 23
     // This is a workaround for http://llvm.org/PR60710. We should be able to remove it once Clang is fixed.
-    template <class _PairLike, bool _Enable = tuple_size<remove_cvref_t<_PairLike>>::value == 2>
+    template <class _PairLike>
     _LIBCPP_HIDE_FROM_ABI static constexpr bool __pair_like_explicit_wknd() {
-        if constexpr (tuple_size<remove_cvref_t<_PairLike>>::value == 2) {
+        if constexpr (__pair_like<_PairLike>) {
             return !is_convertible_v<decltype(std::get<0>(std::declval<_PairLike&&>())), first_type> ||
                    !is_convertible_v<decltype(std::get<1>(std::declval<_PairLike&&>())), second_type>;
         }
diff --git a/contrib/llvm-project/lld/COFF/Driver.cpp b/contrib/llvm-project/lld/COFF/Driver.cpp
index d7476e91e03e..e2f414f78ecb 100644
--- a/contrib/llvm-project/lld/COFF/Driver.cpp
+++ b/contrib/llvm-project/lld/COFF/Driver.cpp
@@ -342,8 +342,8 @@ void LinkerDriver::enqueueArchiveMember(const Archive::Child &c,
       CHECK(c.getFullName(),
             "could not get the filename for the member defining symbol " +
                 toCOFFString(ctx, sym));
-  auto future = std::make_shared<std::future<MBErrPair>>(
-      createFutureForFile(childName));
+  auto future =
+      std::make_shared<std::future<MBErrPair>>(createFutureForFile(childName));
   enqueueTask([=]() {
     auto mbOrErr = future->get();
     if (mbOrErr.second)
@@ -640,26 +640,24 @@ void LinkerDriver::detectWinSysRoot(const opt::InputArgList &Args) {
 void LinkerDriver::addClangLibSearchPaths(const std::string &argv0) {
   std::string lldBinary = sys::fs::getMainExecutable(argv0.c_str(), nullptr);
   SmallString<128> binDir(lldBinary);
-  sys::path::remove_filename(binDir); // remove lld-link.exe
+  sys::path::remove_filename(binDir);                 // remove lld-link.exe
   StringRef rootDir = sys::path::parent_path(binDir); // remove 'bin'
 
   SmallString<128> libDir(rootDir);
   sys::path::append(libDir, "lib");
-  // We need to prepend the paths here in order to make sure that we always
-  // try to link the clang versions of the builtins over the ones supplied by MSVC.
-  searchPaths.insert(searchPaths.begin(), saver().save(libDir.str()));
 
   // Add the resource dir library path
   SmallString<128> runtimeLibDir(rootDir);
-  sys::path::append(runtimeLibDir, "lib", "clang", std::to_string(LLVM_VERSION_MAJOR), "lib");
-  searchPaths.insert(searchPaths.begin(), saver().save(runtimeLibDir.str()));
-
+  sys::path::append(runtimeLibDir, "lib", "clang",
+                    std::to_string(LLVM_VERSION_MAJOR), "lib");
   // Resource dir + osname, which is hardcoded to windows since we are in the
   // COFF driver.
   SmallString<128> runtimeLibDirWithOS(runtimeLibDir);
   sys::path::append(runtimeLibDirWithOS, "windows");
-  searchPaths.insert(searchPaths.begin(), saver().save(runtimeLibDirWithOS.str()));
 
+  searchPaths.push_back(saver().save(runtimeLibDirWithOS.str()));
+  searchPaths.push_back(saver().save(runtimeLibDir.str()));
+  searchPaths.push_back(saver().save(libDir.str()));
 }
 
 void LinkerDriver::addWinSysRootLibSearchPaths() {
@@ -1145,8 +1143,7 @@ void LinkerDriver::parseOrderFile(StringRef arg) {
     if (set.count(s) == 0) {
       if (ctx.config.warnMissingOrderSymbol)
         warn("/order:" + arg + ": missing symbol: " + s + " [LNK4037]");
-    }
-    else
+    } else
       ctx.config.order[s] = INT_MIN + ctx.config.order.size();
   }
 
@@ -1313,8 +1310,8 @@ void LinkerDriver::parsePDBAltPath() {
     else if (var.equals_insensitive("%_ext%"))
       buf.append(binaryExtension);
     else {
-      warn("only %_PDB% and %_EXT% supported in /pdbaltpath:, keeping " +
-           var + " as literal");
+      warn("only %_PDB% and %_EXT% supported in /pdbaltpath:, keeping " + var +
+           " as literal");
       buf.append(var);
     }
 
@@ -1448,8 +1445,8 @@ getVFS(const opt::InputArgList &args) {
     return nullptr;
   }
 
-  if (auto ret = vfs::getVFSFromYAML(std::move(*bufOrErr), /*DiagHandler*/ nullptr,
-                             arg->getValue()))
+  if (auto ret = vfs::getVFSFromYAML(std::move(*bufOrErr),
+                                     /*DiagHandler*/ nullptr, arg->getValue()))
     return ret;
 
   error("Invalid vfs overlay");
@@ -1563,12 +1560,13 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
 
   // Construct search path list.
   searchPaths.emplace_back("");
+  // Prefer the Clang provided builtins over the ones bundled with MSVC.
+  addClangLibSearchPaths(argsArr[0]);
   for (auto *arg : args.filtered(OPT_libpath))
     searchPaths.push_back(arg->getValue());
   detectWinSysRoot(args);
   if (!args.hasArg(OPT_lldignoreenv) && !args.hasArg(OPT_winsysroot))
     addLibSearchPaths();
-  addClangLibSearchPaths(argsArr[0]);
 
   // Handle /ignore
   for (auto *arg : args.filtered(OPT_ignore)) {
@@ -2083,8 +2081,11 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
     raw_svector_ostream stream(buffer);
     stream << "Library search paths:\n";
 
-    for (StringRef path : searchPaths)
+    for (StringRef path : searchPaths) {
+      if (path == "")
+        path = "(cwd)";
       stream << "  " << path << "\n";
+    }
 
     message(buffer);
   }
@@ -2101,7 +2102,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
   // Handle /RELEASE
   if (args.hasArg(OPT_release))
     config->writeCheckSum = true;
-  
+
   // Handle /safeseh, x86 only, on by default, except for mingw.
   if (config->machine == I386) {
     config->safeSEH = args.hasFlag(OPT_safeseh, OPT_safeseh_no, !config->mingw);
@@ -2342,7 +2343,8 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
   std::vector<WrappedSymbol> wrapped = addWrappedSymbols(ctx, args);
   // Load more object files that might be needed for wrapped symbols.
   if (!wrapped.empty())
-    while (run());
+    while (run())
+      ;
 
   if (config->autoImport || config->stdcallFixup) {
     // MinGW specific.
diff --git a/contrib/llvm-project/lld/Common/Filesystem.cpp b/contrib/llvm-project/lld/Common/Filesystem.cpp
index 671b352a3f6b..c93353f2d292 100644
--- a/contrib/llvm-project/lld/Common/Filesystem.cpp
+++ b/contrib/llvm-project/lld/Common/Filesystem.cpp
@@ -57,7 +57,7 @@ void lld::unlinkAsync(StringRef path) {
   //
   // The code here allows LLD to work on all versions of Windows.
   // However, at Windows 10 1903 it seems that the behavior of
-  // Windows has changed, so that we could simply delete the output 
+  // Windows has changed, so that we could simply delete the output
   // file. This code should be simplified once support for older
   // versions of Windows is dropped.
   //
diff --git a/contrib/llvm-project/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/contrib/llvm-project/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index 55fb522554fa..4ffffd85ee53 100644
--- a/contrib/llvm-project/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/contrib/llvm-project/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -855,7 +855,7 @@ static MCSectionELF *selectELFSectionForGlobal(
     Group = C->getName();
     IsComdat = C->getSelectionKind() == Comdat::Any;
   }
-  if (isa<GlobalVariable>(GO)) {
+  if (isa<GlobalVariable>(GO) && !cast<GlobalVariable>(GO)->isThreadLocal()) {
     if (TM.isLargeData()) {
       assert(TM.getTargetTriple().getArch() == Triple::x86_64);
       Flags |= ELF::SHF_X86_64_LARGE;
diff --git a/lib/clang/include/VCSVersion.inc b/lib/clang/include/VCSVersion.inc
index c4338e330ee5..09e5bd0806a8 100644
--- a/lib/clang/include/VCSVersion.inc
+++ b/lib/clang/include/VCSVersion.inc
@@ -1,8 +1,8 @@
-#define LLVM_REVISION "llvmorg-17.0.1-25-g098e653a5bed"
+#define LLVM_REVISION "llvmorg-17.0.2-0-gb2417f51dbbd"
 #define LLVM_REPOSITORY "https://github.com/llvm/llvm-project.git"
 
-#define CLANG_REVISION "llvmorg-17.0.1-25-g098e653a5bed"
+#define CLANG_REVISION "llvmorg-17.0.2-0-gb2417f51dbbd"
 #define CLANG_REPOSITORY "https://github.com/llvm/llvm-project.git"
 
-#define LLDB_REVISION "llvmorg-17.0.1-25-g098e653a5bed"
+#define LLDB_REVISION "llvmorg-17.0.2-0-gb2417f51dbbd"
 #define LLDB_REPOSITORY "https://github.com/llvm/llvm-project.git"
diff --git a/lib/clang/include/lld/Common/Version.inc b/lib/clang/include/lld/Common/Version.inc
index d8b1ac96c623..722673ac78da 100644
--- a/lib/clang/include/lld/Common/Version.inc
+++ b/lib/clang/include/lld/Common/Version.inc
@@ -1,4 +1,4 @@
 // Local identifier in __FreeBSD_version style
 #define LLD_FREEBSD_VERSION 1400006
 
-#define LLD_VERSION_STRING "17.0.2 (FreeBSD llvmorg-17.0.1-25-g098e653a5bed-" __XSTRING(LLD_FREEBSD_VERSION) ")"
+#define LLD_VERSION_STRING "17.0.2 (FreeBSD llvmorg-17.0.2-0-gb2417f51dbbd-" __XSTRING(LLD_FREEBSD_VERSION) ")"
diff --git a/lib/clang/include/llvm/Support/VCSRevision.h b/lib/clang/include/llvm/Support/VCSRevision.h
index 796a12cb1ea0..846d3cb3e014 100644
--- a/lib/clang/include/llvm/Support/VCSRevision.h
+++ b/lib/clang/include/llvm/Support/VCSRevision.h
@@ -1,2 +1,2 @@
-#define LLVM_REVISION "llvmorg-17.0.1-25-g098e653a5bed"
+#define LLVM_REVISION "llvmorg-17.0.2-0-gb2417f51dbbd"
 #define LLVM_REPOSITORY "https://github.com/llvm/llvm-project.git"