diff options
author | Steve Naroff <snaroff@apple.com> | 2009-04-01 15:50:34 +0000 |
---|---|---|
committer | Steve Naroff <snaroff@apple.com> | 2009-04-01 15:50:34 +0000 |
commit | 29cae66bde8b9d1694d85e6fa43fcf5a3ab46e2d (patch) | |
tree | f55c931a819fe55561ce0856e74618897f5546a6 /clang/lib/CodeGen/CodeGenModule.cpp | |
parent | 2e0757f3199f7bb77f59928e210ea0fb1a06256d (diff) | |
download | bcm5719-llvm-29cae66bde8b9d1694d85e6fa43fcf5a3ab46e2d.tar.gz bcm5719-llvm-29cae66bde8b9d1694d85e6fa43fcf5a3ab46e2d.zip |
Add ConvertUTF module from http://www.unicode.org/Public/PROGRAMS/CVTUTF.
#ifdef'd out the 5 conversion routines that we don't currently need.
Still need a bit more work in GetAddrOfConstantCFString(). Added a FIXME to indicate this.
Expect to remove the FIXME today...
llvm-svn: 68208
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index d428c836afb..2e84c6049d5 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -24,6 +24,7 @@ #include "clang/Basic/Diagnostic.h" #include "clang/Basic/SourceManager.h" #include "clang/Basic/TargetInfo.h" +#include "clang/Basic/ConvertUTF.h" #include "llvm/CallingConv.h" #include "llvm/Module.h" #include "llvm/Intrinsics.h" @@ -1003,9 +1004,21 @@ static void appendFieldAndPadding(CodeGenModule &CGM, // See: <rdr://2996215> llvm::Constant *CodeGenModule:: GetAddrOfConstantCFString(const StringLiteral *Literal) { - // if (Literal->containsNonAsciiOrNull()) { - // // FIXME: Convert from UTF-8 to UTF-16. - // } + bool isUTF16 = false; + if (Literal->containsNonAsciiOrNull()) { + // Convert from UTF-8 to UTF-16. + llvm::SmallVector<UTF16, 128> ToBuf(Literal->getByteLength()); + const UTF8 *FromPtr = (UTF8 *)Literal->getStrData(); + UTF16 *ToPtr = &ToBuf[0]; + + ConversionResult Result; + Result = ConvertUTF8toUTF16(&FromPtr, FromPtr+Literal->getByteLength(), + &ToPtr, ToPtr+Literal->getByteLength(), + strictConversion); + assert(Result == conversionOK && "UTF-8 to UTF-16 conversion failed"); + isUTF16 = true; + // FIXME: Do something with the converted value! + } std::string str(Literal->getStrData(), Literal->getByteLength()); llvm::StringMapEntry<llvm::Constant *> &Entry = CFConstantStringMap.GetOrCreateValue(&str[0], &str[str.length()]); @@ -1056,7 +1069,9 @@ GetAddrOfConstantCFString(const StringLiteral *Literal) { NextField = *Field++; const llvm::Type *Ty = getTypes().ConvertType(getContext().UnsignedIntTy); appendFieldAndPadding(*this, Fields, CurField, NextField, - llvm::ConstantInt::get(Ty, 0x07C8), CFRD, STy); + isUTF16 ? llvm::ConstantInt::get(Ty, 0x07d0) + : llvm::ConstantInt::get(Ty, 0x07C8), + CFRD, STy); // String pointer. CurField = NextField; |