diff options
| author | Richard Smith <richard-llvm@metafoo.co.uk> | 2017-12-08 22:32:35 +0000 |
|---|---|---|
| committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2017-12-08 22:32:35 +0000 |
| commit | 8a3adc3abbea26ad8551aa32f4a25fc99882b972 (patch) | |
| tree | f8e989f1ae67d1f745992abe151c03b15c3ca8d7 /llvm | |
| parent | 2659c63e2e27ae0700eda1ef353d14bd0185f3b5 (diff) | |
| download | bcm5719-llvm-8a3adc3abbea26ad8551aa32f4a25fc99882b972.tar.gz bcm5719-llvm-8a3adc3abbea26ad8551aa32f4a25fc99882b972.zip | |
Avoid constructing an out-of-range value for an enumeration (which results in UB).
llvm-svn: 320206
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/utils/TableGen/X86RecognizableInstr.cpp | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/llvm/utils/TableGen/X86RecognizableInstr.cpp b/llvm/utils/TableGen/X86RecognizableInstr.cpp index c3330294d76..9afdd7e0963 100644 --- a/llvm/utils/TableGen/X86RecognizableInstr.cpp +++ b/llvm/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> 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); } |

