diff options
author | Greg Clayton <gclayton@apple.com> | 2014-07-23 18:12:06 +0000 |
---|---|---|
committer | Greg Clayton <gclayton@apple.com> | 2014-07-23 18:12:06 +0000 |
commit | 56b796856fcd59ce93eca78b0754a7c1295ccfc0 (patch) | |
tree | 188471d7bcd4a608da80c98a60dd0f3542ccc062 /lldb/source/Core/ArchSpec.cpp | |
parent | df2c3e89b5fc44127d6597eaa9d71b8b770ead03 (diff) | |
download | bcm5719-llvm-56b796856fcd59ce93eca78b0754a7c1295ccfc0.tar.gz bcm5719-llvm-56b796856fcd59ce93eca78b0754a7c1295ccfc0.zip |
Make sure we don't crash if someone (E.G.) comments out on entry from g_core_definitions[] without removing the ArchSpec::Core enumeration when submitting from source.
We now catch the issue with a static_assert() at compile time and use llvm::array_lengthof(g_core_definitions) as well.
<rdar://problem/17767541>
llvm-svn: 213778
Diffstat (limited to 'lldb/source/Core/ArchSpec.cpp')
-rw-r--r-- | lldb/source/Core/ArchSpec.cpp | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/lldb/source/Core/ArchSpec.cpp b/lldb/source/Core/ArchSpec.cpp index ce24e5d9302..ece0cdefd5f 100644 --- a/lldb/source/Core/ArchSpec.cpp +++ b/lldb/source/Core/ArchSpec.cpp @@ -42,13 +42,13 @@ namespace lldb_private { uint32_t max_opcode_byte_size; llvm::Triple::ArchType machine; ArchSpec::Core core; - const char *name; + const char * const name; }; } // This core information can be looked using the ArchSpec::Core as the index -static const CoreDefinition g_core_definitions[ArchSpec::kNumCores] = +static const CoreDefinition g_core_definitions[] = { { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_generic , "arm" }, { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv4 , "armv4" }, @@ -118,6 +118,11 @@ static const CoreDefinition g_core_definitions[ArchSpec::kNumCores] = { eByteOrderLittle, 4, 1, 1 , llvm::Triple::kalimba , ArchSpec::eCore_kalimba , "kalimba" } }; +// Ensure that we have an entry in the g_core_definitions for each core. If you comment out an entry above, +// you will need to comment out the corresponding ArchSpec::Core enumeration. +static_assert(llvm::array_lengthof(g_core_definitions) == ArchSpec::kNumCores, "make sure we have one core definition for each core"); + + struct ArchDefinitionEntry { ArchSpec::Core core; @@ -142,7 +147,7 @@ ArchSpec::AutoComplete (const char *name, StringList &matches) uint32_t i; if (name && name[0]) { - for (i = 0; i < ArchSpec::kNumCores; ++i) + for (i = 0; i < llvm::array_lengthof(g_core_definitions); ++i) { if (NameMatches(g_core_definitions[i].name, eNameMatchStartsWith, name)) matches.AppendString (g_core_definitions[i].name); @@ -150,7 +155,7 @@ ArchSpec::AutoComplete (const char *name, StringList &matches) } else { - for (i = 0; i < ArchSpec::kNumCores; ++i) + for (i = 0; i < llvm::array_lengthof(g_core_definitions); ++i) matches.AppendString (g_core_definitions[i].name); } return matches.GetSize(); @@ -312,7 +317,7 @@ FindArchDefinition (ArchitectureType arch_type) static const CoreDefinition * FindCoreDefinition (llvm::StringRef name) { - for (unsigned int i = 0; i < ArchSpec::kNumCores; ++i) + for (unsigned int i = 0; i < llvm::array_lengthof(g_core_definitions); ++i) { if (name.equals_lower(g_core_definitions[i].name)) return &g_core_definitions[i]; @@ -323,7 +328,7 @@ FindCoreDefinition (llvm::StringRef name) static inline const CoreDefinition * FindCoreDefinition (ArchSpec::Core core) { - if (core >= 0 && core < ArchSpec::kNumCores) + if (core >= 0 && core < llvm::array_lengthof(g_core_definitions)) return &g_core_definitions[core]; return NULL; } |