diff options
-rw-r--r-- | clang/include/clang/Basic/TargetInfo.h | 12 | ||||
-rw-r--r-- | clang/lib/Basic/Targets.cpp | 16 | ||||
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 26 | ||||
-rw-r--r-- | clang/test/CodeGen/darwin-string-literals.c | 3 |
4 files changed, 52 insertions, 5 deletions
diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h index d9a8bc1f500..4fd624a6269 100644 --- a/clang/include/clang/Basic/TargetInfo.h +++ b/clang/include/clang/Basic/TargetInfo.h @@ -257,6 +257,18 @@ public: return ""; } + /// getUnicodeStringSymbolPrefix - Get the default symbol prefix to + /// use for string literals. + virtual const char *getUnicodeStringSymbolPrefix() const { + return ".str"; + } + + /// getUnicodeStringSymbolPrefix - Get the default symbol prefix to + /// use for string literals. + virtual const char *getUnicodeStringSection() const { + return 0; + } + /// getCFStringSection - Return the section to use for the CFString /// literals, or 0 if no special section is used. virtual const char *getCFStringSection() const { diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp index ce55ec80465..5f5ba60e858 100644 --- a/clang/lib/Basic/Targets.cpp +++ b/clang/lib/Basic/Targets.cpp @@ -658,6 +658,14 @@ public: return IsConstant ? "\01LC" : "\01lC"; } + virtual const char *getUnicodeStringSymbolPrefix() const { + return "__utf16_string_"; + } + + virtual const char *getUnicodeStringSection() const { + return "__TEXT,__ustring"; + } + virtual const char *getCFStringSymbolPrefix() const { return "\01LC"; } @@ -810,6 +818,14 @@ public: return IsConstant ? "\01LC" : "\01lC"; } + virtual const char *getUnicodeStringSymbolPrefix() const { + return "__utf16_string_"; + } + + virtual const char *getUnicodeStringSection() const { + return "__TEXT,__ustring"; + } + virtual const char *getCFStringSymbolPrefix() const { return "\01L_unnamed_cfstring_"; } diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index fa475ced6e8..1132c3f721d 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/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); diff --git a/clang/test/CodeGen/darwin-string-literals.c b/clang/test/CodeGen/darwin-string-literals.c index 5bfb84e91d4..ff245fcc7a5 100644 --- a/clang/test/CodeGen/darwin-string-literals.c +++ b/clang/test/CodeGen/darwin-string-literals.c @@ -2,8 +2,9 @@ // RUN: grep -F '@"\01LC" = internal constant [8 x i8] c"string0\00"' %t && // RUN: grep -F '@"\01LC1" = internal constant [8 x i8] c"string1\00", section "__TEXT,__cstring,cstring_literals"' %t && - +// RUN: grep -F '@__utf16_string_ = internal global [35 x i8] c"h\00e\00l\00l\00o\00 \00\92! \00\03& \00\90! \00w\00o\00r\00l\00d\00\00", section "__TEXT,__ustring", align 2' %t && // RUN: true const char *g0 = "string0"; const void *g1 = __builtin___CFStringMakeConstantString("string1"); +const void *g2 = __builtin___CFStringMakeConstantString("hello \u2192 \u2603 \u2190 world"); |