Skip to content

Commit 1522354

Browse files
authored
[lldb] Add a static_assert that g_core_definitions matches the Core enum (llvm#159452)
This PR uses the same trick as 7ced9ff to ensure the `g_core_definitions` table is correctly indexed by the Core enum. It's easy to make a mistake. Case in point: this caught two entries that appeared in the wrong order.
1 parent 7f2dcaa commit 1522354

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

lldb/source/Utility/ArchSpec.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct CoreDefinition {
4141
} // namespace lldb_private
4242

4343
// This core information can be looked using the ArchSpec::Core as the index
44-
static const CoreDefinition g_core_definitions[] = {
44+
static constexpr const CoreDefinition g_core_definitions[] = {
4545
{eByteOrderLittle, 4, 2, 4, llvm::Triple::arm, ArchSpec::eCore_arm_generic,
4646
"arm"},
4747
{eByteOrderLittle, 4, 2, 4, llvm::Triple::arm, ArchSpec::eCore_arm_armv4,
@@ -90,12 +90,12 @@ static const CoreDefinition g_core_definitions[] = {
9090
"thumbv6m"},
9191
{eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb, ArchSpec::eCore_thumbv7,
9292
"thumbv7"},
93-
{eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb, ArchSpec::eCore_thumbv7f,
94-
"thumbv7f"},
9593
{eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb, ArchSpec::eCore_thumbv7s,
9694
"thumbv7s"},
9795
{eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb, ArchSpec::eCore_thumbv7k,
9896
"thumbv7k"},
97+
{eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb, ArchSpec::eCore_thumbv7f,
98+
"thumbv7f"},
9999
{eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb, ArchSpec::eCore_thumbv7m,
100100
"thumbv7m"},
101101
{eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb, ArchSpec::eCore_thumbv7em,
@@ -257,6 +257,15 @@ static_assert(sizeof(g_core_definitions) / sizeof(CoreDefinition) ==
257257
ArchSpec::kNumCores,
258258
"make sure we have one core definition for each core");
259259

260+
template <int I> struct ArchSpecValidator : ArchSpecValidator<I + 1> {
261+
static_assert(g_core_definitions[I].core == I,
262+
"g_core_definitions order doesn't match Core enumeration");
263+
};
264+
265+
template <> struct ArchSpecValidator<ArchSpec::kNumCores> {};
266+
267+
ArchSpecValidator<ArchSpec::eCore_arm_generic> validator;
268+
260269
struct ArchDefinitionEntry {
261270
ArchSpec::Core core;
262271
uint32_t cpu;

0 commit comments

Comments
 (0)