[llvm] [Offload][PGO] Fix dump of array in ProfData (PR #122039)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 7 18:14:15 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-offload
Author: Jinsong Ji (jsji)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/122039.diff
1 Files Affected:
- (modified) offload/plugins-nextgen/common/src/GlobalHandler.cpp (+5-1)
``````````diff
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";
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/122039
More information about the llvm-commits
mailing list