summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2017-12-08 22:32:35 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2017-12-08 22:32:35 +0000
commitc502040075a582f6fa7782476a884e30b532da2a (patch)
tree2a7f164f901871277ff629d1dcce2b94e43806c7 /utils
parentaf52b3317a4e479e2255ca1de68413ff1cc811ec (diff)
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
Diffstat (limited to 'utils')
-rw-r--r--utils/TableGen/X86RecognizableInstr.cpp9
1 files changed, 4 insertions, 5 deletions
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> 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);
}