Skip to content

Commit 8d1d67e

Browse files
[Offload][PGO] Fix dump of array in ProfData (llvm#122039)
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. --------- Co-authored-by: Ethan Luis McDonough <[email protected]>
1 parent 43491f0 commit 8d1d67e

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

offload/plugins-nextgen/common/src/GlobalHandler.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,15 @@ void GPUProfGlobals::dump() const {
237237
outs() << "========== Data ===========\n";
238238
for (const auto &ProfData : Data) {
239239
outs() << "{ ";
240+
// The ProfData.Name maybe array, eg: NumValueSites[IPVK_Last+1] .
241+
// If we print out it directly, we are accessing out of bound data.
242+
// Skip dumping the array for now.
240243
#define INSTR_PROF_DATA(Type, LLVMType, Name, Initializer) \
241-
outs() << ProfData.Name << " ";
244+
if (sizeof(#Name) > 2 && #Name[sizeof(#Name) - 2] == ']') { \
245+
outs() << "[...] "; \
246+
} else { \
247+
outs() << ProfData.Name << " "; \
248+
}
242249
#include "llvm/ProfileData/InstrProfData.inc"
243250
outs() << "}\n";
244251
}

offload/test/offloading/pgo1.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ int main() {
3636
// CLANG-PGO-NEXT: { {{[0-9]*}} {{[0-9]*}}
3737
// CLANG-PGO-SAME: {{0x[0-9a-fA-F]*}} {{0x[0-9a-fA-F]*}}
3838
// CLANG-PGO-SAME: {{0x[0-9a-fA-F]*}} {{0x[0-9a-fA-F]*}}
39-
// CLANG-PGO-SAME: {{[0-9]*}} {{[0-9]*}} {{[0-9]*}} }
39+
// CLANG-PGO-SAME: {{[0-9]*}} {{.*}} {{[0-9]*}} }
4040
// CLANG-PGO-NEXT: { {{[0-9]*}} {{[0-9]*}}
4141
// CLANG-PGO-SAME: {{0x[0-9a-fA-F]*}} {{0x[0-9a-fA-F]*}}
4242
// CLANG-PGO-SAME: {{0x[0-9a-fA-F]*}} {{0x[0-9a-fA-F]*}}
43-
// CLANG-PGO-SAME: {{[0-9]*}} {{[0-9]*}} {{[0-9]*}} }
43+
// CLANG-PGO-SAME: {{[0-9]*}} {{.*}} {{[0-9]*}} }
4444
// CLANG-PGO-NEXT: { {{[0-9]*}} {{[0-9]*}}
4545
// CLANG-PGO-SAME: {{0x[0-9a-fA-F]*}} {{0x[0-9a-fA-F]*}}
4646
// CLANG-PGO-SAME: {{0x[0-9a-fA-F]*}} {{0x[0-9a-fA-F]*}}
47-
// CLANG-PGO-SAME: {{[0-9]*}} {{[0-9]*}} {{[0-9]*}} }
47+
// CLANG-PGO-SAME: {{[0-9]*}} {{.*}} {{[0-9]*}} }
4848
// CLANG-PGO-NEXT: ======== Functions ========
4949
// CLANG-PGO-NEXT: pgo1.c:
5050
// CLANG-PGO-SAME: __omp_offloading_{{[_0-9a-zA-Z]*}}_main_{{[_0-9a-zA-Z]*}}
@@ -59,15 +59,15 @@ int main() {
5959
// LLVM-PGO-NEXT: { {{[0-9]*}} {{[0-9]*}}
6060
// LLVM-PGO-SAME: {{0x[0-9a-fA-F]*}} {{0x[0-9a-fA-F]*}}
6161
// LLVM-PGO-SAME: {{0x[0-9a-fA-F]*}} {{0x[0-9a-fA-F]*}}
62-
// LLVM-PGO-SAME: {{[0-9]*}} {{[0-9]*}} {{[0-9]*}} }
62+
// LLVM-PGO-SAME: {{[0-9]*}} {{.*}} {{[0-9]*}} }
6363
// LLVM-PGO-NEXT: { {{[0-9]*}} {{[0-9]*}}
6464
// LLVM-PGO-SAME: {{0x[0-9a-fA-F]*}} {{0x[0-9a-fA-F]*}}
6565
// LLVM-PGO-SAME: {{0x[0-9a-fA-F]*}} {{0x[0-9a-fA-F]*}}
66-
// LLVM-PGO-SAME: {{[0-9]*}} {{[0-9]*}} {{[0-9]*}} }
66+
// LLVM-PGO-SAME: {{[0-9]*}} {{.*}} {{[0-9]*}} }
6767
// LLVM-PGO-NEXT: { {{[0-9]*}} {{[0-9]*}}
6868
// LLVM-PGO-SAME: {{0x[0-9a-fA-F]*}} {{0x[0-9a-fA-F]*}}
6969
// LLVM-PGO-SAME: {{0x[0-9a-fA-F]*}} {{0x[0-9a-fA-F]*}}
70-
// LLVM-PGO-SAME: {{[0-9]*}} {{[0-9]*}} {{[0-9]*}} }
70+
// LLVM-PGO-SAME: {{[0-9]*}} {{.*}} {{[0-9]*}} }
7171
// LLVM-PGO-NEXT: ======== Functions ========
7272
// LLVM-PGO-NEXT: __omp_offloading_{{[_0-9a-zA-Z]*}}_main_{{[_0-9a-zA-Z]*}}
7373
// LLVM-PGO-NEXT: test1

0 commit comments

Comments
 (0)