]> granicus.if.org Git - clang/commitdiff
Make sure UTF-16 strings end with a 16-bit null (as opposed to 8-bit).
authorDaniel Dunbar <daniel@zuster.org>
Mon, 3 Aug 2009 21:47:08 +0000 (21:47 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Mon, 3 Aug 2009 21:47:08 +0000 (21:47 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@78001 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenModule.cpp
test/CodeGen/darwin-string-literals.c

index 51fa3302a2384d643e6831a86ceb000650d59b69..08dc9930ba3d9bb8206ce12d3b19c6ae2d2ab174 100644 (file)
@@ -1251,6 +1251,9 @@ GetConstantCFStringEntry(llvm::StringMap<llvm::Constant*> &Map,
       AsBytes.push_back(Val & 0xFF);
     }
   }
+  // Append one extra null character, the second is automatically added by our
+  // caller.
+  AsBytes.push_back(0);
 
   IsUTF16 = true;
   return Map.GetOrCreateValue(llvm::StringRef(AsBytes.data(), AsBytes.size()));
index 2444a155b3a2357f565c09698aa8fd1dcb78a1f4..3be24b1bce93db5c3b0c0e9909e7113fcdea17e8 100644 (file)
@@ -2,14 +2,15 @@
 
 // CHECK-LSB: @.str = private constant [8 x i8] c"string0\00"
 // CHECK-LSB: @.str1 = private constant [8 x i8] c"string1\00", section "__TEXT,__cstring,cstring_literals"
-// CHECK-LSB: @__utf16_string_ = internal global [35 x i8] c"h\00e\00l\00l\00o\00 \00\92! \00\03& \00\90! \00w\00o\00r\00l\00d\00\00", section "__TEXT,__ustring", align 2
+// CHECK-LSB: @__utf16_string_ = internal global [36 x i8] c"h\00e\00l\00l\00o\00 \00\92! \00\03& \00\90! \00w\00o\00r\00l\00d\00\00\00", section "__TEXT,__ustring", align 2
 
 // RUN: clang-cc -triple powerpc-apple-darwin9 -emit-llvm %s -o - | FileCheck -check-prefix MSB %s
 
 // CHECK-MSB: @.str = private constant [8 x i8] c"string0\00"
 // CHECK-MSB: @.str1 = private constant [8 x i8] c"string1\00", section "__TEXT,__cstring,cstring_literals"
-// CHECK-MSB: @__utf16_string_ = internal global [35 x i8] c"\00h\00e\00l\00l\00o\00 !\92\00 &\03\00 !\90\00 \00w\00o\00r\00l\00d\00", section "__TEXT,__ustring", align 2
+// CHECK-MSB: @__utf16_string_ = internal global [36 x i8] c"\00h\00e\00l\00l\00o\00 !\92\00 &\03\00 !\90\00 \00w\00o\00r\00l\00d\00\00", section "__TEXT,__ustring", align 2
 
 const char *g0 = "string0";
 const void *g1 = __builtin___CFStringMakeConstantString("string1");
 const void *g2 = __builtin___CFStringMakeConstantString("hello \u2192 \u2603 \u2190 world");
+const void *g3 = __builtin___CFStringMakeConstantString("testâ„¢");