зеркало из https://github.com/microsoft/clang-1.git
codegen string literals using private linkage now like llvm-gcc, eliminating
some target hooks. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@75895 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
9797a8760b
Коммит
95b851e55c
|
@ -300,18 +300,6 @@ public:
|
||||||
|
|
||||||
virtual bool useGlobalsForAutomaticVariables() const { return false; }
|
virtual bool useGlobalsForAutomaticVariables() const { return false; }
|
||||||
|
|
||||||
/// getStringSymbolPrefix - Get the default symbol prefix to
|
|
||||||
/// use for string literals.
|
|
||||||
virtual const char *getStringSymbolPrefix(bool IsConstant) const {
|
|
||||||
return ".str";
|
|
||||||
}
|
|
||||||
|
|
||||||
/// getCFStringSymbolPrefix - Get the default symbol prefix
|
|
||||||
/// to use for CFString literals.
|
|
||||||
virtual const char *getCFStringSymbolPrefix() const {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
/// getUnicodeStringSymbolPrefix - Get the default symbol prefix to
|
/// getUnicodeStringSymbolPrefix - Get the default symbol prefix to
|
||||||
/// use for string literals.
|
/// use for string literals.
|
||||||
virtual const char *getUnicodeStringSymbolPrefix() const {
|
virtual const char *getUnicodeStringSymbolPrefix() const {
|
||||||
|
|
|
@ -238,14 +238,6 @@ public:
|
||||||
this->TLSSupported = false;
|
this->TLSSupported = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual const char *getCFStringSymbolPrefix() const {
|
|
||||||
return "\01L_unnamed_cfstring_";
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual const char *getStringSymbolPrefix(bool IsConstant) const {
|
|
||||||
return IsConstant ? "\01LC" : "\01lC";
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual const char *getUnicodeStringSymbolPrefix() const {
|
virtual const char *getUnicodeStringSymbolPrefix() const {
|
||||||
return "__utf16_string_";
|
return "__utf16_string_";
|
||||||
}
|
}
|
||||||
|
|
|
@ -494,16 +494,15 @@ llvm::Constant *CodeGenModule::EmitAnnotateAttr(llvm::GlobalValue *GV,
|
||||||
|
|
||||||
// Get the two global values corresponding to the ConstantArrays we just
|
// Get the two global values corresponding to the ConstantArrays we just
|
||||||
// created to hold the bytes of the strings.
|
// created to hold the bytes of the strings.
|
||||||
const char *StringPrefix = getContext().Target.getStringSymbolPrefix(true);
|
|
||||||
llvm::GlobalValue *annoGV =
|
llvm::GlobalValue *annoGV =
|
||||||
new llvm::GlobalVariable(*M, anno->getType(), false,
|
new llvm::GlobalVariable(*M, anno->getType(), false,
|
||||||
llvm::GlobalValue::InternalLinkage, anno,
|
llvm::GlobalValue::PrivateLinkage, anno,
|
||||||
GV->getName() + StringPrefix);
|
GV->getName());
|
||||||
// translation unit name string, emitted into the llvm.metadata section.
|
// translation unit name string, emitted into the llvm.metadata section.
|
||||||
llvm::GlobalValue *unitGV =
|
llvm::GlobalValue *unitGV =
|
||||||
new llvm::GlobalVariable(*M, unit->getType(), false,
|
new llvm::GlobalVariable(*M, unit->getType(), false,
|
||||||
llvm::GlobalValue::InternalLinkage, unit,
|
llvm::GlobalValue::PrivateLinkage, unit,
|
||||||
StringPrefix);
|
".str");
|
||||||
|
|
||||||
// Create the ConstantStruct for the global annotation.
|
// Create the ConstantStruct for the global annotation.
|
||||||
llvm::Constant *Fields[4] = {
|
llvm::Constant *Fields[4] = {
|
||||||
|
@ -1287,22 +1286,25 @@ GetAddrOfConstantCFString(const StringLiteral *Literal) {
|
||||||
|
|
||||||
const char *Sect, *Prefix;
|
const char *Sect, *Prefix;
|
||||||
bool isConstant;
|
bool isConstant;
|
||||||
|
llvm::GlobalValue::LinkageTypes Linkage;
|
||||||
if (isUTF16) {
|
if (isUTF16) {
|
||||||
Prefix = getContext().Target.getUnicodeStringSymbolPrefix();
|
Prefix = getContext().Target.getUnicodeStringSymbolPrefix();
|
||||||
Sect = getContext().Target.getUnicodeStringSection();
|
Sect = getContext().Target.getUnicodeStringSection();
|
||||||
|
// FIXME: why do utf strings get "l" labels instead of "L" labels?
|
||||||
|
Linkage = llvm::GlobalValue::InternalLinkage;
|
||||||
// FIXME: Why does GCC not set constant here?
|
// FIXME: Why does GCC not set constant here?
|
||||||
isConstant = false;
|
isConstant = false;
|
||||||
} else {
|
} else {
|
||||||
Prefix = getContext().Target.getStringSymbolPrefix(true);
|
Prefix = ".str";
|
||||||
Sect = getContext().Target.getCFStringDataSection();
|
Sect = getContext().Target.getCFStringDataSection();
|
||||||
|
Linkage = llvm::GlobalValue::PrivateLinkage;
|
||||||
// FIXME: -fwritable-strings should probably affect this, but we
|
// FIXME: -fwritable-strings should probably affect this, but we
|
||||||
// are following gcc here.
|
// are following gcc here.
|
||||||
isConstant = true;
|
isConstant = true;
|
||||||
}
|
}
|
||||||
llvm::GlobalVariable *GV =
|
llvm::GlobalVariable *GV =
|
||||||
new llvm::GlobalVariable(getModule(), C->getType(), isConstant,
|
new llvm::GlobalVariable(getModule(), C->getType(), isConstant,
|
||||||
llvm::GlobalValue::InternalLinkage,
|
Linkage, C, Prefix);
|
||||||
C, Prefix);
|
|
||||||
if (Sect)
|
if (Sect)
|
||||||
GV->setSection(Sect);
|
GV->setSection(Sect);
|
||||||
if (isUTF16) {
|
if (isUTF16) {
|
||||||
|
@ -1323,8 +1325,8 @@ GetAddrOfConstantCFString(const StringLiteral *Literal) {
|
||||||
// The struct.
|
// The struct.
|
||||||
C = VMContext.getConstantStruct(STy, Fields);
|
C = VMContext.getConstantStruct(STy, Fields);
|
||||||
GV = new llvm::GlobalVariable(getModule(), C->getType(), true,
|
GV = new llvm::GlobalVariable(getModule(), C->getType(), true,
|
||||||
llvm::GlobalVariable::InternalLinkage, C,
|
llvm::GlobalVariable::PrivateLinkage, C,
|
||||||
getContext().Target.getCFStringSymbolPrefix());
|
"_unnamed_cfstring_");
|
||||||
if (const char *Sect = getContext().Target.getCFStringSection())
|
if (const char *Sect = getContext().Target.getCFStringSection())
|
||||||
GV->setSection(Sect);
|
GV->setSection(Sect);
|
||||||
Entry.setValue(GV);
|
Entry.setValue(GV);
|
||||||
|
@ -1383,7 +1385,7 @@ static llvm::Constant *GenerateStringLiteral(const std::string &str,
|
||||||
|
|
||||||
// Create a global variable for this string
|
// Create a global variable for this string
|
||||||
return new llvm::GlobalVariable(CGM.getModule(), C->getType(), constant,
|
return new llvm::GlobalVariable(CGM.getModule(), C->getType(), constant,
|
||||||
llvm::GlobalValue::InternalLinkage,
|
llvm::GlobalValue::PrivateLinkage,
|
||||||
C, GlobalName);
|
C, GlobalName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1401,14 +1403,14 @@ llvm::Constant *CodeGenModule::GetAddrOfConstantString(const std::string &str,
|
||||||
|
|
||||||
// Get the default prefix if a name wasn't specified.
|
// Get the default prefix if a name wasn't specified.
|
||||||
if (!GlobalName)
|
if (!GlobalName)
|
||||||
GlobalName = getContext().Target.getStringSymbolPrefix(IsConstant);
|
GlobalName = ".str";
|
||||||
|
|
||||||
// Don't share any string literals if strings aren't constant.
|
// Don't share any string literals if strings aren't constant.
|
||||||
if (!IsConstant)
|
if (!IsConstant)
|
||||||
return GenerateStringLiteral(str, false, *this, GlobalName);
|
return GenerateStringLiteral(str, false, *this, GlobalName);
|
||||||
|
|
||||||
llvm::StringMapEntry<llvm::Constant *> &Entry =
|
llvm::StringMapEntry<llvm::Constant *> &Entry =
|
||||||
ConstantStringMap.GetOrCreateValue(&str[0], &str[str.length()]);
|
ConstantStringMap.GetOrCreateValue(&str[0], &str[str.length()]);
|
||||||
|
|
||||||
if (Entry.getValue())
|
if (Entry.getValue())
|
||||||
return Entry.getValue();
|
return Entry.getValue();
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
// RUN: clang-cc -triple i386-apple-darwin9 -emit-llvm %s -o %t &&
|
// RUN: clang-cc -triple i386-apple-darwin9 -emit-llvm %s -o - | FileCheck %s
|
||||||
|
|
||||||
// RUN: grep -F '@"\01LC" = internal constant [8 x i8] c"string0\00"' %t &&
|
// CHECK: @.str = private constant [8 x i8] c"string0\00"
|
||||||
// RUN: grep -F '@"\01LC1" = internal constant [8 x i8] c"string1\00", section "__TEXT,__cstring,cstring_literals"' %t &&
|
// CHECK: @.str1 = private constant [8 x i8] c"string1\00", section "__TEXT,__cstring,cstring_literals"
|
||||||
// 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 &&
|
// CHECK: @__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
|
||||||
// RUN: true
|
|
||||||
|
|
||||||
const char *g0 = "string0";
|
const char *g0 = "string0";
|
||||||
const void *g1 = __builtin___CFStringMakeConstantString("string1");
|
const void *g1 = __builtin___CFStringMakeConstantString("string1");
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// RUN: clang-cc -emit-llvm %s -o %t &&
|
// RUN: clang-cc -emit-llvm %s -o %t &&
|
||||||
// RUN: grep 'internal constant \[10 x i8\]' %t &&
|
// RUN: grep 'private constant \[10 x i8\]' %t &&
|
||||||
// RUN: not grep -F "[5 x i8]" %t &&
|
// RUN: not grep -F "[5 x i8]" %t &&
|
||||||
// RUN: not grep "store " %t
|
// RUN: not grep "store " %t
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче