From 8d4141f83d9de379547cf05bd75d4c6cf894b189 Mon Sep 17 00:00:00 2001 From: Steve Naroff Date: Wed, 1 Apr 2009 13:55:36 +0000 Subject: [PATCH] More "prep" work for handling UTF16 CFString. Patch by Jean-Daniel Dupas. Thanks! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68203 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/Expr.h | 4 ++-- lib/CodeGen/CGExprConstant.cpp | 3 +-- lib/CodeGen/CGObjCMac.cpp | 7 +------ lib/CodeGen/CodeGenModule.cpp | 6 +++++- lib/CodeGen/CodeGenModule.h | 2 +- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index 832f83ca73..92b39632b8 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -533,9 +533,9 @@ public: const char *getStrData() const { return StrData; } unsigned getByteLength() const { return ByteLength; } bool isWide() const { return IsWide; } - bool containsNonAscii() const { + bool containsNonAsciiOrNull() const { for (unsigned i = 0; i < getByteLength(); ++i) - if (!isascii(getStrData()[i])) + if (!isascii(getStrData()[i]) || !getStrData()[i]) return true; return false; } diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp index 89b331950c..51ad5b67b8 100644 --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -442,9 +442,8 @@ public: break; const Expr *Arg = CE->getArg(0)->IgnoreParenCasts(); const StringLiteral *Literal = cast(Arg); - std::string S(Literal->getStrData(), Literal->getByteLength()); // FIXME: need to deal with UCN conversion issues. - return CGM.GetAddrOfConstantCFString(S); + return CGM.GetAddrOfConstantCFString(Literal); } case Expr::BlockExprClass: { std::string FunctionName; diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp index 351f8e2527..6b3ced08bf 100644 --- a/lib/CodeGen/CGObjCMac.cpp +++ b/lib/CodeGen/CGObjCMac.cpp @@ -900,12 +900,7 @@ llvm::Value *CGObjCMac::GetSelector(CGBuilderTy &Builder, Selector Sel) { llvm::Constant *CGObjCCommonMac::GenerateConstantString( const ObjCStringLiteral *SL) { - std::string Str(SL->getString()->getStrData(), - SL->getString()->getByteLength()); - if (SL->getString()->containsNonAscii()) { - // FIXME: Convert from UTF-8 to UTF-16. - } - return CGM.GetAddrOfConstantCFString(Str); + return CGM.GetAddrOfConstantCFString(SL->getString()); } /// Generates a message send where the super is the receiver. This is diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 101b2e58b7..d428c836af 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -1002,7 +1002,11 @@ static void appendFieldAndPadding(CodeGenModule &CGM, // We still need to work out the details of handling UTF-16. // See: llvm::Constant *CodeGenModule:: -GetAddrOfConstantCFString(const std::string &str) { +GetAddrOfConstantCFString(const StringLiteral *Literal) { + // if (Literal->containsNonAsciiOrNull()) { + // // FIXME: Convert from UTF-8 to UTF-16. + // } + std::string str(Literal->getStrData(), Literal->getByteLength()); llvm::StringMapEntry &Entry = CFConstantStringMap.GetOrCreateValue(&str[0], &str[str.length()]); diff --git a/lib/CodeGen/CodeGenModule.h b/lib/CodeGen/CodeGenModule.h index 8c7571fd64..c0dbbf8267 100644 --- a/lib/CodeGen/CodeGenModule.h +++ b/lib/CodeGen/CodeGenModule.h @@ -187,7 +187,7 @@ public: /// GetAddrOfConstantCFString - Return a pointer to a constant CFString object /// for the given string. - llvm::Constant *GetAddrOfConstantCFString(const std::string& str); + llvm::Constant *GetAddrOfConstantCFString(const StringLiteral *Literal); /// GetAddrOfConstantStringFromLiteral - Return a pointer to a constant array /// for the given string literal. -- 2.40.0