diff --git a/llvm/lib/ProfileData/SampleProfWriter.cpp b/llvm/lib/ProfileData/SampleProfWriter.cpp --- a/llvm/lib/ProfileData/SampleProfWriter.cpp +++ b/llvm/lib/ProfileData/SampleProfWriter.cpp @@ -252,6 +252,9 @@ } std::error_code SampleProfileWriterExtBinaryBase::writeCSNameTableSection() { + if (CSNameTable.empty()) + return sampleprof_error::success; + // Sort the names to make CSNameTable deterministic. std::set OrderedContexts; for (const auto &I : CSNameTable) diff --git a/llvm/test/tools/llvm-profgen/inline-noprobe2.test b/llvm/test/tools/llvm-profgen/inline-noprobe2.test --- a/llvm/test/tools/llvm-profgen/inline-noprobe2.test +++ b/llvm/test/tools/llvm-profgen/inline-noprobe2.test @@ -6,6 +6,7 @@ ; RUN: FileCheck %s --input-file %t --check-prefix=CHECK ; RUN: llvm-profgen --format=extbinary --perfscript=%S/Inputs/inline-noprobe2.perfscript --binary=%S/Inputs/inline-noprobe2.perfbin --output=%t +; RUN: llvm-profdata show --show-sec-info-only -sample %t | FileCheck %s --check-prefix=CHECK-SECTION-INFO ; RUN: llvm-profdata show -show-prof-sym-list -sample %t | FileCheck %s --check-prefix=CHECK-SYM-LIST ; CHECK-ARTIFICIAL-BRANCH: 3 @@ -16,6 +17,9 @@ ; CHECK-ARTIFICIAL-BRANCH: 400870->400540:2 ; CHECK-ARTIFICIAL-BRANCH: 4008bf->400870:2 +; CHECK-SECTION-INFO: CSNameTableSection - Offset: [[#]], Size: 0, Flags: {} +; CHECK-SECTION-INFO: FunctionMetadata - Offset: [[#]], Size: 0, Flags: {} + ; CHECK-SYM-LIST: Dump profile symbol list ; CHECK-SYM-LIST: main ; CHECK-SYM-LIST: partition_pivot_first