https://github.com/am11 updated https://github.com/llvm/llvm-project/pull/206477

>From 67c487c5e3df39375424ee18affb601aaae35070 Mon Sep 17 00:00:00 2001
From: Adeel Mujahid <[email protected]>
Date: Mon, 29 Jun 2026 16:02:53 +0300
Subject: [PATCH 1/3] [Driver] Find vendor-prefixed musl GCC toolchains

---
 clang/lib/Driver/ToolChains/Gnu.cpp | 32 +++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index b58c10145e7f3..0f42ec188424d 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -2206,6 +2206,38 @@ void Generic_GCC::GCCInstallationDetector::init(
       for (StringRef Candidate : CandidateTripleAliases)
         ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate, false,
                                GCCDirExists, GCCCrossDirExists);
+
+      // Some musl distributions embed a vendor name in their GCC triple that a
+      // neutral --target cannot spell. For example Alpine ships its toolchain
+      // under <arch>-alpine-linux-musl[abi] (e.g. aarch64-alpine-linux-musl,
+      // armv7-alpine-linux-musleabihf), so --target=aarch64-linux-musl or
+      // --target=armv7-linux-musleabihf would otherwise fail to find it.
+      // Enumerate the GCC triple directories and try any entry whose
+      // architecture, OS and environment match the target, ignoring the vendor
+      // field. ScanLibDirForGCCTriple already de-duplicates installations, so
+      // candidates also covered above are harmless. Skip this when the user
+      // pinned an explicit --gcc-triple.
+      if (TargetTriple.isMusl() && !Args.hasArg(options::OPT_gcc_triple_EQ)) {
+        for (const char *GCCDir : {"/gcc", "/gcc-cross"}) {
+          if ((StringRef(GCCDir) == "/gcc" && !GCCDirExists) ||
+              (StringRef(GCCDir) == "/gcc-cross" && !GCCCrossDirExists))
+            continue;
+          std::error_code EC;
+          for (llvm::vfs::directory_iterator
+                   LI = VFS.dir_begin(LibDir + GCCDir, EC),
+                   LE;
+               !EC && LI != LE; LI = LI.increment(EC)) {
+            StringRef Name = llvm::sys::path::filename(LI->path());
+            llvm::Triple CandidateTriple(Name);
+            if (CandidateTriple.getArch() == TargetTriple.getArch() &&
+                CandidateTriple.getOS() == TargetTriple.getOS() &&
+                CandidateTriple.getEnvironment() ==
+                    TargetTriple.getEnvironment())
+              ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Name, false,
+                                     GCCDirExists, GCCCrossDirExists);
+          }
+        }
+      }
     }
     for (StringRef Suffix : CandidateBiarchLibDirs) {
       const std::string LibDir = Prefix + Suffix.str();

>From 8305cbdda6059d3cb1cb405945649dd4bf968696 Mon Sep 17 00:00:00 2001
From: Adeel Mujahid <[email protected]>
Date: Mon, 29 Jun 2026 16:04:09 +0300
Subject: [PATCH 2/3] .

---
 .../Driver/linux-musl-alpine-gcc-detect.c     | 23 +++++++++++++++++++
 1 file changed, 23 insertions(+)
 create mode 100644 clang/test/Driver/linux-musl-alpine-gcc-detect.c

diff --git a/clang/test/Driver/linux-musl-alpine-gcc-detect.c 
b/clang/test/Driver/linux-musl-alpine-gcc-detect.c
new file mode 100644
index 0000000000000..a902bad65f442
--- /dev/null
+++ b/clang/test/Driver/linux-musl-alpine-gcc-detect.c
@@ -0,0 +1,23 @@
+// Alpine Linux ships its GCC toolchain under a vendor-prefixed musl triple
+// (e.g. aarch64-alpine-linux-musl, armv7-alpine-linux-musleabihf). Verify that
+// a neutral --target=<arch>-linux-musl[abi] still locates it, matching the
+// behavior of the exact Alpine triple.
+// See https://github.com/llvm/llvm-project/issues/89146
+
+// RUN: %clang -### %s --target=aarch64-linux-musl --rtlib=libgcc -no-pie \
+// RUN:     --sysroot=%S/Inputs/alpine_aarch64_musl_tree 2>&1 \
+// RUN:   | FileCheck --check-prefix=AARCH64 %s
+// RUN: %clang -### %s --target=aarch64-alpine-linux-musl --rtlib=libgcc 
-no-pie \
+// RUN:     --sysroot=%S/Inputs/alpine_aarch64_musl_tree 2>&1 \
+// RUN:   | FileCheck --check-prefix=AARCH64 %s
+// AARCH64: 
"{{[^"]*}}/usr/lib/gcc/aarch64-alpine-linux-musl/13.2.1{{/|\\\\}}crtbegin.o"
+
+// RUN: %clang -### %s --target=armv7-linux-musleabihf --rtlib=libgcc -no-pie \
+// RUN:     --sysroot=%S/Inputs/alpine_armv7_musl_tree 2>&1 \
+// RUN:   | FileCheck --check-prefix=ARMHF %s
+// RUN: %clang -### %s --target=armv7-alpine-linux-musleabihf --rtlib=libgcc 
-no-pie \
+// RUN:     --sysroot=%S/Inputs/alpine_armv7_musl_tree 2>&1 \
+// RUN:   | FileCheck --check-prefix=ARMHF %s
+// ARMHF: 
"{{[^"]*}}/usr/lib/gcc/armv7-alpine-linux-musleabihf/13.2.1{{/|\\\\}}crtbegin.o"
+
+int main(void) {}

>From b596764181c79f363b8bbb300e8d931b19497241 Mon Sep 17 00:00:00 2001
From: Adeel Mujahid <[email protected]>
Date: Mon, 29 Jun 2026 16:04:44 +0300
Subject: [PATCH 3/3] Update ReleaseNotes.rst

---
 clang/docs/ReleaseNotes.rst | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a2eef75e2a719..eb6e6f41ef4aa 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -71,17 +71,6 @@ C/C++ Language Potentially Breaking Changes
   Clang would previously ``break`` out of the ``while`` loop, whereas GCC 
(since version 9) would
   ``break`` out of the ``for`` loop here. Now, Clang and GCC both break out of 
the ``for`` loop.
 
-- Clang now parses line and digit directives, module names, and original 
filenames as unevaluated
-  strings. This means that code containing strings with escape sequences such 
as
-
-  .. code-block:: c++
-
-    # 1 "original\x12source.c"
-    #pragma clang module import "\x41"
-    # 50 "a\012.c"
-
-  are now ill-formed.
-
 C++ Specific Potentially Breaking Changes
 -----------------------------------------
 
@@ -346,6 +335,11 @@ Non-comprehensive list of changes in this release
 - Linux and Windows toolchains now support Clang multilibs using
   ``-fmultilib-flag=``.
 
+- The GCC installation detector now finds vendor-prefixed musl toolchains, such
+  as Alpine Linux's ``<arch>-alpine-linux-musl[abi]``, when given a neutral
+  ``--target=<arch>-linux-musl[abi]``. Previously this only worked when the
+  exact distribution triple was passed. (#GH89146)
+
 - The SafeStack builtins ``__builtin___get_unsafe_stack_ptr``,
   ``__builtin___get_unsafe_stack_bottom``, 
``__builtin___get_unsafe_stack_top``,
   and ``__builtin___get_unsafe_stack_start`` are now deprecated. Use the
@@ -538,9 +532,7 @@ Attribute Changes in Clang
   ISO 18037 fixed-point ``printf`` specifiers.
 
 - The ``const`` and ``pure`` attributes only apply to functions; they are now
-  diagnosed and ignored when applied to anything else. Additionally, calling
-  a function marked ``noreturn`` from a function marked ``const`` or ``pure``
-  is now diagnosed as undefined behavior (#GH129022).
+  diagnosed and ignored when applied to anything else.
 
 Improvements to Clang's diagnostics
 -----------------------------------

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to