Skip to content

Commit d4e8619

Browse files
authored
[CGData] Fix assertions when skipping name (#151570)
This fixes assertion failures when using `-indexed-codegen-data-read-function-map-names=false`
1 parent 1dec9b9 commit d4e8619

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

llvm/lib/CGData/StableFunctionMapRecord.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,18 @@ void StableFunctionMapRecord::deserialize(const unsigned char *&Ptr,
160160
for (unsigned I = 0; I < NumFuncs; ++I) {
161161
auto Hash =
162162
endian::readNext<stable_hash, endianness::little, unaligned>(Ptr);
163-
auto FunctionNameId =
163+
[[maybe_unused]] auto FunctionNameId =
164164
endian::readNext<uint32_t, endianness::little, unaligned>(Ptr);
165-
assert(FunctionMap->getNameForId(FunctionNameId) &&
166-
"FunctionNameId out of range");
167-
auto ModuleNameId =
165+
[[maybe_unused]] auto ModuleNameId =
168166
endian::readNext<uint32_t, endianness::little, unaligned>(Ptr);
169-
assert(FunctionMap->getNameForId(ModuleNameId) &&
170-
"ModuleNameId out of range");
167+
// Only validate IDs if we've read the names
168+
if (ReadStableFunctionMapNames) {
169+
assert(FunctionMap->getNameForId(FunctionNameId) &&
170+
"FunctionNameId out of range");
171+
assert(FunctionMap->getNameForId(ModuleNameId) &&
172+
"ModuleNameId out of range");
173+
}
174+
171175
auto InstCount =
172176
endian::readNext<uint32_t, endianness::little, unaligned>(Ptr);
173177

llvm/test/ThinLTO/AArch64/cgdata-merge-read.ll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@
3030
; RUN: llvm-objdump -d %tout-read.1 | FileCheck %s --check-prefix=THUNK1
3131
; RUN: llvm-objdump -d %tout-read.2 | FileCheck %s --check-prefix=THUNK2
3232

33+
; It runs the same if we use -indexed-codegen-data-read-function-map-names=false.
34+
; RUN: llvm-lto2 run -enable-global-merge-func=true \
35+
; RUN: -indexed-codegen-data-read-function-map-names=false \
36+
; RUN: -codegen-data-use-path=%tout.cgdata \
37+
; RUN: %t-foo.bc %t-goo.bc -o %tout-read \
38+
; RUN: -r %t-foo.bc,_f1,px \
39+
; RUN: -r %t-goo.bc,_f2,px \
40+
; RUN: -r %t-foo.bc,_g,l -r %t-foo.bc,_g1,l -r %t-foo.bc,_g2,l \
41+
; RUN: -r %t-goo.bc,_g,l -r %t-goo.bc,_g1,l -r %t-goo.bc,_g2,l
42+
; RUN: llvm-nm %tout-read.1 | FileCheck %s --check-prefix=READ1
43+
; RUN: llvm-nm %tout-read.2 | FileCheck %s --check-prefix=READ2
44+
; RUN: llvm-objdump -d %tout-read.1 | FileCheck %s --check-prefix=THUNK1
45+
; RUN: llvm-objdump -d %tout-read.2 | FileCheck %s --check-prefix=THUNK2
46+
3347
; READ1: _f1.Tgm
3448
; READ2: _f2.Tgm
3549

0 commit comments

Comments
 (0)