summaryrefslogtreecommitdiffstats
path: root/llvm/include
diff options
context:
space:
mode:
authorGeorge Rimar <grimar@accesssoftek.com>2017-10-04 08:50:08 +0000
committerGeorge Rimar <grimar@accesssoftek.com>2017-10-04 08:50:08 +0000
commit099960d3222ded960033943a7b7a26340b0d7440 (patch)
tree833f6d17efac4934c4b255a2953e3582fbc151fd /llvm/include
parenta1a3f5c5e68793cb5bae5c798494e194cbe8ce58 (diff)
downloadbcm5719-llvm-099960d3222ded960033943a7b7a26340b0d7440.tar.gz
bcm5719-llvm-099960d3222ded960033943a7b7a26340b0d7440.zip
[MC] - Don't assert when non-english characters are used.
I found that llvm-mc does not like non-english characters even in comments, which it tries to tokenize. Problem happens because of functions like isdigit(), isalnum() which takes int argument and expects it is not negative. But at the same time MCParser uses char* to store input buffer poiner, char has signed value, so it is possible to pass negative value to one of functions from above and that triggers an assert. Testcase for demonstration is provided. To fix the issue helper functions were introduced in StringExtras.h Differential revision: https://reviews.llvm.org/D38461 llvm-svn: 314883
Diffstat (limited to 'llvm/include')
-rw-r--r--llvm/include/llvm/ADT/StringExtras.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/llvm/include/llvm/ADT/StringExtras.h b/llvm/include/llvm/ADT/StringExtras.h
index cc32bf43f29..a9a8c87d0d7 100644
--- a/llvm/include/llvm/ADT/StringExtras.h
+++ b/llvm/include/llvm/ADT/StringExtras.h
@@ -59,6 +59,21 @@ static inline unsigned hexDigitValue(char C) {
return -1U;
}
+/// Checks if character \p C is one of the 10 decimal digits.
+static inline bool isDigit(char C) { return C >= '0' && C <= '9'; }
+
+/// Checks if character \p C is a hexadecimal numeric character.
+static inline bool isHexDigit(char C) { return hexDigitValue(C) != -1U; }
+
+/// Checks if character \p C is a valid letter as classified by "C" locale.
+static inline bool isAlpha(char C) {
+ return ('a' <= C && C <= 'z') || ('A' <= C && C <= 'Z');
+}
+
+/// Checks whether character \p C is either a decimal digit or an uppercase or
+/// lowercase letter as classified by "C" locale.
+static inline bool isAlnum(char C) { return isAlpha(C) || isDigit(C); }
+
static inline std::string utohexstr(uint64_t X, bool LowerCase = false) {
char Buffer[17];
char *BufPtr = std::end(Buffer);
OpenPOWER on IntegriCloud