[llvm] e1e3b6e - [M68k] Avoid UB in disassembler
Ricky Taylor via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 29 14:11:56 PDT 2021
Author: Ricky Taylor
Date: 2021-09-29T22:07:14+01:00
New Revision: e1e3b6ee72977c584052a9da8735c31c2a17385a
URL: https://github.com/llvm/llvm-project/commit/e1e3b6ee72977c584052a9da8735c31c2a17385a
DIFF: https://github.com/llvm/llvm-project/commit/e1e3b6ee72977c584052a9da8735c31c2a17385a.diff
LOG: [M68k] Avoid UB in disassembler
When reading 32 bits a 32-bit shift would be executed.
This is undefined behaviour, but in this case we can just replace the
entire scratch value to avoid it.
Differential Revision: https://reviews.llvm.org/D110769
Added:
Modified:
llvm/lib/Target/M68k/Disassembler/M68kDisassembler.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/M68k/Disassembler/M68kDisassembler.cpp b/llvm/lib/Target/M68k/Disassembler/M68kDisassembler.cpp
index a8453c838493d..1e397f0f4641d 100644
--- a/llvm/lib/Target/M68k/Disassembler/M68kDisassembler.cpp
+++ b/llvm/lib/Target/M68k/Disassembler/M68kDisassembler.cpp
@@ -451,7 +451,8 @@ void M68kDisassembler::decodeImm(MCInst &Instr, unsigned Bead,
llvm_unreachable("invalid imm");
}
- Scratch = (Scratch << NumToRead) | Reader.readBits(NumToRead);
+ Scratch = (NumToRead < 32) ? (Scratch << NumToRead) : 0;
+ Scratch |= Reader.readBits(NumToRead);
}
DecodeStatus M68kDisassembler::getInstruction(MCInst &Instr, uint64_t &Size,
More information about the llvm-commits
mailing list