Skip to content

Commit 165d008

Browse files
committed
Merging r315310:
------------------------------------------------------------------------ r315310 | sdardis | 2017-10-10 06:34:45 -0700 (Tue, 10 Oct 2017) | 22 lines [mips] Partially fix PR34391 Previously, the parsing of the 'subu $reg, ($reg,) imm' relied on a parser which also rendered the operand to the instruction. In some cases the general parser could construct an MCExpr which was not a MCConstantExpr which MipsAsmParser was expecting. Address this by altering the special handling to cope with unexpected inputs and fine-tune the handling of cases where an register name that is not available in the current ABI is regarded as not a match for the custom parser but also not as an outright error. Also enforces the binutils restriction that only constants are accepted. This partially resolves PR34391. Thanks to Ed Maste for reporting the issue! Reviewers: nitesh.jain, arichardson Differential Revision: https://reviews.llvm.org/D37476 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_50@318192 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent d27dcd3 commit 165d008

File tree

3 files changed

+84
-4
lines changed

3 files changed

+84
-4
lines changed

lib/Target/Mips/AsmParser/MipsAsmParser.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5793,14 +5793,21 @@ OperandMatchResultTy
57935793
MipsAsmParser::parseInvNum(OperandVector &Operands) {
57945794
MCAsmParser &Parser = getParser();
57955795
const MCExpr *IdVal;
5796-
// If the first token is '$' we may have register operand.
5797-
if (Parser.getTok().is(AsmToken::Dollar))
5798-
return MatchOperand_NoMatch;
5796+
// If the first token is '$' we may have register operand. We have to reject
5797+
// cases where it is not a register. Complicating the matter is that
5798+
// register names are not reserved across all ABIs.
5799+
// Peek past the dollar to see if it's a register name for this ABI.
57995800
SMLoc S = Parser.getTok().getLoc();
5801+
if (Parser.getTok().is(AsmToken::Dollar)) {
5802+
return matchCPURegisterName(Parser.getLexer().peekTok().getString()) == -1
5803+
? MatchOperand_ParseFail
5804+
: MatchOperand_NoMatch;
5805+
}
58005806
if (getParser().parseExpression(IdVal))
58015807
return MatchOperand_ParseFail;
58025808
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(IdVal);
5803-
assert(MCE && "Unexpected MCExpr type.");
5809+
if (!MCE)
5810+
return MatchOperand_NoMatch;
58045811
int64_t Val = MCE->getValue();
58055812
SMLoc E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
58065813
Operands.push_back(MipsOperand::CreateImm(
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# RUN: not llvm-mc -arch=mips %s 2>%t1
2+
# RUN: FileCheck --check-prefix=O32 %s < %t1
3+
4+
# RUN: not llvm-mc -arch=mips64 %s 2>%t1
5+
# RUN: FileCheck --check-prefix=N64 %s < %t1
6+
7+
# Check that subu only rejects any non-constant values.
8+
9+
.globl end
10+
subu $4, $4, %lo($start) # O32: [[@LINE]]:{{[0-9]+}}: error: unexpected token in argument list
11+
# N64: [[@LINE-1]]:{{[0-9]+}}: error: unexpected token in argument list
12+
subu $4, $4, $start # O32: [[@LINE]]:{{[0-9]+}}: error: unexpected token in argument list
13+
# N64: [[@LINE-1]]:{{[0-9]+}}: error: unexpected token in argument list
14+
subu $4, $a4, $a4 # O32: [[@LINE]]:{{[0-9]+}}: error: unexpected token in argument list
15+
subu $4, $4, %hi(end) # O32: [[@LINE]]:{{[0-9]+}}: error: unexpected token in argument list
16+
# N64: [[@LINE-1]]:{{[0-9]+}}: error: unexpected token in argument list
17+
subu $4, $4, end + 4 # O32: [[@LINE]]:{{[0-9]+}}: error: unexpected token in argument list
18+
# N64: [[@LINE-1]]:{{[0-9]+}}: error: unexpected token in argument list
19+
subu $4, $4, end # O32: [[@LINE]]:{{[0-9]+}}: error: unexpected token in argument list
20+
# N64: [[@LINE-1]]:{{[0-9]+}}: error: unexpected token in argument list
21+
subu $4, $4, sp # O32: [[@LINE]]:{{[0-9]+}}: error: unexpected token in argument list
22+
# N64: [[@LINE-1]]:{{[0-9]+}}: error: unexpected token in argument list
23+
24+
subu $4, %lo($start) # O32: [[@LINE]]:{{[0-9]+}}: error: unexpected token in argument list
25+
# N64: [[@LINE-1]]:{{[0-9]+}}: error: unexpected token in argument list
26+
subu $4, $start # O32: [[@LINE]]:{{[0-9]+}}: error: unexpected token in argument list
27+
# N64: [[@LINE-1]]:{{[0-9]+}}: error: unexpected token in argument list
28+
subu $4, $a4 # O32: [[@LINE]]:{{[0-9]+}}: error: unexpected token in argument list
29+
subu $4, %hi(end) # O32: [[@LINE]]:{{[0-9]+}}: error: unexpected token in argument list
30+
# N64: [[@LINE-1]]:{{[0-9]+}}: error: unexpected token in argument list
31+
subu $4, end + 4 # O32: [[@LINE]]:{{[0-9]+}}: error: unexpected token in argument list
32+
# N64: [[@LINE-1]]:{{[0-9]+}}: error: unexpected token in argument list
33+
subu $4, end # O32: [[@LINE]]:{{[0-9]+}}: error: unexpected token in argument list
34+
# N64: [[@LINE-1]]:{{[0-9]+}}: error: unexpected token in argument list
35+
subu $4, sp # O32: [[@LINE]]:{{[0-9]+}}: error: unexpected token in argument list
36+
# N64: [[@LINE-1]]:{{[0-9]+}}: error: unexpected token in argument list
37+
38+
$start:

test/MC/Mips/macro-aliases.s

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# RUN: llvm-mc -arch=mips -mcpu=mips32r2 %s -show-inst | FileCheck %s
2+
3+
# Test that subu accepts constant operands and inverts them when
4+
# rendering the operand.
5+
6+
subu $4, $4, 4 # CHECK: ADDiu
7+
# CHECK; Imm:-4
8+
subu $gp, $gp, 4 # CHECK: ADDiu
9+
# CHECK; Imm:-4
10+
subu $sp, $sp, 4 # CHECK: ADDiu
11+
# CHECK; Imm:-4
12+
subu $4, $4, -4 # CHECK: ADDiu
13+
# CHECK; Imm:4
14+
subu $gp, $gp, -4 # CHECK: ADDiu
15+
# CHECK; Imm:4
16+
subu $sp, $sp, -4 # CHECK: ADDiu
17+
# CHECK; Imm:4
18+
subu $sp, $sp, -(4 + 4) # CHECK: ADDiu
19+
# CHECK: Imm:8
20+
21+
subu $4, 8 # CHECK: ADDiu
22+
# CHECK; Imm:-8
23+
subu $gp, 8 # CHECK: ADDiu
24+
# CHECK; Imm:-8
25+
subu $sp, 8 # CHECK: ADDiu
26+
# CHECK; Imm:-8
27+
subu $4, -8 # CHECK: ADDiu
28+
# CHECK; Imm:8
29+
subu $gp, -8 # CHECK: ADDiu
30+
# CHECK; Imm:8
31+
subu $sp, -8 # CHECK: ADDiu
32+
# CHECK; Imm:8
33+
subu $sp, -(4 + 4) # CHECK: ADDiu
34+
# CHECK: Imm:8
35+

0 commit comments

Comments
 (0)