1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 11:02:59 +02:00

[IA] Recognize hexadecimal escape sequences

Summary:
Implement support for hexadecimal escape sequences to match how GNU 'as'
handles them. I.e., read all hexadecimal characters and truncate to the
lower 16 bits.

Reviewers: nickdesaulniers

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D68483

llvm-svn: 373888
This commit is contained in:
Bill Wendling 2019-10-07 09:54:53 +00:00
parent be68f43712
commit 97854ad2fb
2 changed files with 21 additions and 1 deletions

View File

@ -2914,11 +2914,26 @@ bool AsmParser::parseEscapedString(std::string &Data) {
}
// Recognize escaped characters. Note that this escape semantics currently
// loosely follows Darwin 'as'. Notably, it doesn't support hex escapes.
// loosely follows Darwin 'as'.
++i;
if (i == e)
return TokError("unexpected backslash at end of string");
// Recognize hex sequences similarly to GNU 'as'.
if (Str[i] == 'x' || Str[i] == 'X') {
if (!isHexDigit(Str[i + 1]))
return TokError("invalid hexadecimal escape sequence");
// Consume hex characters. GNU 'as' reads all hexadecimal characters and
// then truncates to the lower 16 bits. Seems reasonable.
unsigned Value = 0;
while (isHexDigit(Str[i + 1]))
Value = Value * 16 + hexDigitValue(Str[++i]);
Data += (unsigned char)(Value & 0xFF);
continue;
}
// Recognize octal sequences.
if ((unsigned)(Str[i] - '0') <= 7) {
// Consume up to three octal characters.

View File

@ -39,3 +39,8 @@ TEST5:
# CHECK: .byte 0
TEST6:
.string "B", "C"
# CHECK: TEST7:
# CHECK: .ascii "dk"
TEST7:
.ascii "\x64\Xa6B"