diff --git a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp --- a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp +++ b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp @@ -6046,9 +6046,16 @@ return parseRegisterList(Operands, !Mnemonic.startswith("clr")); case AsmToken::Dollar: case AsmToken::Hash: - // #42 -> immediate. + // #42 -> immediate + // $42 -> immediate + // $foo -> symbol name S = Parser.getTok().getLoc(); - Parser.Lex(); + + // Operand can be a symbol starting with the $ character, in which case we + // should not drop the current token before parsing the expression + if (Parser.getTok().isNot(AsmToken::Dollar) + || getLexer().peekTok().isNot(AsmToken::Identifier)) + Parser.Lex(); if (Parser.getTok().isNot(AsmToken::Colon)) { bool isNegative = Parser.getTok().is(AsmToken::Minus); diff --git a/llvm/test/MC/ARM/arm-branches.s b/llvm/test/MC/ARM/arm-branches.s --- a/llvm/test/MC/ARM/arm-branches.s +++ b/llvm/test/MC/ARM/arm-branches.s @@ -13,3 +13,32 @@ @ CHECK: bl #4 @ encoding: [0x01,0x00,0x00,0xeb] @ CHECK: beq #4 @ encoding: [0x01,0x00,0x00,0x0a] @ CHECK: blx #2 @ encoding: [0x00,0x00,0x00,0xfb] + +@------------------------------------------------------------------------------ +@ Immediate constant should be allowed to be prefixed with '$' instead of '#' +@------------------------------------------------------------------------------ + + b $4 + bl $4 + beq $4 + blx $2 + +@ CHECK: b #4 @ encoding: [0x01,0x00,0x00,0xea] +@ CHECK: bl #4 @ encoding: [0x01,0x00,0x00,0xeb] +@ CHECK: beq #4 @ encoding: [0x01,0x00,0x00,0x0a] +@ CHECK: blx #2 @ encoding: [0x00,0x00,0x00,0xfb] + +@------------------------------------------------------------------------------ +@ Leading '$' on branch targets must not be dropped if part of symbol names +@------------------------------------------------------------------------------ + + .global $foo + b $foo + bl $foo + beq $foo + blx $foo + +@ CHECK: b ($foo) @ encoding: [A,A,A,0xea] +@ CHECK: bl ($foo) @ encoding: [A,A,A,0xeb] +@ CHECK: beq ($foo) @ encoding: [A,A,A,0x0a] +@ CHECK: blx ($foo) @ encoding: [A,A,A,0xfa]