forked from OSchip/llvm-project
fix some cfstring related issues:
1) -fwritable-string does affect the non-utf16 version of cfstrings just not the utf16 ones. 2) utf16 strings should always be marked constant, as the __TEXT segment is readonly. 3) The name of the global doesn't matter, remove it from TargetInfo. 4) Trust the asmprinter to drop cstrings into the right section, like llvmgcc does now. This fixes rdar://7115750 llvm-svn: 84077
This commit is contained in:
parent
4ae411e096
commit
4f8a2e22c0
|
@ -300,12 +300,6 @@ public:
|
||||||
|
|
||||||
virtual bool useGlobalsForAutomaticVariables() const { return false; }
|
virtual bool useGlobalsForAutomaticVariables() const { return false; }
|
||||||
|
|
||||||
/// getUnicodeStringSymbolPrefix - Get the default symbol prefix to
|
|
||||||
/// use for string literals.
|
|
||||||
virtual const char *getUnicodeStringSymbolPrefix() const {
|
|
||||||
return ".str";
|
|
||||||
}
|
|
||||||
|
|
||||||
/// getUnicodeStringSection - Return the section to use for unicode
|
/// getUnicodeStringSection - Return the section to use for unicode
|
||||||
/// string literals, or 0 if no special section is used.
|
/// string literals, or 0 if no special section is used.
|
||||||
virtual const char *getUnicodeStringSection() const {
|
virtual const char *getUnicodeStringSection() const {
|
||||||
|
@ -318,14 +312,6 @@ public:
|
||||||
return "__DATA,__cfstring";
|
return "__DATA,__cfstring";
|
||||||
}
|
}
|
||||||
|
|
||||||
/// getCFStringDataSection - Return the section to use for the
|
|
||||||
/// constant string data associated with a CFString literal, or 0 if
|
|
||||||
/// no special section is used.
|
|
||||||
virtual const char *getCFStringDataSection() const {
|
|
||||||
return "__TEXT,__cstring,cstring_literals";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// isValidSectionSpecifier - This is an optional hook that targets can
|
/// isValidSectionSpecifier - This is an optional hook that targets can
|
||||||
/// implement to perform semantic checking on attribute((section("foo")))
|
/// implement to perform semantic checking on attribute((section("foo")))
|
||||||
/// specifiers. In this case, "foo" is passed in to be checked. If the
|
/// specifiers. In this case, "foo" is passed in to be checked. If the
|
||||||
|
|
|
@ -197,10 +197,6 @@ public:
|
||||||
this->TLSSupported = false;
|
this->TLSSupported = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual const char *getUnicodeStringSymbolPrefix() const {
|
|
||||||
return "__utf16_string_";
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual const char *getUnicodeStringSection() const {
|
virtual const char *getUnicodeStringSection() const {
|
||||||
return "__TEXT,__ustring";
|
return "__TEXT,__ustring";
|
||||||
}
|
}
|
||||||
|
|
|
@ -1434,27 +1434,24 @@ CodeGenModule::GetAddrOfConstantCFString(const StringLiteral *Literal) {
|
||||||
// String pointer.
|
// String pointer.
|
||||||
llvm::Constant *C = llvm::ConstantArray::get(VMContext, Entry.getKey().str());
|
llvm::Constant *C = llvm::ConstantArray::get(VMContext, Entry.getKey().str());
|
||||||
|
|
||||||
const char *Sect, *Prefix;
|
const char *Sect = 0;
|
||||||
bool isConstant;
|
|
||||||
llvm::GlobalValue::LinkageTypes Linkage;
|
llvm::GlobalValue::LinkageTypes Linkage;
|
||||||
|
bool isConstant;
|
||||||
if (isUTF16) {
|
if (isUTF16) {
|
||||||
Prefix = getContext().Target.getUnicodeStringSymbolPrefix();
|
|
||||||
Sect = getContext().Target.getUnicodeStringSection();
|
Sect = getContext().Target.getUnicodeStringSection();
|
||||||
// FIXME: why do utf strings get "l" labels instead of "L" labels?
|
// FIXME: why do utf strings get "_" labels instead of "L" labels?
|
||||||
Linkage = llvm::GlobalValue::InternalLinkage;
|
Linkage = llvm::GlobalValue::InternalLinkage;
|
||||||
// FIXME: Why does GCC not set constant here?
|
// Note: -fwritable-strings doesn't make unicode CFStrings writable, but
|
||||||
isConstant = false;
|
// does make plain ascii ones writable.
|
||||||
} else {
|
|
||||||
Prefix = ".str";
|
|
||||||
Sect = getContext().Target.getCFStringDataSection();
|
|
||||||
Linkage = llvm::GlobalValue::PrivateLinkage;
|
|
||||||
// FIXME: -fwritable-strings should probably affect this, but we
|
|
||||||
// are following gcc here.
|
|
||||||
isConstant = true;
|
isConstant = true;
|
||||||
|
} else {
|
||||||
|
Linkage = llvm::GlobalValue::PrivateLinkage;
|
||||||
|
isConstant = !Features.WritableStrings;
|
||||||
}
|
}
|
||||||
|
|
||||||
llvm::GlobalVariable *GV =
|
llvm::GlobalVariable *GV =
|
||||||
new llvm::GlobalVariable(getModule(), C->getType(), isConstant,
|
new llvm::GlobalVariable(getModule(), C->getType(), isConstant, Linkage, C,
|
||||||
Linkage, C, Prefix);
|
".str");
|
||||||
if (Sect)
|
if (Sect)
|
||||||
GV->setSection(Sect);
|
GV->setSection(Sect);
|
||||||
if (isUTF16) {
|
if (isUTF16) {
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
// RUN: clang-cc -triple i386-apple-darwin9 -emit-llvm %s -o - | FileCheck -check-prefix LSB %s &&
|
// RUN: clang-cc -triple i386-apple-darwin9 -emit-llvm %s -o - | FileCheck -check-prefix LSB %s &&
|
||||||
|
|
||||||
// CHECK-LSB: @.str = private constant [8 x i8] c"string0\00"
|
// CHECK-LSB: @.str = private constant [8 x i8] c"string0\00"
|
||||||
// CHECK-LSB: @.str1 = private constant [8 x i8] c"string1\00", section "__TEXT,__cstring,cstring_literals"
|
// CHECK-LSB: @.str1 = private constant [8 x i8] c"string1\00"
|
||||||
// CHECK-LSB: @__utf16_string_ = internal global [36 x i8] c"h\00e\00l\00l\00o\00 \00\92! \00\03& \00\90! \00w\00o\00r\00l\00d\00\00\00", section "__TEXT,__ustring", align 2
|
// CHECK-LSB: @.str2 = internal constant [36 x i8] c"h\00e\00l\00l\00o\00 \00\92! \00\03& \00\90! \00w\00o\00r\00l\00d\00\00\00", section "__TEXT,__ustring", align 2
|
||||||
|
|
||||||
// RUN: clang-cc -triple powerpc-apple-darwin9 -emit-llvm %s -o - | FileCheck -check-prefix MSB %s
|
// RUN: clang-cc -triple powerpc-apple-darwin9 -emit-llvm %s -o - | FileCheck -check-prefix MSB %s
|
||||||
|
|
||||||
// CHECK-MSB: @.str = private constant [8 x i8] c"string0\00"
|
// CHECK-MSB: @.str = private constant [8 x i8] c"string0\00"
|
||||||
// CHECK-MSB: @.str1 = private constant [8 x i8] c"string1\00", section "__TEXT,__cstring,cstring_literals"
|
// CHECK-MSB: @.str1 = private constant [8 x i8] c"string1\00"
|
||||||
// CHECK-MSB: @__utf16_string_ = internal global [36 x i8] c"\00h\00e\00l\00l\00o\00 !\92\00 &\03\00 !\90\00 \00w\00o\00r\00l\00d\00\00", section "__TEXT,__ustring", align 2
|
// CHECK-MSB: @.str2 = internal constant [36 x i8] c"\00h\00e\00l\00l\00o\00 !\92\00 &\03\00 !\90\00 \00w\00o\00r\00l\00d\00\00", section "__TEXT,__ustring", align 2
|
||||||
|
|
||||||
const char *g0 = "string0";
|
const char *g0 = "string0";
|
||||||
const void *g1 = __builtin___CFStringMakeConstantString("string1");
|
const void *g1 = __builtin___CFStringMakeConstantString("string1");
|
||||||
|
|
Loading…
Reference in New Issue