[llvm] [llvm-profgen] Reject incompatible ExtBinary section flags (PR #215470)

via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 10 23:29:59 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-pgo

Author: Sergey Shcherbinin (SergeyShch01)

<details>
<summary>Changes</summary>

Reject section-specific ExtBinary flags that do not belong to the given section type, instead of silently accepting the mismatch. A death unit test covers applying SecFlagOrdered to SecLBRProfile.

---
Full diff: https://github.com/llvm/llvm-project/pull/215470.diff


2 Files Affected:

- (modified) llvm/include/llvm/ProfileData/SampleProf.h (+2-1) 
- (modified) llvm/unittests/ProfileData/SampleProfTest.cpp (+10) 


``````````diff
diff --git a/llvm/include/llvm/ProfileData/SampleProf.h b/llvm/include/llvm/ProfileData/SampleProf.h
index eaf347b62b24e..766212d327ff6 100644
--- a/llvm/include/llvm/ProfileData/SampleProf.h
+++ b/llvm/include/llvm/ProfileData/SampleProf.h
@@ -277,10 +277,11 @@ static inline void verifySecFlag(SecType Type, SecFlagType Flag) {
   case SecFuncMetadata:
     IsFlagLegal = std::is_same<SecFuncMetadataFlags, SecFlagType>();
     break;
-  default:
   case SecFuncOffsetTable:
     IsFlagLegal = std::is_same<SecFuncOffsetFlags, SecFlagType>();
     break;
+  default:
+    break;
   }
   if (!IsFlagLegal)
     llvm_unreachable("Misuse of a flag in an incompatible section");
diff --git a/llvm/unittests/ProfileData/SampleProfTest.cpp b/llvm/unittests/ProfileData/SampleProfTest.cpp
index d35427478e129..5268b32d62427 100644
--- a/llvm/unittests/ProfileData/SampleProfTest.cpp
+++ b/llvm/unittests/ProfileData/SampleProfTest.cpp
@@ -686,6 +686,16 @@ TEST_F(SampleProfTest, SampleProfileFuncOffsetTableOnDisk) {
   EXPECT_EQ(Table.lookup(0x9999999999999999ULL), std::nullopt);
 }
 
+#if defined(GTEST_HAS_DEATH_TEST) && !defined(NDEBUG)
+// Verify that function-offset flags are rejected for unrelated section types.
+TEST(SampleProfSectionFlagTest, RejectsMismatchedSectionSpecificFlag) {
+  SecHdrTableEntry Entry{SecLBRProfile, 0, 0, 0, 0};
+  EXPECT_DEATH(
+      static_cast<void>(hasSecFlag(Entry, SecFuncOffsetFlags::SecFlagOrdered)),
+      "Misuse of a flag in an incompatible section");
+}
+#endif
+
 // Verify that requesting format version 103 results in a version 103 profile.
 TEST_F(SampleProfTest, SampleProfileFormatVersion103) {
   auto BufferOrErr = writeProfileToBuffer(103);

``````````

</details>


https://github.com/llvm/llvm-project/pull/215470


More information about the llvm-commits mailing list