diff options
author | Steve Naroff <snaroff@apple.com> | 2009-04-01 21:16:31 +0000 |
---|---|---|
committer | Steve Naroff <snaroff@apple.com> | 2009-04-01 21:16:31 +0000 |
commit | 8d816d6cb521d3d97036766710e0bc694c8de934 (patch) | |
tree | b80f493f4a570baad9d26496766403a39f6e9a8b /clang/lib/CodeGen/CodeGenModule.cpp | |
parent | afb066d1f551c0449c0fc1d53d41bee2bbfe674e (diff) | |
download | bcm5719-llvm-8d816d6cb521d3d97036766710e0bc694c8de934.tar.gz bcm5719-llvm-8d816d6cb521d3d97036766710e0bc694c8de934.zip |
CodeGenModule::GetAddrOfConstantCFString():
- Finish up support for converting UTF8->UTF16 to support ObjC @"string" constants.
Remove warning from CheckObjCString.
As the FIXME in the test case indicates, I still have a bug to work out (apparently with \u handling).
llvm-svn: 68245
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 2e84c6049d5..44a045ef8a5 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -1000,10 +1000,11 @@ static void appendFieldAndPadding(CodeGenModule &CGM, } } -// We still need to work out the details of handling UTF-16. -// See: <rdr://2996215> llvm::Constant *CodeGenModule:: GetAddrOfConstantCFString(const StringLiteral *Literal) { + std::string str; + unsigned StringLength; + bool isUTF16 = false; if (Literal->containsNonAsciiOrNull()) { // Convert from UTF-8 to UTF-16. @@ -1016,10 +1017,14 @@ GetAddrOfConstantCFString(const StringLiteral *Literal) { &ToPtr, ToPtr+Literal->getByteLength(), strictConversion); assert(Result == conversionOK && "UTF-8 to UTF-16 conversion failed"); + + StringLength = ToPtr-&ToBuf[0]; + str.assign((char *)&ToBuf[0], StringLength*2); // Twice as many UTF8 chars. isUTF16 = true; - // FIXME: Do something with the converted value! + } else { + str.assign(Literal->getStrData(), Literal->getByteLength()); + StringLength = str.length(); } - std::string str(Literal->getStrData(), Literal->getByteLength()); llvm::StringMapEntry<llvm::Constant *> &Entry = CFConstantStringMap.GetOrCreateValue(&str[0], &str[str.length()]); @@ -1093,7 +1098,7 @@ GetAddrOfConstantCFString(const StringLiteral *Literal) { NextField = 0; Ty = getTypes().ConvertType(getContext().LongTy); appendFieldAndPadding(*this, Fields, CurField, NextField, - llvm::ConstantInt::get(Ty, str.length()), CFRD, STy); + llvm::ConstantInt::get(Ty, StringLength), CFRD, STy); // The struct. C = llvm::ConstantStruct::get(STy, Fields); |