[llvm] WIP - [ThinLTO] Preserve Unicode characters in module paths when writing the combined-index (PR #194320)
Ben Dunbobbin via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 27 02:10:09 PDT 2026
https://github.com/bd1976bris created https://github.com/llvm/llvm-project/pull/194320
`IndexBitcodeWriter::writeModStrings()` serializes module path strings into a `SmallVector<unsigned>` before emitting `MST_CODE_ENTRY` records. When a path contains UTF-8 bytes with the high bit set, appending from `StringRef::begin()/end()` can be incorrect. Instead, append the module path through `bytes_begin()/bytes_end()`, so the bitcode writer always serializes unsigned bytes.
Fixes: https://github.com/llvm/llvm-project/issues/194318
>From f1c8668cc947c1719b2d77de8d3d9aa6a1087006 Mon Sep 17 00:00:00 2001
From: Ben <ben.dunbobbin at sony.com>
Date: Mon, 27 Apr 2026 09:13:23 +0100
Subject: [PATCH] [ThinLTO] Preserve Unicode characters in module paths
IndexBitcodeWriter::writeModStrings() serializes module path strings
into a SmallVector<unsigned> before emitting MST_CODE_ENTRY records.
When a path contains UTF-8 bytes with the high bit set, appending via
StringRef::begin()/end() can be incorrect. Instead, append the module
path using bytes_begin()/bytes_end() so the bitcode writer always
serializes unsigned bytes.
---
llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 2 +-
.../Bitcode/thinlto-unicode-module-paths.test | 18 ++++++++++++++++++
2 files changed, 19 insertions(+), 1 deletion(-)
create mode 100644 llvm/test/Bitcode/thinlto-unicode-module-paths.test
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index 71d5a8bc98a4b..a49beaf885e0e 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -4263,7 +4263,7 @@ void IndexBitcodeWriter::writeModStrings() {
auto ModuleId = ModuleIdMap.size();
ModuleIdMap[Key] = ModuleId;
Vals.push_back(ModuleId);
- Vals.append(Key.begin(), Key.end());
+ Vals.append(Key.bytes_begin(), Key.bytes_end());
// Emit the finished record.
Stream.EmitRecord(bitc::MST_CODE_ENTRY, Vals, AbbrevToUse);
diff --git a/llvm/test/Bitcode/thinlto-unicode-module-paths.test b/llvm/test/Bitcode/thinlto-unicode-module-paths.test
new file mode 100644
index 0000000000000..ef339286deda3
--- /dev/null
+++ b/llvm/test/Bitcode/thinlto-unicode-module-paths.test
@@ -0,0 +1,18 @@
+## Test that ThinLTO combined-index handles Unicode characters in module paths.
+
+RUN: rm -rf %t && split-file %s %t && cd %t
+RUN: opt -module-summary α.ll -o α.bc
+RUN: llvm-lto -thinlto-action=thinlink -o index.bc α.bc
+RUN: llvm-bcanalyzer -dump index.bc | FileCheck %s
+
+CHECK: <MODULE_STRTAB_BLOCK
+CHECK-NEXT: <ENTRY abbrevid=
+## UTF-8 for "α.bc" is CE B1 2E 62 63.
+CHECK-SAME: op1=206 op2=177 op3=46 op4=98 op5=99/>
+
+#--- α.ll
+target triple = "x86_64-unknown-linux-gnu"
+
+define i32 @f() {
+ ret i32 0
+}
More information about the llvm-commits
mailing list