Author: Akira Hatanaka
Date: 2026-03-12T18:34:24-07:00
New Revision: 14e04edf0725e06cbb5fe72c8f8aa0a6112ee254

URL: 
https://github.com/llvm/llvm-project/commit/14e04edf0725e06cbb5fe72c8f8aa0a6112ee254
DIFF: 
https://github.com/llvm/llvm-project/commit/14e04edf0725e06cbb5fe72c8f8aa0a6112ee254.diff

LOG: Fix TranslateOpenMPTargetArgs dropping -mlinker-version (#186208)

TranslateOpenMPTargetArgs drops OPT_m_Group options, including
`-mlinker-version`, when the device triple differs from the host triple.
This can cause an assertion failure in MachO::getLinkerVersion when
running `offload-Xarch.c` and `openmp-offload-gpu.c` on Darwin as it
expects the linker version obtained via `-mlinker-version` and the
version cached during a previous invocation to match.

Fix this by preserving `-mlinker-version` when filtering OPT_m_Group
options.

The tests currently pass because 6758becb8f19 ("[ObjC] Support emission
of selector stubs calls instead of objc_msgSend."), which triggered the
assertion, was reverted. This fix is a prerequisite for reapplying that
commit.

Added: 
    

Modified: 
    clang/lib/Driver/ToolChain.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index ac66ccbae6f39..94913837f5339 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -1762,10 +1762,15 @@ llvm::opt::DerivedArgList 
*ToolChain::TranslateOpenMPTargetArgs(
     // matches the current toolchain triple. If it is not present
     // at all, target and host share a toolchain.
     if (A->getOption().matches(options::OPT_m_Group)) {
-      // Pass code object version to device toolchain
-      // to correctly set metadata in intermediate files.
+      // Pass certain options to the device toolchain even when the triple
+      // 
diff ers from the host: code object version must be passed to correctly
+      // set metadata in intermediate files; linker version must be passed
+      // because the Darwin toolchain requires the host and device linker
+      // versions to match (the host version is cached in
+      // MachO::getLinkerVersion).
       if (SameTripleAsHost ||
-          A->getOption().matches(options::OPT_mcode_object_version_EQ))
+          A->getOption().matches(options::OPT_mcode_object_version_EQ) ||
+          A->getOption().matches(options::OPT_mlinker_version_EQ))
         DAL->append(A);
       else
         Modified = true;


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

Reply via email to