[llvm] [Offload][PGO] Fix dump of array in ProfData (PR #122039)
Jinsong Ji via llvm-commits
llvm-commits at lists.llvm.org
Sat Jan 11 06:57:20 PST 2025
https://github.com/jsji updated https://github.com/llvm/llvm-project/pull/122039
>From 98dd814f138091143641c66fc4830cbb480aafa5 Mon Sep 17 00:00:00 2001
From: Jinsong Ji <jinsong.ji at intel.com>
Date: Tue, 7 Jan 2025 14:32:20 -0800
Subject: [PATCH 1/4] [Offload][PGO] Fix dump of array in ProfData
Exposed by -Warray-bounds:
In file included from ../../../../../../../llvm/offload/plugins-nextgen/common/src/GlobalHandler.cpp:252:
../../../../../../../llvm/llvm/include/llvm/ProfileData/InstrProfData.inc:109:1: error: array index 4 is past the end of the array (that has type 'const std::remove_const<const uint16_t>::type[4]' (aka 'const unsigned short[4]')) [-Werror,-Warray-bounds]
109 | INSTR_PROF_DATA(const uint16_t, Int16ArrayTy, NumValueSites[IPVK_Last+1], \
| ^ ~~~~~~~~~~~
../../../../../../../llvm/offload/plugins-nextgen/common/src/GlobalHandler.cpp:250:15: note: expanded from macro 'INSTR_PROF_DATA'
250 | outs() << ProfData.Name << " "; \
| ^ ~~~~
../../../../../../../llvm/llvm/include/llvm/ProfileData/InstrProfData.inc:109:1: note: array 'NumValueSites' declared here
109 | INSTR_PROF_DATA(const uint16_t, Int16ArrayTy, NumValueSites[IPVK_Last+1], \
| ^
../../../../../../../llvm/offload/plugins-nextgen/common/include/GlobalHandler.h:62:3: note: expanded from macro 'INSTR_PROF_DATA'
62 | std::remove_const<Type>::type Name;
Avoid accessing out-of-bound data, but skip printing array data for now.
As there is no simple way to do this without hardcoding the NumValueSites field.
---
offload/plugins-nextgen/common/src/GlobalHandler.cpp | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/offload/plugins-nextgen/common/src/GlobalHandler.cpp b/offload/plugins-nextgen/common/src/GlobalHandler.cpp
index 5acc94458bbd89..f02d97ce38552d 100644
--- a/offload/plugins-nextgen/common/src/GlobalHandler.cpp
+++ b/offload/plugins-nextgen/common/src/GlobalHandler.cpp
@@ -238,7 +238,11 @@ void GPUProfGlobals::dump() const {
for (const auto &ProfData : Data) {
outs() << "{ ";
#define INSTR_PROF_DATA(Type, LLVMType, Name, Initializer) \
- outs() << ProfData.Name << " ";
+ if (sizeof(#Name) > 2 && #Name[sizeof(#Name) - 2] == ']') { \
+ outs() << " [...]"; \
+ } else { \
+ outs() << ProfData.Name << " "; \
+ }
#include "llvm/ProfileData/InstrProfData.inc"
outs() << "}\n";
}
>From ccd310eb0388bf76ae55bf65e4c120b852fec243 Mon Sep 17 00:00:00 2001
From: Jinsong Ji <jinsong.ji at intel.com>
Date: Fri, 10 Jan 2025 07:09:36 -0800
Subject: [PATCH 2/4] Add comments
---
offload/plugins-nextgen/common/src/GlobalHandler.cpp | 3 +++
1 file changed, 3 insertions(+)
diff --git a/offload/plugins-nextgen/common/src/GlobalHandler.cpp b/offload/plugins-nextgen/common/src/GlobalHandler.cpp
index f02d97ce38552d..4bb71ae176594a 100644
--- a/offload/plugins-nextgen/common/src/GlobalHandler.cpp
+++ b/offload/plugins-nextgen/common/src/GlobalHandler.cpp
@@ -237,6 +237,9 @@ void GPUProfGlobals::dump() const {
outs() << "========== Data ===========\n";
for (const auto &ProfData : Data) {
outs() << "{ ";
+// The ProfData.Name maybe array, eg: NumValueSites[IPVK_Last+1] .
+// If we print out it directly, we are accessing out of bound data.
+// Skip dumping the array for now.
#define INSTR_PROF_DATA(Type, LLVMType, Name, Initializer) \
if (sizeof(#Name) > 2 && #Name[sizeof(#Name) - 2] == ']') { \
outs() << " [...]"; \
>From 098d8a72ef6c39f952c08505ef91108732a95512 Mon Sep 17 00:00:00 2001
From: Jinsong Ji <jinsong.ji at intel.com>
Date: Fri, 10 Jan 2025 11:03:22 -0800
Subject: [PATCH 3/4] Update test
---
offload/test/offloading/pgo1.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/offload/test/offloading/pgo1.c b/offload/test/offloading/pgo1.c
index c0d698323adf06..5dc1e5d95caf3d 100644
--- a/offload/test/offloading/pgo1.c
+++ b/offload/test/offloading/pgo1.c
@@ -36,15 +36,15 @@ int main() {
// CLANG-PGO-NEXT: { {{[0-9]*}} {{[0-9]*}}
// CLANG-PGO-SAME: {{0x[0-9a-fA-F]*}} {{0x[0-9a-fA-F]*}}
// CLANG-PGO-SAME: {{0x[0-9a-fA-F]*}} {{0x[0-9a-fA-F]*}}
-// CLANG-PGO-SAME: {{[0-9]*}} {{[0-9]*}} {{[0-9]*}} }
+// CLANG-PGO-SAME: {{[0-9]*}} {{.*}} {{[0-9]*}} }
// CLANG-PGO-NEXT: { {{[0-9]*}} {{[0-9]*}}
// CLANG-PGO-SAME: {{0x[0-9a-fA-F]*}} {{0x[0-9a-fA-F]*}}
// CLANG-PGO-SAME: {{0x[0-9a-fA-F]*}} {{0x[0-9a-fA-F]*}}
-// CLANG-PGO-SAME: {{[0-9]*}} {{[0-9]*}} {{[0-9]*}} }
+// CLANG-PGO-SAME: {{[0-9]*}} {{.*}} {{[0-9]*}} }
// CLANG-PGO-NEXT: { {{[0-9]*}} {{[0-9]*}}
// CLANG-PGO-SAME: {{0x[0-9a-fA-F]*}} {{0x[0-9a-fA-F]*}}
// CLANG-PGO-SAME: {{0x[0-9a-fA-F]*}} {{0x[0-9a-fA-F]*}}
-// CLANG-PGO-SAME: {{[0-9]*}} {{[0-9]*}} {{[0-9]*}} }
+// CLANG-PGO-SAME: {{[0-9]*}} {{.*}} {{[0-9]*}} }
// CLANG-PGO-NEXT: ======== Functions ========
// CLANG-PGO-NEXT: pgo1.c:
// CLANG-PGO-SAME: __omp_offloading_{{[_0-9a-zA-Z]*}}_main_{{[_0-9a-zA-Z]*}}
@@ -59,15 +59,15 @@ int main() {
// LLVM-PGO-NEXT: { {{[0-9]*}} {{[0-9]*}}
// LLVM-PGO-SAME: {{0x[0-9a-fA-F]*}} {{0x[0-9a-fA-F]*}}
// LLVM-PGO-SAME: {{0x[0-9a-fA-F]*}} {{0x[0-9a-fA-F]*}}
-// LLVM-PGO-SAME: {{[0-9]*}} {{[0-9]*}} {{[0-9]*}} }
+// LLVM-PGO-SAME: {{[0-9]*}} {{.*}} {{[0-9]*}} }
// LLVM-PGO-NEXT: { {{[0-9]*}} {{[0-9]*}}
// LLVM-PGO-SAME: {{0x[0-9a-fA-F]*}} {{0x[0-9a-fA-F]*}}
// LLVM-PGO-SAME: {{0x[0-9a-fA-F]*}} {{0x[0-9a-fA-F]*}}
-// LLVM-PGO-SAME: {{[0-9]*}} {{[0-9]*}} {{[0-9]*}} }
+// LLVM-PGO-SAME: {{[0-9]*}} {{.*}} {{[0-9]*}} }
// LLVM-PGO-NEXT: { {{[0-9]*}} {{[0-9]*}}
// LLVM-PGO-SAME: {{0x[0-9a-fA-F]*}} {{0x[0-9a-fA-F]*}}
// LLVM-PGO-SAME: {{0x[0-9a-fA-F]*}} {{0x[0-9a-fA-F]*}}
-// LLVM-PGO-SAME: {{[0-9]*}} {{[0-9]*}} {{[0-9]*}} }
+// LLVM-PGO-SAME: {{[0-9]*}} {{.*}} {{[0-9]*}} }
// LLVM-PGO-NEXT: ======== Functions ========
// LLVM-PGO-NEXT: __omp_offloading_{{[_0-9a-zA-Z]*}}_main_{{[_0-9a-zA-Z]*}}
// LLVM-PGO-NEXT: test1
>From 362b97af36848e6b6d795850d25a1c42b533c401 Mon Sep 17 00:00:00 2001
From: Jinsong Ji <jinsong.ji at intel.com>
Date: Sat, 11 Jan 2025 09:57:12 -0500
Subject: [PATCH 4/4] Update
offload/plugins-nextgen/common/src/GlobalHandler.cpp
Co-authored-by: Ethan Luis McDonough <ethanluismcdonough at gmail.com>
---
offload/plugins-nextgen/common/src/GlobalHandler.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/offload/plugins-nextgen/common/src/GlobalHandler.cpp b/offload/plugins-nextgen/common/src/GlobalHandler.cpp
index 4bb71ae176594a..8ad7f15990ac6a 100644
--- a/offload/plugins-nextgen/common/src/GlobalHandler.cpp
+++ b/offload/plugins-nextgen/common/src/GlobalHandler.cpp
@@ -242,7 +242,7 @@ void GPUProfGlobals::dump() const {
// Skip dumping the array for now.
#define INSTR_PROF_DATA(Type, LLVMType, Name, Initializer) \
if (sizeof(#Name) > 2 && #Name[sizeof(#Name) - 2] == ']') { \
- outs() << " [...]"; \
+ outs() << "[...] "; \
} else { \
outs() << ProfData.Name << " "; \
}
More information about the llvm-commits
mailing list