diff --git a/compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c b/compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c --- a/compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c +++ b/compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c @@ -1,12 +1,18 @@ // REQUIRES: zlib // Value profiling is currently not supported in lightweight mode. -// RUN: %clang_pgogen -o %t -g -gdwarf-4 -mllvm --debug-info-correlate -mllvm --disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-main.cpp %S/../Inputs/instrprof-debug-info-correlate-foo.cpp -// RUN: env LLVM_PROFILE_FILE=%t.proflite %run %t -// RUN: llvm-profdata merge -o %t.profdata --debug-info=%t %t.proflite - // RUN: %clang_pgogen -o %t.normal -mllvm --disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-main.cpp %S/../Inputs/instrprof-debug-info-correlate-foo.cpp // RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t.normal // RUN: llvm-profdata merge -o %t.normal.profdata %t.profraw +// RUN: %clang_pgogen -o %t.d4 -g -gdwarf-4 -mllvm --debug-info-correlate -mllvm --disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-main.cpp %S/../Inputs/instrprof-debug-info-correlate-foo.cpp +// RUN: env LLVM_PROFILE_FILE=%t.d4.proflite %run %t.d4 +// RUN: llvm-profdata merge -o %t.d4.profdata --debug-info=%t.d4 %t.d4.proflite + +// RUN: diff %t.normal.profdata %t.d4.profdata + +// RUN: %clang_pgogen -o %t -g -mllvm --debug-info-correlate -mllvm --disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-main.cpp %S/../Inputs/instrprof-debug-info-correlate-foo.cpp +// RUN: env LLVM_PROFILE_FILE=%t.proflite %run %t +// RUN: llvm-profdata merge -o %t.profdata --debug-info=%t %t.proflite + // RUN: diff %t.normal.profdata %t.profdata diff --git a/llvm/lib/ProfileData/InstrProfCorrelator.cpp b/llvm/lib/ProfileData/InstrProfCorrelator.cpp --- a/llvm/lib/ProfileData/InstrProfCorrelator.cpp +++ b/llvm/lib/ProfileData/InstrProfCorrelator.cpp @@ -167,13 +167,19 @@ return {}; } auto &DU = *Die.getDwarfUnit(); + auto AddressSize = DU.getAddressByteSize(); for (auto &Location : *Locations) { - auto AddressSize = DU.getAddressByteSize(); DataExtractor Data(Location.Expr, DICtx->isLittleEndian(), AddressSize); DWARFExpression Expr(Data, AddressSize); - for (auto &Op : Expr) - if (Op.getCode() == dwarf::DW_OP_addr) + for (auto &Op : Expr) { + if (Op.getCode() == dwarf::DW_OP_addr) { return Op.getRawOperand(0); + } else if (Op.getCode() == dwarf::DW_OP_addrx) { + uint64_t Index = Op.getRawOperand(0); + if (auto SA = DU.getAddrOffsetSectionItem(Index)) + return SA->Address; + } + } } return {}; }