From: Richard Smith Date: Fri, 8 Dec 2017 22:32:35 +0000 (+0000) Subject: Avoid constructing an out-of-range value for an enumeration (which results in UB). X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c502040075a582f6fa7782476a884e30b532da2a;p=llvm Avoid constructing an out-of-range value for an enumeration (which results in UB). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320206 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/utils/TableGen/X86RecognizableInstr.cpp b/utils/TableGen/X86RecognizableInstr.cpp index c3330294d76..9afdd7e0963 100644 --- a/utils/TableGen/X86RecognizableInstr.cpp +++ b/utils/TableGen/X86RecognizableInstr.cpp @@ -706,7 +706,7 @@ void RecognizableInstr::emitDecodePath(DisassemblerTables &tables) const { #define MAP(from, to) \ case X86Local::MRM_##from: - OpcodeType opcodeType = (OpcodeType)-1; + llvm::Optional opcodeType; ModRMFilter* filter = nullptr; uint8_t opcodeToSet = 0; @@ -786,8 +786,7 @@ void RecognizableInstr::emitDecodePath(DisassemblerTables &tables) const { case X86Local::AdSize64: AddressSize = 64; break; } - assert(opcodeType != (OpcodeType)-1 && - "Opcode type not set"); + assert(opcodeType && "Opcode type not set"); assert(filter && "Filter not set"); if (Form == X86Local::AddRegFrm) { @@ -799,12 +798,12 @@ void RecognizableInstr::emitDecodePath(DisassemblerTables &tables) const { for (currentOpcode = opcodeToSet; currentOpcode < opcodeToSet + 8; ++currentOpcode) - tables.setTableFields(opcodeType, insnContext(), currentOpcode, *filter, + tables.setTableFields(*opcodeType, insnContext(), currentOpcode, *filter, UID, Is32Bit, OpPrefix == 0, IgnoresVEX_L || EncodeRC, VEX_WPrefix == X86Local::VEX_WIG, AddressSize); } else { - tables.setTableFields(opcodeType, insnContext(), opcodeToSet, *filter, UID, + tables.setTableFields(*opcodeType, insnContext(), opcodeToSet, *filter, UID, Is32Bit, OpPrefix == 0, IgnoresVEX_L || EncodeRC, VEX_WPrefix == X86Local::VEX_WIG, AddressSize); }