Skip to content

[Coverage] Use the proper endianness for reading profile data fields #136427

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llvm/include/llvm/ProfileData/InstrProfReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ class RawInstrProfReader : public InstrProfReader {
}

StringRef getName(uint64_t NameRef) const {
return Symtab->getFuncOrVarName(swap(NameRef));
return Symtab->getFuncOrVarName(Correlator ? NameRef : swap(NameRef));
}

int getCounterTypeSize() const {
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/ProfileData/InstrProfCorrelator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ void InstrProfCorrelatorImpl<IntPtrT>::addDataProbe(uint64_t NameRef,
maybeSwap<uint64_t>(CFGHash),
// In this mode, CounterPtr actually stores the section relative address
// of the counter.
maybeSwap<IntPtrT>(CounterOffset),
CounterOffset,
// TODO: MC/DC is not yet supported.
/*BitmapOffset=*/maybeSwap<IntPtrT>(0),
maybeSwap<IntPtrT>(FunctionPtr),
Expand Down
23 changes: 14 additions & 9 deletions llvm/lib/ProfileData/InstrProfReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,10 +553,11 @@ Error RawInstrProfReader<IntPtrT>::createSymtab(InstrProfSymtab &Symtab) {
StringRef(VNamesStart, VNamesEnd - VNamesStart)))
return error(std::move(E));
for (const RawInstrProf::ProfileData<IntPtrT> *I = Data; I != DataEnd; ++I) {
const IntPtrT FPtr = swap(I->FunctionPointer);
const IntPtrT FPtr =
Correlator ? I->FunctionPointer : swap(I->FunctionPointer);
if (!FPtr)
continue;
Symtab.mapAddress(FPtr, swap(I->NameRef));
Symtab.mapAddress(FPtr, Correlator ? I->NameRef : swap(I->NameRef));
}

if (VTableBegin != nullptr && VTableEnd != nullptr) {
Expand Down Expand Up @@ -711,18 +712,20 @@ Error RawInstrProfReader<IntPtrT>::readName(NamedInstrProfRecord &Record) {

template <class IntPtrT>
Error RawInstrProfReader<IntPtrT>::readFuncHash(NamedInstrProfRecord &Record) {
Record.Hash = swap(Data->FuncHash);
Record.Hash = Correlator ? Data->FuncHash : swap(Data->FuncHash);
return success();
}

template <class IntPtrT>
Error RawInstrProfReader<IntPtrT>::readRawCounts(
InstrProfRecord &Record) {
uint32_t NumCounters = swap(Data->NumCounters);
uint32_t NumCounters =
Correlator ? Data->NumCounters : swap(Data->NumCounters);
if (NumCounters == 0)
return error(instrprof_error::malformed, "number of counters is zero");

ptrdiff_t CounterBaseOffset = swap(Data->CounterPtr) - CountersDelta;
ptrdiff_t CounterBaseOffset =
Correlator ? Data->CounterPtr : swap(Data->CounterPtr) - CountersDelta;
if (CounterBaseOffset < 0)
return error(
instrprof_error::malformed,
Expand Down Expand Up @@ -754,8 +757,8 @@ Error RawInstrProfReader<IntPtrT>::readRawCounts(
uint64_t TimestampValue = swap(*reinterpret_cast<const uint64_t *>(Ptr));
if (TimestampValue != 0 &&
TimestampValue != std::numeric_limits<uint64_t>::max()) {
TemporalProfTimestamps.emplace_back(TimestampValue,
swap(Data->NameRef));
TemporalProfTimestamps.emplace_back(
TimestampValue, Correlator ? Data->NameRef : swap(Data->NameRef));
TemporalProfTraceStreamSize = 1;
}
if (hasSingleByteCoverage()) {
Expand Down Expand Up @@ -785,7 +788,8 @@ Error RawInstrProfReader<IntPtrT>::readRawCounts(

template <class IntPtrT>
Error RawInstrProfReader<IntPtrT>::readRawBitmapBytes(InstrProfRecord &Record) {
uint32_t NumBitmapBytes = swap(Data->NumBitmapBytes);
uint32_t NumBitmapBytes =
Correlator ? Data->NumBitmapBytes : swap(Data->NumBitmapBytes);

Record.BitmapBytes.clear();
Record.BitmapBytes.reserve(NumBitmapBytes);
Expand All @@ -796,7 +800,8 @@ Error RawInstrProfReader<IntPtrT>::readRawBitmapBytes(InstrProfRecord &Record) {
return success();

// BitmapDelta decreases as we advance to the next data record.
ptrdiff_t BitmapOffset = swap(Data->BitmapPtr) - BitmapDelta;
ptrdiff_t BitmapOffset =
Correlator ? Data->BitmapPtr : swap(Data->BitmapPtr) - BitmapDelta;
if (BitmapOffset < 0)
return error(
instrprof_error::malformed,
Expand Down