From 1c83093cd5f4f6d33e732c817bb5afd033531beb Mon Sep 17 00:00:00 2001 From: Kevin Enderby Date: Thu, 29 Nov 2012 23:47:11 +0000 Subject: [PATCH] Fixed the arm disassembly of invalid BFI instructions to not build a bad MCInst which would then cause an assert when printed. rdar://11437956 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@168960 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/ARM/Disassembler/ARMDisassembler.cpp | 8 +++++++- test/MC/Disassembler/ARM/unpredictable-BFI.txt | 11 +++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 test/MC/Disassembler/ARM/unpredictable-BFI.txt diff --git a/lib/Target/ARM/Disassembler/ARMDisassembler.cpp b/lib/Target/ARM/Disassembler/ARMDisassembler.cpp index f00142de50d..5de50d592e7 100644 --- a/lib/Target/ARM/Disassembler/ARMDisassembler.cpp +++ b/lib/Target/ARM/Disassembler/ARMDisassembler.cpp @@ -1281,7 +1281,13 @@ static DecodeStatus DecodeBitfieldMaskOperand(MCInst &Inst, unsigned Val, unsigned lsb = fieldFromInstruction(Val, 0, 5); DecodeStatus S = MCDisassembler::Success; - if (lsb > msb) Check(S, MCDisassembler::SoftFail); + if (lsb > msb) { + Check(S, MCDisassembler::SoftFail); + // The check above will cause the warning for the "potentially undefined + // instruction encoding" but we can't build a bad MCOperand value here + // with a lsb > msb or else printing the MCInst will cause a crash. + lsb = msb; + } uint32_t msb_mask = 0xFFFFFFFF; if (msb != 31) msb_mask = (1U << (msb+1)) - 1; diff --git a/test/MC/Disassembler/ARM/unpredictable-BFI.txt b/test/MC/Disassembler/ARM/unpredictable-BFI.txt new file mode 100644 index 00000000000..a98f859c4c6 --- /dev/null +++ b/test/MC/Disassembler/ARM/unpredictable-BFI.txt @@ -0,0 +1,11 @@ +# RUN: llvm-mc --disassemble %s -triple=arm-apple-darwin9 2>&1 | FileCheck %s + +# rdar://11437956 + +# CHECK: warning: invalid instruction encoding +# CHECK: 0x90 0x00 0xc0 0xe7 +0x90 0x00 0xc0 0xe7 + +# CHECK: warning: invalid instruction encoding +# CHECK: 0x90 0x01 0xc0 0xe7 +0x90 0x01 0xc0 0xe7 -- 2.34.1