AsmParser: Verifier that the contents of a hex integer are hex

llvm-svn: 223856
This commit is contained in:
David Majnemer 2014-12-09 23:50:38 +00:00
parent 8759649013
commit aa5d70764f
1 changed files with 7 additions and 1 deletions

View File

@ -757,7 +757,13 @@ lltok::Kind LLLexer::LexIdentifier() {
isxdigit(static_cast<unsigned char>(TokStart[3]))) {
int len = CurPtr-TokStart-3;
uint32_t bits = len * 4;
APInt Tmp(bits, StringRef(TokStart+3, len), 16);
StringRef HexStr(TokStart + 3, len);
if (!std::all_of(HexStr.begin(), HexStr.end(), isxdigit)) {
// Bad token, return it as an error.
CurPtr = TokStart+3;
return lltok::Error;
}
APInt Tmp(bits, HexStr, 16);
uint32_t activeBits = Tmp.getActiveBits();
if (activeBits > 0 && activeBits < bits)
Tmp = Tmp.trunc(activeBits);