diff --git a/llvm/include/llvm/ProfileData/SampleProf.h b/llvm/include/llvm/ProfileData/SampleProf.h index 043e402603075..124e07a930711 100644 --- a/llvm/include/llvm/ProfileData/SampleProf.h +++ b/llvm/include/llvm/ProfileData/SampleProf.h @@ -149,8 +149,9 @@ static inline std::string getSecName(SecType Type) { return "CSNameTableSection"; case SecLBRProfile: return "LBRProfileSection"; + default: + return "UnknownSection"; } - llvm_unreachable("A SecType has no name for output"); } // Entry type of section header table used by SampleProfileExtBinaryBaseReader diff --git a/llvm/include/llvm/ProfileData/SampleProfReader.h b/llvm/include/llvm/ProfileData/SampleProfReader.h index f9a7830335bb7..169ba28965fb3 100644 --- a/llvm/include/llvm/ProfileData/SampleProfReader.h +++ b/llvm/include/llvm/ProfileData/SampleProfReader.h @@ -786,6 +786,8 @@ class SampleProfileReaderExtBinary : public SampleProfileReaderExtBinaryBase { virtual std::error_code verifySPMagic(uint64_t Magic) override; virtual std::error_code readCustomSection(const SecHdrTableEntry &Entry) override { + // Update the data reader pointer to the end of the section. + Data += Entry.Size; return sampleprof_error::success; }; diff --git a/llvm/test/tools/llvm-profdata/Inputs/unknown.section.extbin.profdata b/llvm/test/tools/llvm-profdata/Inputs/unknown.section.extbin.profdata new file mode 100644 index 0000000000000..b7d0ddbf36573 Binary files /dev/null and b/llvm/test/tools/llvm-profdata/Inputs/unknown.section.extbin.profdata differ diff --git a/llvm/test/tools/llvm-profdata/forward-compatible.test b/llvm/test/tools/llvm-profdata/forward-compatible.test new file mode 100644 index 0000000000000..50c79a0d3e511 --- /dev/null +++ b/llvm/test/tools/llvm-profdata/forward-compatible.test @@ -0,0 +1,26 @@ +RUN: llvm-profdata show -sample %S/Inputs/unknown.section.extbin.profdata | FileCheck %s +RUN: llvm-profdata show -sample -show-sec-info-only %S/Inputs/unknown.section.extbin.profdata | FileCheck %s -check-prefix=HDR + +# The input unknown.section.extbin.profdata contains an unknown section type +# which uses an enum value which won't be used in the near future. Check +# llvm-profdata can read it without problem. This is to ensure adding new +# section in extbinary format for SampleFDO won't cause forward compatibility +# issue. + +CHECK: Function: main: 366846, 0, 3 sampled lines +CHECK-NEXT: Samples collected in the function's body { +CHECK-NEXT: 2.1: 60401 +CHECK-NEXT: 3: 0 +CHECK-NEXT: 4: 0 +CHECK-NEXT: } + +HDR: ProfileSummarySection - Offset: 242, Size: 121, Flags: {} +HDR-NEXT: NameTableSection - Offset: 363, Size: 6, Flags: {} +HDR-NEXT: UnknownSection - Offset: 369, Size: 1, Flags: {} +HDR-NEXT: FuncOffsetTableSection - Offset: 391, Size: 3, Flags: {} +HDR-NEXT: LBRProfileSection - Offset: 370, Size: 21, Flags: {} +HDR-NEXT: ProfileSymbolListSection - Offset: 391, Size: 0, Flags: {} +HDR-NEXT: FunctionMetadata - Offset: 394, Size: 0, Flags: {} +HDR-NEXT: Header Size: 242 +HDR-NEXT: Total Sections Size: 152 +HDR-NEXT: File Size: 394