Index: lib/MC/MCParser/AsmLexer.cpp =================================================================== --- lib/MC/MCParser/AsmLexer.cpp +++ lib/MC/MCParser/AsmLexer.cpp @@ -251,6 +251,7 @@ /// Local Label: [0-9][:] /// Forward/Backward Label: [0-9][fb] /// Binary integer: 0b[01]+ +/// However, 0b[0-9a-fA-F]*[hH], with the [hH] suffix, is hexadecimal. /// Octal integer: 0[0-7]+ /// Hex integer: 0x[0-9a-fA-F]+ or [0x]?[0-9][0-9a-fA-F]*[hH] /// Decimal integer: [1-9][0-9]* @@ -286,7 +287,7 @@ if ((*CurPtr == 'b') || (*CurPtr == 'B')) { ++CurPtr; // See if we actually have "0b" as part of something like "jmp 0b\n" - if (!isdigit(CurPtr[0])) { + if (!isxdigit(CurPtr[0]) && *CurPtr != 'h' && *CurPtr != 'H') { --CurPtr; StringRef Result(TokStart, CurPtr - TokStart); return AsmToken(AsmToken::Integer, Result, 0); @@ -295,16 +296,31 @@ while (CurPtr[0] == '0' || CurPtr[0] == '1') ++CurPtr; + // Special case: check for the [hH] suffix and treat 0bedh as hexadecimal. + const char *NonBinStart = CurPtr; + while (isxdigit(*CurPtr)) + ++CurPtr; + unsigned Radix = 2; + if (*CurPtr == 'h' || *CurPtr == 'H') { + Radix = 16; + --NumStart; // the "b" in "0bedh" also counts + } else + CurPtr = NonBinStart; + // Requires at least one binary digit. if (CurPtr == NumStart) return ReturnError(TokStart, "invalid binary number"); - StringRef Result(TokStart, CurPtr - TokStart); + StringRef Result(NumStart, CurPtr - NumStart); APInt Value(128, 0, true); - if (Result.substr(2).getAsInteger(2, Value)) + if (Result.getAsInteger(Radix, Value)) return ReturnError(TokStart, "invalid binary number"); + // Consume the [hH] suffix + if (Radix == 16) + ++CurPtr; + // The darwin/x86 (and x86-64) assembler accepts and ignores ULL and LL // suffixes on integer literals. SkipIgnoredIntegerSuffix(CurPtr); Index: test/MC/AsmParser/uppercase-hex.s =================================================================== --- test/MC/AsmParser/uppercase-hex.s +++ test/MC/AsmParser/uppercase-hex.s @@ -5,3 +5,7 @@ # CHECK: .short 1 .short 0B1 # CHECK: .short 1 +.short 0BH +# CHECK: .short 11 +.short 0BEDH +# CHECK: .short 3053