Index: lib/Target/X86/AsmParser/X86AsmParser.cpp =================================================================== --- lib/Target/X86/AsmParser/X86AsmParser.cpp +++ lib/Target/X86/AsmParser/X86AsmParser.cpp @@ -1834,10 +1834,25 @@ // FIXME: Offset operator // Should be handled as part of immediate expression, as other operators // Currently, only supported as a stand-alone operand - if (isParsingInlineAsm()) - if (IdentifyIntelInlineAsmOperator(Tok.getString()) == IOK_OFFSET) + if (IdentifyIntelInlineAsmOperator(Tok.getString()) == IOK_OFFSET) { + // FIXME: Should MS inline assembly parsing really be handling this + // differently? + if (isParsingInlineAsm()) return ParseIntelOffsetOfOperator(); + // Not parsing MS inline assembly. Parse this like '$' in AT&T. + Parser.Lex(); + const MCExpr *Val; + // This is an immediate, so we should not parse a register. Do a precheck + // for '%' to supercede intra-register parse errors. + SMLoc L = Parser.getTok().getLoc(); + if (getParser().parseExpression(Val, End) || + check(isa(Val), L, "expected immediate expression")) + return nullptr; + return X86Operand::CreateImm(Val, Start, End); + } + + // Parse optional Size directive. unsigned Size; if (ParseIntelMemoryOperandSize(Size)) Index: test/MC/X86/intel-syntax-var-offset.s =================================================================== --- /dev/null +++ test/MC/X86/intel-syntax-var-offset.s @@ -0,0 +1,12 @@ +// RUN: llvm-mc %s -triple x86_64-unknown-unknown -show-encoding | FileCheck %s + +.intel_syntax noprefix +// CHECK: movq $X, %rax +// CHECK: encoding: [0x48,0xc7,0xc0,A,A,A,A] +// CHECK: fixup A - offset: 3, value: X, kind: reloc_signed_4byte +mov rax, offset X + +// CHECK: movq $X+1, %rax +// CHECK: encoding: [0x48,0xc7,0xc0,A,A,A,A] +// CHECK: fixup A - offset: 3, value: X+1, kind: reloc_signed_4byte +mov rax, offset X + 1