[llvm] [CGData] Fix assertions when skipping name (PR #151570)
Kyungwoo Lee via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 31 11:26:13 PDT 2025
https://github.com/kyulee-com updated https://github.com/llvm/llvm-project/pull/151570
>From e9c1242b4cdb275caa041ff76c6335c59156f663 Mon Sep 17 00:00:00 2001
From: Kyungwoo Lee <kyulee at meta.com>
Date: Thu, 31 Jul 2025 10:53:59 -0700
Subject: [PATCH 1/2] [CGData] Fix assertions when skipping name
This fixes assertion failures when using `-indexed-codegen-data-read-function-map-names=false`
---
llvm/lib/CGData/StableFunctionMapRecord.cpp | 14 ++++++++++----
llvm/test/ThinLTO/AArch64/cgdata-merge-read.ll | 16 ++++++++++++++++
2 files changed, 26 insertions(+), 4 deletions(-)
diff --git a/llvm/lib/CGData/StableFunctionMapRecord.cpp b/llvm/lib/CGData/StableFunctionMapRecord.cpp
index 4e4fceffb52b5..0c060bdbf27bc 100644
--- a/llvm/lib/CGData/StableFunctionMapRecord.cpp
+++ b/llvm/lib/CGData/StableFunctionMapRecord.cpp
@@ -162,12 +162,18 @@ void StableFunctionMapRecord::deserialize(const unsigned char *&Ptr,
endian::readNext<stable_hash, endianness::little, unaligned>(Ptr);
auto FunctionNameId =
endian::readNext<uint32_t, endianness::little, unaligned>(Ptr);
- assert(FunctionMap->getNameForId(FunctionNameId) &&
- "FunctionNameId out of range");
+ (void)FunctionNameId;
auto ModuleNameId =
endian::readNext<uint32_t, endianness::little, unaligned>(Ptr);
- assert(FunctionMap->getNameForId(ModuleNameId) &&
- "ModuleNameId out of range");
+ (void)ModuleNameId;
+ // Only validate IDs if we've read the names
+ if (ReadStableFunctionMapNames) {
+ assert(FunctionMap->getNameForId(FunctionNameId) &&
+ "FunctionNameId out of range");
+ assert(FunctionMap->getNameForId(ModuleNameId) &&
+ "ModuleNameId out of range");
+ }
+
auto InstCount =
endian::readNext<uint32_t, endianness::little, unaligned>(Ptr);
diff --git a/llvm/test/ThinLTO/AArch64/cgdata-merge-read.ll b/llvm/test/ThinLTO/AArch64/cgdata-merge-read.ll
index da756e7f15e68..37113028240e8 100644
--- a/llvm/test/ThinLTO/AArch64/cgdata-merge-read.ll
+++ b/llvm/test/ThinLTO/AArch64/cgdata-merge-read.ll
@@ -1,3 +1,5 @@
+; REQUIRES: asserts
+
; This test demonstrates how similar functions are handled during global outlining.
; Currently, we do not attempt to share an merged function for identical sequences.
; Instead, each merging instance is created uniquely.
@@ -30,6 +32,20 @@
; RUN: llvm-objdump -d %tout-read.1 | FileCheck %s --check-prefix=THUNK1
; RUN: llvm-objdump -d %tout-read.2 | FileCheck %s --check-prefix=THUNK2
+; It runs the same if we use -indexed-codegen-data-read-function-map-names=false.
+; RUN: llvm-lto2 run -enable-global-merge-func=true \
+; RUN: -indexed-codegen-data-read-function-map-names=false \
+; RUN: -codegen-data-use-path=%tout.cgdata \
+; RUN: %t-foo.bc %t-goo.bc -o %tout-read \
+; RUN: -r %t-foo.bc,_f1,px \
+; RUN: -r %t-goo.bc,_f2,px \
+; RUN: -r %t-foo.bc,_g,l -r %t-foo.bc,_g1,l -r %t-foo.bc,_g2,l \
+; RUN: -r %t-goo.bc,_g,l -r %t-goo.bc,_g1,l -r %t-goo.bc,_g2,l
+; RUN: llvm-nm %tout-read.1 | FileCheck %s --check-prefix=READ1
+; RUN: llvm-nm %tout-read.2 | FileCheck %s --check-prefix=READ2
+; RUN: llvm-objdump -d %tout-read.1 | FileCheck %s --check-prefix=THUNK1
+; RUN: llvm-objdump -d %tout-read.2 | FileCheck %s --check-prefix=THUNK2
+
; READ1: _f1.Tgm
; READ2: _f2.Tgm
>From 4e3a0d514777297e62905d9d72f3e882479eafdc Mon Sep 17 00:00:00 2001
From: Kyungwoo Lee <kyulee at meta.com>
Date: Thu, 31 Jul 2025 11:24:13 -0700
Subject: [PATCH 2/2] Address comments from Ellis
---
llvm/lib/CGData/StableFunctionMapRecord.cpp | 6 ++----
llvm/test/ThinLTO/AArch64/cgdata-merge-read.ll | 2 --
2 files changed, 2 insertions(+), 6 deletions(-)
diff --git a/llvm/lib/CGData/StableFunctionMapRecord.cpp b/llvm/lib/CGData/StableFunctionMapRecord.cpp
index 0c060bdbf27bc..423e068023088 100644
--- a/llvm/lib/CGData/StableFunctionMapRecord.cpp
+++ b/llvm/lib/CGData/StableFunctionMapRecord.cpp
@@ -160,12 +160,10 @@ void StableFunctionMapRecord::deserialize(const unsigned char *&Ptr,
for (unsigned I = 0; I < NumFuncs; ++I) {
auto Hash =
endian::readNext<stable_hash, endianness::little, unaligned>(Ptr);
- auto FunctionNameId =
+ [[maybe_unused]] auto FunctionNameId =
endian::readNext<uint32_t, endianness::little, unaligned>(Ptr);
- (void)FunctionNameId;
- auto ModuleNameId =
+ [[maybe_unused]] auto ModuleNameId =
endian::readNext<uint32_t, endianness::little, unaligned>(Ptr);
- (void)ModuleNameId;
// Only validate IDs if we've read the names
if (ReadStableFunctionMapNames) {
assert(FunctionMap->getNameForId(FunctionNameId) &&
diff --git a/llvm/test/ThinLTO/AArch64/cgdata-merge-read.ll b/llvm/test/ThinLTO/AArch64/cgdata-merge-read.ll
index 37113028240e8..9eb9bda0b54d7 100644
--- a/llvm/test/ThinLTO/AArch64/cgdata-merge-read.ll
+++ b/llvm/test/ThinLTO/AArch64/cgdata-merge-read.ll
@@ -1,5 +1,3 @@
-; REQUIRES: asserts
-
; This test demonstrates how similar functions are handled during global outlining.
; Currently, we do not attempt to share an merged function for identical sequences.
; Instead, each merging instance is created uniquely.
More information about the llvm-commits
mailing list