[llvm] [llvm-profgen] Reject incompatible ExtBinary section flags (PR #215470)
Sergey Shcherbinin via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 10 23:29:16 PDT 2026
https://github.com/SergeyShch01 created https://github.com/llvm/llvm-project/pull/215470
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.
>From 3880393f9d166e4f0eb8cf80f3004a5732add68b Mon Sep 17 00:00:00 2001
From: Sergey Shcherbinin <sscherbinin at nvidia.com>
Date: Tue, 4 Aug 2026 14:11:43 +0400
Subject: [PATCH] [llvm-profgen] Reject incompatible ExtBinary section flags
---
llvm/include/llvm/ProfileData/SampleProf.h | 3 ++-
llvm/unittests/ProfileData/SampleProfTest.cpp | 10 ++++++++++
2 files changed, 12 insertions(+), 1 deletion(-)
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);
More information about the llvm-commits
mailing list