llvm.org GIT mirror llvm / 165d008
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 Tom Stellard 1 year, 9 months ago
3 changed file(s) with 84 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
57925792 MipsAsmParser::parseInvNum(OperandVector &Operands) {
57935793 MCAsmParser &Parser = getParser();
57945794 const MCExpr *IdVal;
5795 // If the first token is '$' we may have register operand.
5796 if (Parser.getTok().is(AsmToken::Dollar))
5797 return MatchOperand_NoMatch;
5795 // If the first token is '$' we may have register operand. We have to reject
5796 // cases where it is not a register. Complicating the matter is that
5797 // register names are not reserved across all ABIs.
5798 // Peek past the dollar to see if it's a register name for this ABI.
57985799 SMLoc S = Parser.getTok().getLoc();
5800 if (Parser.getTok().is(AsmToken::Dollar)) {
5801 return matchCPURegisterName(Parser.getLexer().peekTok().getString()) == -1
5802 ? MatchOperand_ParseFail
5803 : MatchOperand_NoMatch;
5804 }
57995805 if (getParser().parseExpression(IdVal))
58005806 return MatchOperand_ParseFail;
58015807 const MCConstantExpr *MCE = dyn_cast(IdVal);
5802 assert(MCE && "Unexpected MCExpr type.");
5808 if (!MCE)
5809 return MatchOperand_NoMatch;
58035810 int64_t Val = MCE->getValue();
58045811 SMLoc E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
58055812 Operands.push_back(MipsOperand::CreateImm(
0 # RUN: not llvm-mc -arch=mips %s 2>%t1
1 # RUN: FileCheck --check-prefix=O32 %s < %t1
2
3 # RUN: not llvm-mc -arch=mips64 %s 2>%t1
4 # RUN: FileCheck --check-prefix=N64 %s < %t1
5
6 # Check that subu only rejects any non-constant values.
7
8 .globl end
9 subu $4, $4, %lo($start) # O32: [[@LINE]]:{{[0-9]+}}: error: unexpected token in argument list
10 # N64: [[@LINE-1]]:{{[0-9]+}}: error: unexpected token in argument list
11 subu $4, $4, $start # O32: [[@LINE]]:{{[0-9]+}}: error: unexpected token in argument list
12 # N64: [[@LINE-1]]:{{[0-9]+}}: error: unexpected token in argument list
13 subu $4, $a4, $a4 # O32: [[@LINE]]:{{[0-9]+}}: error: unexpected token in argument list
14 subu $4, $4, %hi(end) # O32: [[@LINE]]:{{[0-9]+}}: error: unexpected token in argument list
15 # N64: [[@LINE-1]]:{{[0-9]+}}: error: unexpected token in argument list
16 subu $4, $4, end + 4 # O32: [[@LINE]]:{{[0-9]+}}: error: unexpected token in argument list
17 # N64: [[@LINE-1]]:{{[0-9]+}}: error: unexpected token in argument list
18 subu $4, $4, end # O32: [[@LINE]]:{{[0-9]+}}: error: unexpected token in argument list
19 # N64: [[@LINE-1]]:{{[0-9]+}}: error: unexpected token in argument list
20 subu $4, $4, sp # O32: [[@LINE]]:{{[0-9]+}}: error: unexpected token in argument list
21 # N64: [[@LINE-1]]:{{[0-9]+}}: error: unexpected token in argument list
22
23 subu $4, %lo($start) # O32: [[@LINE]]:{{[0-9]+}}: error: unexpected token in argument list
24 # N64: [[@LINE-1]]:{{[0-9]+}}: error: unexpected token in argument list
25 subu $4, $start # O32: [[@LINE]]:{{[0-9]+}}: error: unexpected token in argument list
26 # N64: [[@LINE-1]]:{{[0-9]+}}: error: unexpected token in argument list
27 subu $4, $a4 # O32: [[@LINE]]:{{[0-9]+}}: error: unexpected token in argument list
28 subu $4, %hi(end) # O32: [[@LINE]]:{{[0-9]+}}: error: unexpected token in argument list
29 # N64: [[@LINE-1]]:{{[0-9]+}}: error: unexpected token in argument list
30 subu $4, end + 4 # O32: [[@LINE]]:{{[0-9]+}}: error: unexpected token in argument list
31 # N64: [[@LINE-1]]:{{[0-9]+}}: error: unexpected token in argument list
32 subu $4, end # O32: [[@LINE]]:{{[0-9]+}}: error: unexpected token in argument list
33 # N64: [[@LINE-1]]:{{[0-9]+}}: error: unexpected token in argument list
34 subu $4, sp # O32: [[@LINE]]:{{[0-9]+}}: error: unexpected token in argument list
35 # N64: [[@LINE-1]]:{{[0-9]+}}: error: unexpected token in argument list
36
37 $start:
0 # RUN: llvm-mc -arch=mips -mcpu=mips32r2 %s -show-inst | FileCheck %s
1
2 # Test that subu accepts constant operands and inverts them when
3 # rendering the operand.
4
5 subu $4, $4, 4 # CHECK: ADDiu
6 # CHECK; Imm:-4
7 subu $gp, $gp, 4 # CHECK: ADDiu
8 # CHECK; Imm:-4
9 subu $sp, $sp, 4 # CHECK: ADDiu
10 # CHECK; Imm:-4
11 subu $4, $4, -4 # CHECK: ADDiu
12 # CHECK; Imm:4
13 subu $gp, $gp, -4 # CHECK: ADDiu
14 # CHECK; Imm:4
15 subu $sp, $sp, -4 # CHECK: ADDiu
16 # CHECK; Imm:4
17 subu $sp, $sp, -(4 + 4) # CHECK: ADDiu
18 # CHECK: Imm:8
19
20 subu $4, 8 # CHECK: ADDiu
21 # CHECK; Imm:-8
22 subu $gp, 8 # CHECK: ADDiu
23 # CHECK; Imm:-8
24 subu $sp, 8 # CHECK: ADDiu
25 # CHECK; Imm:-8
26 subu $4, -8 # CHECK: ADDiu
27 # CHECK; Imm:8
28 subu $gp, -8 # CHECK: ADDiu
29 # CHECK; Imm:8
30 subu $sp, -8 # CHECK: ADDiu
31 # CHECK; Imm:8
32 subu $sp, -(4 + 4) # CHECK: ADDiu
33 # CHECK: Imm:8
34