Skip to content

Commit bcf09c1

Browse files
authored
[ARM][Disassembler] Advance IT State when instruction is unknown (#154531)
When an instruction that the disassembler does not recognize is in an IT block, we should still advance the IT state otherwise the IT state spills over into the next recognized instruction, which is incorrect. We want to avoid disassembly like: it eq <unknown> // Often because disassembler has insufficient target info. addeq r0,r0,r0 // eq spills over into add. Fixes #150569
1 parent 26d4e56 commit bcf09c1

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

llvm/lib/Target/ARM/Disassembler/ARMDisassembler.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,6 +1264,10 @@ DecodeStatus ARMDisassembler::getThumbInstruction(MCInst &MI, uint64_t &Size,
12641264
return Result;
12651265
}
12661266

1267+
// Advance IT state to prevent next instruction inheriting
1268+
// the wrong IT state.
1269+
if (ITBlock.instrInITBlock())
1270+
ITBlock.advanceITState();
12671271
Size = 0;
12681272
return MCDisassembler::Fail;
12691273
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
@RUN: llvm-mc -triple arm-none-eabi -mcpu=cortex-m33 -filetype=obj %s | llvm-objdump -d --mcpu=cortex-m3 - | FileCheck %s
2+
3+
@ Check that instructions that are disassembled as <undefined> within an IT
4+
@ block advance the IT state. This prevents the IT state spilling over into
5+
@ the next instruction.
6+
7+
@ The vldmiaeq instruction is disassembled as <undefined> with
8+
@ -mcpu=cortex-m3 as this does not have a fpu.
9+
.text
10+
.fpu fp-armv8
11+
.thumb
12+
ite eq
13+
vldmiaeq r0!, {s16-s31}
14+
addne r0, r0, r0
15+
add r1, r1, r1
16+
17+
itet eq
18+
vldmiaeq r0!, {s16-s31}
19+
vldmiane r0!, {s16-s31}
20+
vldmiaeq r0!, {s16-s31}
21+
add r0, r0, r0
22+
add r1, r1, r1
23+
add r2, r2, r2
24+
25+
it eq
26+
vldmiaeq r0!, {s16-s31}
27+
28+
it ne
29+
addne r0, r0, r0
30+
31+
@ CHECK: 0: bf0c ite eq
32+
@ CHECK-NEXT: 2: ecb0 8a10 <unknown>
33+
@ CHECK-NEXT: 6: 1800 addne r0, r0, r0
34+
@ CHECK-NEXT: 8: 4409 add r1, r1
35+
@ CHECK-NEXT: a: bf0a itet eq
36+
@ CHECK-NEXT: c: ecb0 8a10 <unknown>
37+
@ CHECK-NEXT: 10: ecb0 8a10 <unknown>
38+
@ CHECK-NEXT: 14: ecb0 8a10 <unknown>
39+
@ CHECK-NEXT: 18: 4400 add r0, r0
40+
@ CHECK-NEXT: 1a: 4409 add r1, r1
41+
@ CHECK-NEXT: 1c: 4412 add r2, r2
42+
@ CHECK-NEXT: 1e: bf08 it eq
43+
@ CHECK-NEXT: 20: ecb0 8a10 <unknown>
44+
@ CHECK-NEXT: 24: bf18 it ne
45+
@ CHECK-NEXT: 26: 1800 addne r0, r0, r0

0 commit comments

Comments
 (0)