Skip to content

Commit 91a55cf

Browse files
committed
[X86][MC] Not decode 0xf3 as rep prefix if it's right before REX2
This fixes #95412
1 parent 525c25a commit 91a55cf

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

llvm/lib/Target/X86/Disassembler/X86Disassembler.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,10 @@ static int readPrefixes(struct InternalInstruction *insn) {
284284
// it's not mandatory prefix
285285
// 3. if (nextByte >= 0x40 && nextByte <= 0x4f) it's REX and we need
286286
// 0x0f exactly after it to be mandatory prefix
287-
if (isREX(insn, nextByte) || nextByte == 0x0f || nextByte == 0x66)
287+
// 4. if (nextByte == 0xd5) it's REX2 and we need
288+
// 0x0f exactly after it to be mandatory prefix
289+
if (isREX(insn, nextByte) || isREX2(insn, nextByte) || nextByte == 0x0f ||
290+
nextByte == 0x66)
288291
// The last of 0xf2 /0xf3 is mandatory prefix
289292
insn->mandatoryPrefix = byte;
290293
insn->repeatPrefix = byte;

llvm/test/MC/Disassembler/X86/apx/rex2-format.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
# INTEL: movsxd r17, r16d
2222
0xd5,0x58,0x63,0xc8
2323

24-
# ATT: rep
25-
# ATT-SAME: popcntl %r16d, %r17d
26-
# INTEL: rep
27-
# INTEL-SAME: popcnt r17d, r16d
24+
# ATT-NOT: rep
25+
# ATT: popcntl %r16d, %r17d
26+
# INTEL-NOT: rep
27+
# INTEL: popcnt r17d, r16d
2828
0xf3,0xd5,0xd0,0xb8,0xc8
2929

3030
## MRMSrcRegCC

0 commit comments

Comments
 (0)