From a9668e0b4c451a1021fe650c451b54dc98c2d18d Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Fri, 3 Apr 2009 00:57:44 +0000 Subject: Add target hook for setting symbol prefix and section of unicode string literals. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68363 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenModule.cpp | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'lib/CodeGen/CodeGenModule.cpp') diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index fa475ced6e..1132c3f721 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -1082,13 +1082,31 @@ GetAddrOfConstantCFString(const StringLiteral *Literal) { CurField = NextField; NextField = *Field++; llvm::Constant *C = llvm::ConstantArray::get(str); + + const char *Sect, *Prefix; + bool isConstant; + if (isUTF16) { + Prefix = getContext().Target.getUnicodeStringSymbolPrefix(); + Sect = getContext().Target.getUnicodeStringSection(); + // FIXME: Why does GCC not set constant here? + isConstant = false; + } else { + Prefix = getContext().Target.getStringSymbolPrefix(true); + Sect = getContext().Target.getCFStringDataSection(); + // FIXME: -fwritable-strings should probably affect this, but we + // are following gcc here. + isConstant = true; + } llvm::GlobalVariable *GV = - new llvm::GlobalVariable(C->getType(), true, + new llvm::GlobalVariable(C->getType(), isConstant, llvm::GlobalValue::InternalLinkage, - C, getContext().Target.getStringSymbolPrefix(true), - &getModule()); - if (const char *Sect = getContext().Target.getCFStringDataSection()) + C, Prefix, &getModule()); + if (Sect) GV->setSection(Sect); + if (isUTF16) { + unsigned Align = getContext().getTypeAlign(getContext().ShortTy)/8; + GV->setAlignment(Align); + } appendFieldAndPadding(*this, Fields, CurField, NextField, llvm::ConstantExpr::getGetElementPtr(GV, Zeros, 2), CFRD, STy); -- cgit v1.2.3