[cfe-commits] r68363 - in /cfe/trunk: include/clang/Basic/TargetInfo.h lib/Basic/Targets.cpp lib/CodeGen/CodeGenModule.cpp test/CodeGen/darwin-string-literals.c
Daniel Dunbar
daniel at zuster.org
Thu Apr 2 17:57:45 PDT 2009
Author: ddunbar
Date: Thu Apr 2 19:57:44 2009
New Revision: 68363
URL: http://llvm.org/viewvc/llvm-project?rev=68363&view=rev
Log:
Add target hook for setting symbol prefix and section of unicode
string literals.
Modified:
cfe/trunk/include/clang/Basic/TargetInfo.h
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/test/CodeGen/darwin-string-literals.c
Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=68363&r1=68362&r2=68363&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Thu Apr 2 19:57:44 2009
@@ -257,6 +257,18 @@
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 {
Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=68363&r1=68362&r2=68363&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Thu Apr 2 19:57:44 2009
@@ -658,6 +658,14 @@
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 @@
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_";
}
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=68363&r1=68362&r2=68363&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Thu Apr 2 19:57:44 2009
@@ -1082,13 +1082,31 @@
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);
Modified: cfe/trunk/test/CodeGen/darwin-string-literals.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/darwin-string-literals.c?rev=68363&r1=68362&r2=68363&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/darwin-string-literals.c (original)
+++ cfe/trunk/test/CodeGen/darwin-string-literals.c Thu Apr 2 19:57:44 2009
@@ -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");
More information about the cfe-commits
mailing list