From: Adrian Prantl Date: Tue, 12 Sep 2017 16:10:24 +0000 (+0000) Subject: Statically assert that enum items don't overflow storage. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=91a879b291b83f54d3f83d83ae12483396d3c8a5;p=llvm Statically assert that enum items don't overflow storage. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313041 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/DebugInfo/DIContext.h b/include/llvm/DebugInfo/DIContext.h index d6657b4d8d4..8f96b42ec8f 100644 --- a/include/llvm/DebugInfo/DIContext.h +++ b/include/llvm/DebugInfo/DIContext.h @@ -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 };