From 434da48d0e35764f18b3fc96c75504746050b046 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Mon, 3 Aug 2009 21:47:08 +0000 Subject: [PATCH] Make sure UTF-16 strings end with a 16-bit null (as opposed to 8-bit). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@78001 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenModule.cpp | 3 +++ test/CodeGen/darwin-string-literals.c | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 51fa3302a2..08dc9930ba 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -1251,6 +1251,9 @@ GetConstantCFStringEntry(llvm::StringMap &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())); diff --git a/test/CodeGen/darwin-string-literals.c b/test/CodeGen/darwin-string-literals.c index 2444a155b3..3be24b1bce 100644 --- a/test/CodeGen/darwin-string-literals.c +++ b/test/CodeGen/darwin-string-literals.c @@ -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™"); -- 2.40.0