summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-09-27 17:00:18 +0000
committerDouglas Gregor <dgregor@apple.com>2011-09-27 17:00:18 +0000
commit4d68366b2f280242401f5184dc4fc35ca32ae819 (patch)
treea7f81986501898c9f03eb62d217f98315555ee5e
parentff5d0965b0a89a6ccbe952b64b1e27ab128e6d93 (diff)
downloadbcm5719-llvm-4d68366b2f280242401f5184dc4fc35ca32ae819.tar.gz
bcm5719-llvm-4d68366b2f280242401f5184dc4fc35ca32ae819.zip
When parsing a character literal, extract the characters from the
buffer as an 'unsigned char', so that integer promotion doesn't sign-extend character values > 127 into oblivion. Fixes <rdar://problem/10188919>. llvm-svn: 140608
-rw-r--r--clang/lib/Lex/LiteralSupport.cpp2
-rw-r--r--clang/test/Lexer/utf8-char-literal.cpp4
2 files changed, 5 insertions, 1 deletions
diff --git a/clang/lib/Lex/LiteralSupport.cpp b/clang/lib/Lex/LiteralSupport.cpp
index ef385a8aedb..96550e6492b 100644
--- a/clang/lib/Lex/LiteralSupport.cpp
+++ b/clang/lib/Lex/LiteralSupport.cpp
@@ -784,7 +784,7 @@ CharLiteralParser::CharLiteralParser(const char *begin, const char *end,
// Is this a Universal Character Name escape?
if (begin[0] != '\\') // If this is a normal character, consume it.
- ResultChar = *begin++;
+ ResultChar = (unsigned char)*begin++;
else { // Otherwise, this is an escape character.
unsigned CharWidth = getCharWidth(Kind, PP.getTargetInfo());
// Check for UCN.
diff --git a/clang/test/Lexer/utf8-char-literal.cpp b/clang/test/Lexer/utf8-char-literal.cpp
new file mode 100644
index 00000000000..1dbd669cfd2
--- /dev/null
+++ b/clang/test/Lexer/utf8-char-literal.cpp
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++0x -fsyntax-only -verify %s
+
+int array0[u'ñ' == u'\xf1'? 1 : -1];
+int array1['ñ' != u'\xf1'? 1 : -1];
OpenPOWER on IntegriCloud