]> granicus.if.org Git - llvm/commitdiff
Statically assert that enum items don't overflow storage.
authorAdrian Prantl <aprantl@apple.com>
Tue, 12 Sep 2017 16:10:24 +0000 (16:10 +0000)
committerAdrian Prantl <aprantl@apple.com>
Tue, 12 Sep 2017 16:10:24 +0000 (16:10 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313041 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/DebugInfo/DIContext.h

index d6657b4d8d4bb5e07bf2ef0d844f52cd0a745dd5..8f96b42ec8f4982af3be2b1e7fabfb5a4d72e417 100644 (file)
@@ -112,7 +112,6 @@ struct DILineInfoSpecifier {
       : FLIKind(FLIKind), FNKind(FNKind) {}
 };
 
-namespace {
 /// This is just a helper to programmatically construct DIDumpType.
 enum DIDumpTypeCounter {
   DIDT_ID_Null = 0,
@@ -120,15 +119,16 @@ enum DIDumpTypeCounter {
   DIDT_ID##ENUM_NAME,
 #include "llvm/BinaryFormat/Dwarf.def"
 #undef HANDLE_DWARF_SECTION
+  DIDT_ID_Count,
 };
-}
+  static_assert(DIDT_ID_Count <= 64, "section types overflow storage");
 
 /// Selects which debug sections get dumped.
 enum DIDumpType : uint64_t {
   DIDT_Null,
   DIDT_All             = ~0ULL,
 #define HANDLE_DWARF_SECTION(ENUM_NAME, ELF_NAME, CMDLINE_NAME) \
-  DIDT_##ENUM_NAME = 1 << DIDT_ID##ENUM_NAME,
+  DIDT_##ENUM_NAME = 1 << (DIDT_ID##ENUM_NAME - 1),
 #include "llvm/BinaryFormat/Dwarf.def"
 #undef HANDLE_DWARF_SECTION
 };