From cf8e168baf75b7ede6493d0373d64545c29c1a90 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Fri, 13 May 2011 18:13:10 +0000 Subject: [PATCH] Produce UTF-8 strings with -fconstant-string-class -fno-constant-cfstrings. Patch by Jonathan Schleifer. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@131298 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenModule.cpp | 36 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index ea2b2d16d6..e4b3210d1e 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -1641,6 +1641,16 @@ GetConstantCFStringEntry(llvm::StringMap &Map, return Map.GetOrCreateValue(llvm::StringRef(AsBytes.data(), AsBytes.size())); } +static llvm::StringMapEntry & +GetConstantStringEntry(llvm::StringMap &Map, + const StringLiteral *Literal, + unsigned &StringLength) +{ + llvm::StringRef String = Literal->getString(); + StringLength = String.size(); + return Map.GetOrCreateValue(String); +} + llvm::Constant * CodeGenModule::GetAddrOfConstantCFString(const StringLiteral *Literal) { unsigned StringLength = 0; @@ -1734,11 +1744,8 @@ CodeGenModule::GetAddrOfConstantCFString(const StringLiteral *Literal) { llvm::Constant * CodeGenModule::GetAddrOfConstantString(const StringLiteral *Literal) { unsigned StringLength = 0; - bool isUTF16 = false; llvm::StringMapEntry &Entry = - GetConstantCFStringEntry(CFConstantStringMap, Literal, - getTargetData().isLittleEndian(), - isUTF16, StringLength); + GetConstantStringEntry(CFConstantStringMap, Literal, StringLength); if (llvm::Constant *C = Entry.getValue()) return C; @@ -1786,28 +1793,15 @@ CodeGenModule::GetAddrOfConstantString(const StringLiteral *Literal) { llvm::GlobalValue::LinkageTypes Linkage; bool isConstant; - if (isUTF16) { - // FIXME: why do utf strings get "_" labels instead of "L" labels? - Linkage = llvm::GlobalValue::InternalLinkage; - // Note: -fwritable-strings doesn't make unicode NSStrings writable, but - // does make plain ascii ones writable. - isConstant = true; - } else { - Linkage = llvm::GlobalValue::PrivateLinkage; - isConstant = !Features.WritableStrings; - } + Linkage = llvm::GlobalValue::PrivateLinkage; + isConstant = !Features.WritableStrings; llvm::GlobalVariable *GV = new llvm::GlobalVariable(getModule(), C->getType(), isConstant, Linkage, C, ".str"); GV->setUnnamedAddr(true); - if (isUTF16) { - CharUnits Align = getContext().getTypeAlignInChars(getContext().ShortTy); - GV->setAlignment(Align.getQuantity()); - } else { - CharUnits Align = getContext().getTypeAlignInChars(getContext().CharTy); - GV->setAlignment(Align.getQuantity()); - } + CharUnits Align = getContext().getTypeAlignInChars(getContext().CharTy); + GV->setAlignment(Align.getQuantity()); Fields[1] = llvm::ConstantExpr::getGetElementPtr(GV, Zeros, 2); // String length. -- 2.50.1