From 102de6b935c4595e14e0f56bb7307962915b3f72 Mon Sep 17 00:00:00 2001 From: James Molloy Date: Wed, 9 Oct 2019 09:15:34 +0000 Subject: [PATCH] [TableGen] Fix crash when using HwModes in CodeEmitterGen When an instruction has an encoding definition for only a subset of the available HwModes, ensure we just avoid generating an encoding rather than crash. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@374150 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/TableGen/HwModeEncodeDecode.td | 9 +++++++++ utils/TableGen/CodeEmitterGen.cpp | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/test/TableGen/HwModeEncodeDecode.td b/test/TableGen/HwModeEncodeDecode.td index b76d8564651..1c9b86ff26a 100644 --- a/test/TableGen/HwModeEncodeDecode.td +++ b/test/TableGen/HwModeEncodeDecode.td @@ -56,6 +56,15 @@ def bar: Instruction { let Inst{1-0} = 0b10; let AsmString = "bar $factor"; } + +def baz : Instruction { + let InOperandList = (ins i32imm:$factor); + bits<32> Inst; + let EncodingInfos = EncodingByHwMode< + [ModeB], [fooTypeEncA] + >; + let AsmString = "foo $factor"; +} } // DECODER-LABEL: DecoderTable_ModeA32[] = diff --git a/utils/TableGen/CodeEmitterGen.cpp b/utils/TableGen/CodeEmitterGen.cpp index b021d08881f..42f69cb253d 100644 --- a/utils/TableGen/CodeEmitterGen.cpp +++ b/utils/TableGen/CodeEmitterGen.cpp @@ -367,7 +367,8 @@ void CodeEmitterGen::emitInstructionBaseValues( if (const RecordVal *RV = R->getValue("EncodingInfos")) { if (auto *DI = dyn_cast_or_null(RV->getValue())) { EncodingInfoByHwMode EBM(DI->getDef(), HWM); - EncodingDef = EBM.get(HwMode); + if (EBM.hasMode(HwMode)) + EncodingDef = EBM.get(HwMode); } } BitsInit *BI = EncodingDef->getValueAsBitsInit("Inst"); -- 2.40.0