[llvm] r350903 - [MSP430] Minor fixes/improvements for assembler/disassembler
Anton Korobeynikov via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 10 14:59:50 PST 2019
Author: asl
Date: Thu Jan 10 14:59:50 2019
New Revision: 350903
URL: http://llvm.org/viewvc/llvm-project?rev=350903&view=rev
Log:
[MSP430] Minor fixes/improvements for assembler/disassembler
* Teach AsmParser to recognize @rn in distination operand as 0(rn).
* Do not allow Disassembler decoding instructions that have size more
than a number of input bytes.
* Fix UB in MSP430MCCodeEmitter.
Patch by Kristina Bessonova!
Differential Revision: https://reviews.llvm.org/D56547
Added:
llvm/trunk/test/MC/Disassembler/MSP430/unknown.txt
Modified:
llvm/trunk/lib/Target/MSP430/AsmParser/MSP430AsmParser.cpp
llvm/trunk/lib/Target/MSP430/Disassembler/MSP430Disassembler.cpp
llvm/trunk/lib/Target/MSP430/MCTargetDesc/MSP430MCCodeEmitter.cpp
llvm/trunk/test/MC/MSP430/addrmode.s
llvm/trunk/test/MC/MSP430/invalid.s
Modified: llvm/trunk/lib/Target/MSP430/AsmParser/MSP430AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/MSP430/AsmParser/MSP430AsmParser.cpp?rev=350903&r1=350902&r2=350903&view=diff
==============================================================================
--- llvm/trunk/lib/Target/MSP430/AsmParser/MSP430AsmParser.cpp (original)
+++ llvm/trunk/lib/Target/MSP430/AsmParser/MSP430AsmParser.cpp Thu Jan 10 14:59:50 2019
@@ -497,7 +497,11 @@ bool MSP430AsmParser::ParseOperand(Opera
getLexer().Lex(); // Eat '+'
return false;
}
- Operands.push_back(MSP430Operand::CreateIndReg(RegNo, StartLoc, EndLoc));
+ if (Operands.size() > 1) // Emulate @rd in destination position as 0(rd)
+ Operands.push_back(MSP430Operand::CreateMem(RegNo,
+ MCConstantExpr::create(0, getContext()), StartLoc, EndLoc));
+ else
+ Operands.push_back(MSP430Operand::CreateIndReg(RegNo, StartLoc, EndLoc));
return false;
}
case AsmToken::Hash:
Modified: llvm/trunk/lib/Target/MSP430/Disassembler/MSP430Disassembler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/MSP430/Disassembler/MSP430Disassembler.cpp?rev=350903&r1=350902&r2=350903&view=diff
==============================================================================
--- llvm/trunk/lib/Target/MSP430/Disassembler/MSP430Disassembler.cpp (original)
+++ llvm/trunk/lib/Target/MSP430/Disassembler/MSP430Disassembler.cpp Thu Jan 10 14:59:50 2019
@@ -249,6 +249,10 @@ DecodeStatus MSP430Disassembler::getInst
case amSymbolic:
case amImmediate:
case amAbsolute:
+ if (Bytes.size() < (Words + 1) * 2) {
+ Size = 2;
+ return DecodeStatus::Fail;
+ }
Insn |= (uint64_t)support::endian::read16le(Bytes.data() + 2) << 16;
++Words;
break;
@@ -259,6 +263,10 @@ DecodeStatus MSP430Disassembler::getInst
case amIndexed:
case amSymbolic:
case amAbsolute:
+ if (Bytes.size() < (Words + 1) * 2) {
+ Size = 2;
+ return DecodeStatus::Fail;
+ }
Insn |= (uint64_t)support::endian::read16le(Bytes.data() + Words * 2)
<< (Words * 16);
++Words;
@@ -296,6 +304,10 @@ DecodeStatus MSP430Disassembler::getInst
case amSymbolic:
case amImmediate:
case amAbsolute:
+ if (Bytes.size() < (Words + 1) * 2) {
+ Size = 2;
+ return DecodeStatus::Fail;
+ }
Insn |= (uint64_t)support::endian::read16le(Bytes.data() + 2) << 16;
++Words;
break;
Modified: llvm/trunk/lib/Target/MSP430/MCTargetDesc/MSP430MCCodeEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/MSP430/MCTargetDesc/MSP430MCCodeEmitter.cpp?rev=350903&r1=350902&r2=350903&view=diff
==============================================================================
--- llvm/trunk/lib/Target/MSP430/MCTargetDesc/MSP430MCCodeEmitter.cpp (original)
+++ llvm/trunk/lib/Target/MSP430/MCTargetDesc/MSP430MCCodeEmitter.cpp Thu Jan 10 14:59:50 2019
@@ -128,7 +128,7 @@ unsigned MSP430MCCodeEmitter::getMemOpVa
const MCOperand &MO2 = MI.getOperand(Op + 1);
if (MO2.isImm()) {
Offset += 2;
- return (MO2.getImm() << 4) | Reg;
+ return ((unsigned)MO2.getImm() << 4) | Reg;
}
assert(MO2.isExpr() && "Expr operand expected");
Added: llvm/trunk/test/MC/Disassembler/MSP430/unknown.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/Disassembler/MSP430/unknown.txt?rev=350903&view=auto
==============================================================================
--- llvm/trunk/test/MC/Disassembler/MSP430/unknown.txt (added)
+++ llvm/trunk/test/MC/Disassembler/MSP430/unknown.txt Thu Jan 10 14:59:50 2019
@@ -0,0 +1,13 @@
+# RUN: not llvm-mc -disassemble -triple=msp430 %s 2>&1 | FileCheck %s
+
+# This should not decode as 'and.b @r15+, (0)r1' [0xf1,0xff,0x00,0x00]
+[0xf1 0xff]
+# CHECK: warning: invalid instruction encoding
+
+# This should not decode as 'add 6(r7), 6(r5)' [0x95 0x57 0x06 0x00 0x06 0x00]
+[0x95 0x57 0x06 0x00]
+# CHECK: warning: invalid instruction encoding
+
+# This should not decode as 'call 6(r7)' [0x97 0x12 0x06 0x00]
+[0x97 0x12]
+# CHECK: warning: invalid instruction encoding
Modified: llvm/trunk/test/MC/MSP430/addrmode.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/MSP430/addrmode.s?rev=350903&r1=350902&r2=350903&view=diff
==============================================================================
--- llvm/trunk/test/MC/MSP430/addrmode.s (original)
+++ llvm/trunk/test/MC/MSP430/addrmode.s Thu Jan 10 14:59:50 2019
@@ -21,11 +21,13 @@ foo:
mov #42, 12(r15)
mov #42, &disp
mov disp, disp+2
+ mov r7, @r15
; CHECK: mov #42, r15 ; encoding: [0x3f,0x40,0x2a,0x00]
; CHECK: mov #42, 12(r15) ; encoding: [0xbf,0x40,0x2a,0x00,0x0c,0x00]
; CHECK: mov #42, &disp ; encoding: [0xb2,0x40,0x2a,0x00,A,A]
; CHECK: mov disp, disp+2 ; encoding: [0x90,0x40,A,A,B,B]
+; CHECK: mov r7, 0(r15) ; encoding: [0x8f,0x47,0x00,0x00]
add r7, r8
add 6(r7), r8
Modified: llvm/trunk/test/MC/MSP430/invalid.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/MSP430/invalid.s?rev=350903&r1=350902&r2=350903&view=diff
==============================================================================
--- llvm/trunk/test/MC/MSP430/invalid.s (original)
+++ llvm/trunk/test/MC/MSP430/invalid.s Thu Jan 10 14:59:50 2019
@@ -4,7 +4,6 @@ foo:
mov r7 ; CHECK: :[[@LINE]]:3: error: too few operands for instruction
;; invalid destination addressing modes
- mov r7, @r15 ; CHECK: :[[@LINE]]:14: error: invalid operand for instruction
mov r7, @r15+ ; CHECK: :[[@LINE]]:14: error: invalid operand for instruction
mov r7, #0 ; CHECK: :[[@LINE]]:14: error: invalid operand for instruction
mov r7, #123 ; CHECK: :[[@LINE]]:14: error: invalid operand for instruction
More information about the llvm-commits
mailing list