[llvm] r320206 - Avoid constructing an out-of-range value for an enumeration (which results in UB).
Richard Smith via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 8 14:32:35 PST 2017
Author: rsmith
Date: Fri Dec 8 14:32:35 2017
New Revision: 320206
URL: http://llvm.org/viewvc/llvm-project?rev=320206&view=rev
Log:
Avoid constructing an out-of-range value for an enumeration (which results in UB).
Modified:
llvm/trunk/utils/TableGen/X86RecognizableInstr.cpp
Modified: llvm/trunk/utils/TableGen/X86RecognizableInstr.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/X86RecognizableInstr.cpp?rev=320206&r1=320205&r2=320206&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/X86RecognizableInstr.cpp (original)
+++ llvm/trunk/utils/TableGen/X86RecognizableInstr.cpp Fri Dec 8 14:32:35 2017
@@ -706,7 +706,7 @@ void RecognizableInstr::emitDecodePath(D
#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(D
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(D
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);
}
More information about the llvm-commits
mailing list