[cfe-commits] r68975 - in /cfe/trunk: lib/CodeGen/CodeGenModule.cpp test/CodeGen/illegal-UTF8.m

Steve Naroff snaroff at apple.com
Mon Apr 13 12:08:09 PDT 2009


Author: snaroff
Date: Mon Apr 13 14:08:08 2009
New Revision: 68975

URL: http://llvm.org/viewvc/llvm-project?rev=68975&view=rev
Log:
Fixed crasher in <rdar://problem/6780904> [irgen] Assertion failed: (Result == conversionOK && "UTF-8 to UTF-16 conversion failed"), function GetAddrOfConstantCFString, file CodeGenModule.cpp, line 1063.

Still a diagnostic related FIXME (will discuss with Daniel/Fariborz offline).

Added:
    cfe/trunk/test/CodeGen/illegal-UTF8.m
Modified:
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=68975&r1=68974&r2=68975&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Mon Apr 13 14:08:08 2009
@@ -1060,16 +1060,25 @@
     Result = ConvertUTF8toUTF16(&FromPtr, FromPtr+Literal->getByteLength(),
                                 &ToPtr, ToPtr+Literal->getByteLength(),
                                 strictConversion);
-    assert(Result == conversionOK && "UTF-8 to UTF-16 conversion failed");
+    if (Result == conversionOK) {
+      // FIXME: Storing UTF-16 in a C string is a hack to test Unicode strings
+      // without doing more surgery to this routine. Since we aren't explicitly
+      // checking for endianness here, it's also a bug (when generating code for
+      // a target that doesn't match the host endianness). Modeling this as an
+      // i16 array is likely the cleanest solution.
+      StringLength = ToPtr-&ToBuf[0];
+      str.assign((char *)&ToBuf[0], StringLength*2);// Twice as many UTF8 chars.
+      isUTF16 = true;
+    } else if (Result == sourceIllegal) {
+      // FIXME: GCC currently emits the following warning (in the backend):
+      // "warning: input conversion stopped due to an input byte that does not 
+      //           belong to the input codeset UTF-8"
+      // The clang backend doesn't currently emit any warnings.
+      str.assign(Literal->getStrData(), Literal->getByteLength());
+      StringLength = str.length();
+    } else
+      assert(Result == conversionOK && "UTF-8 to UTF-16 conversion failed");
     
-    // FIXME: Storing UTF-16 in a C string is a hack to test Unicode strings
-    // without doing more surgery to this routine. Since we aren't explicitly
-    // checking for endianness here, it's also a bug (when generating code for
-    // a target that doesn't match the host endianness). Modeling this as an i16
-    // array is likely the cleanest solution.
-    StringLength = ToPtr-&ToBuf[0];
-    str.assign((char *)&ToBuf[0], StringLength*2); // Twice as many UTF8 chars.
-    isUTF16 = true;
   } else {
     str.assign(Literal->getStrData(), Literal->getByteLength());
     StringLength = str.length();

Added: cfe/trunk/test/CodeGen/illegal-UTF8.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/illegal-UTF8.m?rev=68975&view=auto

==============================================================================
--- cfe/trunk/test/CodeGen/illegal-UTF8.m (added)
+++ cfe/trunk/test/CodeGen/illegal-UTF8.m Mon Apr 13 14:08:08 2009
@@ -0,0 +1,8 @@
+// RUN: clang %s -S -m64
+
+ at class NSString;
+
+// FIXME: GCC emits the following warning:
+// CodeGen/illegal-UTF8.m:4: warning: input conversion stopped due to an input byte that does not belong to the input codeset UTF-8
+
+NSString *S = @"\xff\xff___WAIT___";





More information about the cfe-commits mailing list