Skip to content

Commit 935e5e1

Browse files
committed
SparcDisassembler: Ensure Size is initialized
To fix uninitialized value with an invalid encoding.
1 parent ed2f89f commit 935e5e1

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

llvm/lib/Target/Sparc/Disassembler/SparcDisassembler.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ static DecodeStatus readInstruction32(ArrayRef<uint8_t> Bytes, uint64_t Address,
276276
return MCDisassembler::Fail;
277277
}
278278

279+
Size = 4;
279280
Insn = IsLittleEndian
280281
? (Bytes[0] << 0) | (Bytes[1] << 8) | (Bytes[2] << 16) |
281282
(Bytes[3] << 24)
@@ -306,20 +307,13 @@ DecodeStatus SparcDisassembler::getInstruction(MCInst &Instr, uint64_t &Size,
306307
{
307308
Result = decodeInstruction(DecoderTableSparcV832, Instr, Insn, Address, this, STI);
308309
}
309-
if (Result != MCDisassembler::Fail) {
310-
Size = 4;
310+
if (Result != MCDisassembler::Fail)
311311
return Result;
312-
}
313312

314313
Result =
315314
decodeInstruction(DecoderTableSparc32, Instr, Insn, Address, this, STI);
316315

317-
if (Result != MCDisassembler::Fail) {
318-
Size = 4;
319-
return Result;
320-
}
321-
322-
return MCDisassembler::Fail;
316+
return Result;
323317
}
324318

325319
static bool tryAddingSymbolicOperand(int64_t Value, bool isBranch,
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# RUN: llvm-mc --disassemble %s -triple=sparcv9 2>&1 | FileCheck %s
2+
3+
0xff 0xdc 0xba 0x98
4+
# CHECK: [[@LINE-1]]:1: warning: invalid instruction encoding
5+
6+
0xff 0xdc 0xba 0x98
7+
# CHECK: [[@LINE-1]]:1: warning: invalid instruction encoding

0 commit comments

Comments
 (0)