[cfe-commits] r158391 - in /cfe/trunk: lib/Lex/LiteralSupport.cpp test/Lexer/char-literal.cpp

Richard Smith richard-llvm at metafoo.co.uk
Tue Jun 12 22:41:30 PDT 2012


Author: rsmith
Date: Wed Jun 13 00:41:29 2012
New Revision: 158391

URL: http://llvm.org/viewvc/llvm-project?rev=158391&view=rev
Log:
Fix off-by-one error in UTF-16 encoding: don't try to use a surrogate pair for U+FFFF.

Modified:
    cfe/trunk/lib/Lex/LiteralSupport.cpp
    cfe/trunk/test/Lexer/char-literal.cpp

Modified: cfe/trunk/lib/Lex/LiteralSupport.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/LiteralSupport.cpp?rev=158391&r1=158390&r2=158391&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/LiteralSupport.cpp (original)
+++ cfe/trunk/lib/Lex/LiteralSupport.cpp Wed Jun 13 00:41:29 2012
@@ -322,7 +322,7 @@
     // using reinterpret_cast.
     UTF16 *ResultPtr = reinterpret_cast<UTF16*>(ResultBuf);
 
-    if (UcnVal < (UTF32)0xFFFF) {
+    if (UcnVal <= (UTF32)0xFFFF) {
       *ResultPtr = UcnVal;
       ResultBuf += 2;
       return;

Modified: cfe/trunk/test/Lexer/char-literal.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/char-literal.cpp?rev=158391&r1=158390&r2=158391&view=diff
==============================================================================
--- cfe/trunk/test/Lexer/char-literal.cpp (original)
+++ cfe/trunk/test/Lexer/char-literal.cpp Wed Jun 13 00:41:29 2012
@@ -22,3 +22,6 @@
 
 char32_t n = U'ab'; // expected-error {{Unicode character literals may not contain multiple characters}}
 char16_t o = '👽'; // expected-error {{character too large for enclosing character literal type}}
+
+char16_t p[2] = u"\U0000FFFF";
+char16_t q[2] = u"\U00010000"; // expected-error {{too long}}





More information about the cfe-commits mailing list