[PATCH] D68598: [IA] Recognize hexadecimal escape sequences
Bill Wendling via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 7 22:27:29 PDT 2019
This revision was not accepted when it landed; it landed in state "Needs Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rL374018: [IA] Recognize hexadecimal escape sequences (authored by void, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D68598?vs=223666&id=223787#toc
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D68598/new/
https://reviews.llvm.org/D68598
Files:
llvm/trunk/lib/MC/MCParser/AsmParser.cpp
llvm/trunk/test/MC/AsmParser/directive_ascii.s
Index: llvm/trunk/lib/MC/MCParser/AsmParser.cpp
===================================================================
--- llvm/trunk/lib/MC/MCParser/AsmParser.cpp
+++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp
@@ -2914,11 +2914,27 @@
}
// 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') {
+ size_t length = Str.size();
+ if (i + 1 >= length || !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 (i + 1 < length && 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.
Index: llvm/trunk/test/MC/AsmParser/directive_ascii.s
===================================================================
--- llvm/trunk/test/MC/AsmParser/directive_ascii.s
+++ llvm/trunk/test/MC/AsmParser/directive_ascii.s
@@ -39,3 +39,8 @@
# CHECK: .byte 0
TEST6:
.string "B", "C"
+
+# CHECK: TEST7:
+# CHECK: .ascii "dk"
+TEST7:
+ .ascii "\x64\Xa6B"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68598.223787.patch
Type: text/x-patch
Size: 1636 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191008/fd87dc29/attachment-0001.bin>
More information about the llvm-commits
mailing list