Skip to content

Commit 4e1f72a

Browse files
committed
[RISCV][Disassemble] Ensure the comment stream of the disassembler is set.
1 parent 0d7ee52 commit 4e1f72a

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ class MCDisassembler {
131131
/// MCDisassembler::SoftFail if the instruction was
132132
/// disassemblable but invalid,
133133
/// MCDisassembler::Fail if the instruction was invalid.
134+
///
135+
/// Note: to avoid potential issues caused by the field
136+
/// `MCDisassembler::CommentStream` being set nullptr (its default
137+
/// value), an implementation of this method should make sure to set
138+
/// `CommentStream = &CStream;`.
134139
virtual DecodeStatus getInstruction(MCInst &Instr, uint64_t &Size,
135140
ArrayRef<uint8_t> Bytes, uint64_t Address,
136141
raw_ostream &CStream) const = 0;

llvm/lib/MC/MCDisassembler/MCDisassembler.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,21 @@ bool MCDisassembler::tryAddingSymbolicOperand(MCInst &Inst, int64_t Value,
2929
uint64_t Address, bool IsBranch,
3030
uint64_t Offset, uint64_t OpSize,
3131
uint64_t InstSize) const {
32-
if (Symbolizer)
32+
if (Symbolizer) {
33+
assert(CommentStream && "CommentStream is not set.");
3334
return Symbolizer->tryAddingSymbolicOperand(Inst, *CommentStream, Value,
3435
Address, IsBranch, Offset,
3536
OpSize, InstSize);
37+
}
3638
return false;
3739
}
3840

3941
void MCDisassembler::tryAddingPcLoadReferenceComment(int64_t Value,
4042
uint64_t Address) const {
41-
if (Symbolizer)
43+
if (Symbolizer) {
44+
assert(CommentStream && "CommentStream is not set.");
4245
Symbolizer->tryAddingPcLoadReferenceComment(*CommentStream, Value, Address);
46+
}
4347
}
4448

4549
void MCDisassembler::setSymbolizer(std::unique_ptr<MCSymbolizer> Symzer) {

llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,7 @@ DecodeStatus RISCVDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
789789
ArrayRef<uint8_t> Bytes,
790790
uint64_t Address,
791791
raw_ostream &CS) const {
792+
CommentStream = &CS;
792793
// It's a 16 bit instruction if bit 0 and 1 are not 0b11.
793794
if ((Bytes[0] & 0b11) != 0b11)
794795
return getInstruction16(MI, Size, Bytes, Address, CS);

0 commit comments

Comments
 (0)