[llvm] [Linker] Do not warn on data layout mismatch when the source module has none (PR #186098)
Paulius Velesko via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 15 05:24:45 PDT 2026
https://github.com/pvelesko updated https://github.com/llvm/llvm-project/pull/186098
>From 17d87423e2590a8138b7da929f2435e0a9b4392b Mon Sep 17 00:00:00 2001
From: Paulius Velesko <pvelesko at pglc.io>
Date: Tue, 28 Jul 2026 12:10:44 +0300
Subject: [PATCH 1/2] [Linker] Add test for data layout mismatch warning with
empty source layout
---
llvm/test/Linker/Inputs/datalayout-empty.ll | 3 +++
llvm/test/Linker/datalayout.ll | 10 ++++++++++
2 files changed, 13 insertions(+)
create mode 100644 llvm/test/Linker/Inputs/datalayout-empty.ll
diff --git a/llvm/test/Linker/Inputs/datalayout-empty.ll b/llvm/test/Linker/Inputs/datalayout-empty.ll
new file mode 100644
index 0000000000000..4b8bfc2b3961b
--- /dev/null
+++ b/llvm/test/Linker/Inputs/datalayout-empty.ll
@@ -0,0 +1,3 @@
+define void @from_empty_layout_module() {
+ ret void
+}
diff --git a/llvm/test/Linker/datalayout.ll b/llvm/test/Linker/datalayout.ll
index 8e71e3b8420c4..f87fd73783bcb 100644
--- a/llvm/test/Linker/datalayout.ll
+++ b/llvm/test/Linker/datalayout.ll
@@ -6,9 +6,19 @@
; RUN: llvm-link %s %S/Inputs/datalayout-b.ll -S -o - 2>%t.b.err
; RUN: cat %t.b.err | FileCheck --check-prefix=WARN-B %s
+; A module with no data layout has made no ABI commitments, so linking it
+; into a module that has one should not warn, matching how an empty source
+; target triple is treated.
+; Ensure t.c.err is non-empty.
+; RUN: echo foo > %t.c.err
+; RUN: llvm-link %S/Inputs/datalayout-b.ll %S/Inputs/datalayout-empty.ll -S -o - 2>>%t.c.err
+; RUN: FileCheck --check-prefix=WARN-C %s < %t.c.err
+
target datalayout = "e"
; WARN-A-NOT: warning
; WARN-B: warning: Linking two modules of different data layouts:
+
+; WARN-C-NOT: warning
>From d81aa47831a76815c65c0e04337c9afb35ef27c6 Mon Sep 17 00:00:00 2001
From: Paulius Velesko <pvelesko at pglc.io>
Date: Tue, 28 Jul 2026 12:20:53 +0300
Subject: [PATCH 2/2] [Linker] Do not warn on data layout mismatch when the
source module has none
A module with no data layout has made no ABI commitments, so linking it
into a module that has one leaves nothing to conflict with; the
destination's layout simply applies. This matches how an empty source
target triple is already treated, and mirrors the silent inheritance
that happens when the destination layout is the empty one.
The warning fired in practice when linking archives whose members are
empty modules, for example the empty device bitcode clang's static
device library handling extracts from host-only archives during HIP
-fgpu-rdc links (CHIP-SPV/chipStar#525).
archive-non-bitcode.test relied on the spurious warning to keep
FileCheck's input non-empty; allow empty input there now.
---
llvm/lib/Linker/IRMover.cpp | 6 +++++-
llvm/test/tools/llvm-link/archive-non-bitcode.test | 2 +-
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Linker/IRMover.cpp b/llvm/lib/Linker/IRMover.cpp
index 3b72b412d0b2e..670005db522b2 100644
--- a/llvm/lib/Linker/IRMover.cpp
+++ b/llvm/lib/Linker/IRMover.cpp
@@ -1500,7 +1500,11 @@ Error IRLinker::run() {
EnableDLWarning = !(SrcHasLibDeviceTriple && SrcHasLibDeviceDL);
}
- if (EnableDLWarning && (SrcM->getDataLayout() != DstM.getDataLayout())) {
+ // A source module without a data layout has made no ABI commitments, so
+ // there is nothing to conflict with; the destination's layout simply
+ // applies, matching how an empty source target triple is treated below.
+ if (EnableDLWarning && !SrcM->getDataLayoutStr().empty() &&
+ (SrcM->getDataLayout() != DstM.getDataLayout())) {
emitWarning("Linking two modules of different data layouts: '" +
SrcM->getModuleIdentifier() + "' is '" +
SrcM->getDataLayoutStr() + "' whereas '" +
diff --git a/llvm/test/tools/llvm-link/archive-non-bitcode.test b/llvm/test/tools/llvm-link/archive-non-bitcode.test
index 631b03290c687..4d63fde6ab5d5 100644
--- a/llvm/test/tools/llvm-link/archive-non-bitcode.test
+++ b/llvm/test/tools/llvm-link/archive-non-bitcode.test
@@ -3,7 +3,7 @@
# RUN: echo "This is not a bitcode file" > %t.not_bitcode.txt
# RUN: llvm-ar cr %t.a %t.f.bc %t.not_bitcode.txt %t.g.bc
# RUN: llvm-ar cr --format=gnu %t.empty.lib
-# RUN: llvm-link -ignore-non-bitcode %t.a %t.empty.lib -o %t.linked.bc 2>&1 | FileCheck --check-prefix CHECK_IGNORE_NON_BITCODE %s
+# RUN: llvm-link -ignore-non-bitcode %t.a %t.empty.lib -o %t.linked.bc 2>&1 | FileCheck --allow-empty --check-prefix CHECK_IGNORE_NON_BITCODE %s
# RUN: not llvm-link %t.a %t.empty.lib -o %t.linked2.bc 2>&1 | FileCheck --check-prefix CHECK_ERROR_BITCODE %s
# CHECK_ERROR_BITCODE: error: member of archive is not a bitcode file
More information about the llvm-commits
mailing list