[llvm] [ThinLTO] Only replace uses in ExportM when promoting CFI functions (PR #229634)

via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 6 19:01:39 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lto

Author: Mircea Trofin (mtrofin)

<details>
<summary>Changes</summary>

addresses http://crbug.com/570039617

---
Full diff: https://github.com/llvm/llvm-project/pull/229634.diff


3 Files Affected:

- (modified) llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp (+2-2) 
- (modified) llvm/test/ThinLTO/X86/cfi-import-internal-coroutine.ll (+1-2) 
- (added) llvm/test/Transforms/ThinLTOBitcodeWriter/cfi-relative-vtable.ll (+36) 


``````````diff
diff --git a/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp b/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
index d9ec0a51f942f80..0010d94a17d6963 100644
--- a/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
+++ b/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
@@ -76,10 +76,10 @@ void promoteInternals(Module &ExportM, Module &ImportM, StringRef ModuleId,
         ExportGV.getValueType(), ExportGV.getAddressSpace(),
         GlobalValue::ExternalLinkage, NewName, Aliasee, &ExportM);
     ExternalAlias->setVisibility(GlobalValue::HiddenVisibility);
-    ExportGV.replaceUsesWithIf(
-        ExternalAlias, [](Use &U) { return !isa<GlobalAlias>(U.getUser()); });
 
     if (MustPromote) {
+      ExportGV.replaceUsesWithIf(
+          ExternalAlias, [](Use &U) { return !isa<GlobalAlias>(U.getUser()); });
       PromoteExtra->remove(&ExportGV);
       PromoteExtra->insert(ExternalAlias);
     }
diff --git a/llvm/test/ThinLTO/X86/cfi-import-internal-coroutine.ll b/llvm/test/ThinLTO/X86/cfi-import-internal-coroutine.ll
index 622db2b6a8f6fec..3fdf6a2a2423c81 100644
--- a/llvm/test/ThinLTO/X86/cfi-import-internal-coroutine.ll
+++ b/llvm/test/ThinLTO/X86/cfi-import-internal-coroutine.ll
@@ -21,8 +21,7 @@
 ; RUN: llvm-dis %t.dir/out.2.3.import.bc -o - | FileCheck %s --check-prefix=IMPORT
 
 ; IMPORT: define available_externally hidden ptr @coro.llvm.{{[0-9]+}}()
-; IMPORT-NEXT: %id = call token @llvm.coro.id(i32 8, ptr null, ptr nonnull @coro.b66cc3a748330e63b2451fa89522eb06, ptr null)
-; IMPORT: declare ptr @coro.b66cc3a748330e63b2451fa89522eb06()
+; IMPORT-NEXT: %id = call token @llvm.coro.id(i32 8, ptr null, ptr nonnull @coro.llvm.{{[0-9]+}}, ptr null)
 
 ;--- a.ll
 source_filename = "a.ll"
diff --git a/llvm/test/Transforms/ThinLTOBitcodeWriter/cfi-relative-vtable.ll b/llvm/test/Transforms/ThinLTOBitcodeWriter/cfi-relative-vtable.ll
new file mode 100644
index 000000000000000..c765f5eb6972362
--- /dev/null
+++ b/llvm/test/Transforms/ThinLTOBitcodeWriter/cfi-relative-vtable.ll
@@ -0,0 +1,36 @@
+; REQUIRES: x86-registered-target
+
+; Verify that promoting an internal relative vtable in ThinLTOBitcodeWriter
+; does not replace the vtable's self-reference in its own initializer with the
+; promoted alias, which would break AsmPrinter lowering of dso_local_equivalent.
+
+; RUN: opt -thinlto-bc -thinlto-split-lto-unit -o %t %s
+; RUN: llvm-modextract -b -n 0 -o - %t | llvm-dis | FileCheck --check-prefix=M0 %s
+; RUN: llvm-modextract -b -n 1 -o %t.m1.bc %t
+; RUN: llvm-dis -o - %t.m1.bc | FileCheck --check-prefix=M1 %s
+; RUN: llc -filetype=null %t.m1.bc
+
+target triple = "x86_64-unknown-linux-gnu"
+
+; M0: @rel_vtable.{{[0-9a-f]+}} = external hidden constant [1 x i32]
+; M0: @f.{{[0-9a-f]+}} = hidden alias void (), ptr @f
+; M0: define internal void @f()
+; M0: define ptr @use_rel()
+; M0-NEXT: ret ptr @rel_vtable.{{[0-9a-f]+}}
+
+; M1: @rel_vtable = internal constant [1 x i32] [i32 trunc (i64 sub (i64 ptrtoint (ptr dso_local_equivalent @f.{{[0-9a-f]+}} to i64), i64 ptrtoint (ptr @rel_vtable to i64)) to i32)]
+; M1: @rel_vtable.{{[0-9a-f]+}} = hidden alias [1 x i32], ptr @rel_vtable
+; M1: declare !guid !{{[0-9]+}} hidden void @f.{{[0-9a-f]+}}()
+ at rel_vtable = internal constant [1 x i32] [
+  i32 trunc (i64 sub (i64 ptrtoint (ptr dso_local_equivalent @f to i64), i64 ptrtoint (ptr @rel_vtable to i64)) to i32)
+], !type !0
+
+define internal void @f() {
+  ret void
+}
+
+define ptr @use_rel() {
+  ret ptr @rel_vtable
+}
+
+!0 = !{i32 0, !"typeid"}

``````````

</details>


https://github.com/llvm/llvm-project/pull/229634


More information about the llvm-commits mailing list