[llvm] 7ab6bc0 - [ThinLTO] Preserve Unicode characters in module paths when writing the combined-index (#194320)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 29 01:11:46 PDT 2026
Author: Ben Dunbobbin
Date: 2026-04-29T09:11:41+01:00
New Revision: 7ab6bc066cbb09ee9eebb60577317966eef6e796
URL: https://github.com/llvm/llvm-project/commit/7ab6bc066cbb09ee9eebb60577317966eef6e796
DIFF: https://github.com/llvm/llvm-project/commit/7ab6bc066cbb09ee9eebb60577317966eef6e796.diff
LOG: [ThinLTO] Preserve Unicode characters in module paths when writing the combined-index (#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 (#194318)
Based on work by @kbelochapka and @romanova-ekaterina.
Added:
llvm/test/Bitcode/thinlto-unicode-module-paths.test
Modified:
llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index 7153b1a0000fd..31b8367083087 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -4270,7 +4270,8 @@ void IndexBitcodeWriter::writeModStrings() {
auto ModuleId = ModuleIdMap.size();
ModuleIdMap[Key] = ModuleId;
Vals.push_back(ModuleId);
- Vals.append(Key.begin(), Key.end());
+ // Use bytes_begin/end() for unsigned char iteration.
+ 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