aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAnton Korobeynikov <asl@math.spbu.ru>2009-01-27 22:29:24 +0000
committerAnton Korobeynikov <asl@math.spbu.ru>2009-01-27 22:29:24 +0000
commit72bb40229ec455d6c39f0c1482ca6621e41a380a (patch)
tree0a6c7384580253fe8fb69f303d5063f416baf03e /lib
parent5f7c41c9d091ad3ac9d0f5ebcf1ef9acd98e4e64 (diff)
downloadexternal_llvm-72bb40229ec455d6c39f0c1482ca6621e41a380a.zip
external_llvm-72bb40229ec455d6c39f0c1482ca6621e41a380a.tar.gz
external_llvm-72bb40229ec455d6c39f0c1482ca6621e41a380a.tar.bz2
Treat [1 x i8] zeroinitializer as a C string, placing such stuff into
mergeable string section. I don't see any bad impact of such decision (rather then placing it into mergeable const section, as it was before), but at least Darwin linker won't complain anymore. The problem in LLVM is that we don't have special type for string constants (like gcc does). Even more, we have two separate types: ConstatArray for non-null strings and ConstantAggregateZero for null stuff.... It's a bit weird :) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@63142 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Target/DarwinTargetAsmInfo.cpp4
-rw-r--r--lib/Target/ELFTargetAsmInfo.cpp3
-rw-r--r--lib/Target/TargetAsmInfo.cpp23
3 files changed, 24 insertions, 6 deletions
diff --git a/lib/Target/DarwinTargetAsmInfo.cpp b/lib/Target/DarwinTargetAsmInfo.cpp
index 57e7014..cc05c09 100644
--- a/lib/Target/DarwinTargetAsmInfo.cpp
+++ b/lib/Target/DarwinTargetAsmInfo.cpp
@@ -115,9 +115,9 @@ const Section*
DarwinTargetAsmInfo::MergeableStringSection(const GlobalVariable *GV) const {
const TargetData *TD = TM.getTargetData();
Constant *C = cast<GlobalVariable>(GV)->getInitializer();
- const Type *Type = cast<ConstantArray>(C)->getType()->getElementType();
+ const Type *Ty = cast<ArrayType>(C->getType())->getElementType();
- unsigned Size = TD->getTypePaddedSize(Type);
+ unsigned Size = TD->getTypePaddedSize(Ty);
if (Size) {
unsigned Align = TD->getPreferredAlignment(GV);
if (Align <= 32)
diff --git a/lib/Target/ELFTargetAsmInfo.cpp b/lib/Target/ELFTargetAsmInfo.cpp
index 5a3b93a..624b95c 100644
--- a/lib/Target/ELFTargetAsmInfo.cpp
+++ b/lib/Target/ELFTargetAsmInfo.cpp
@@ -126,8 +126,7 @@ const Section*
ELFTargetAsmInfo::MergeableStringSection(const GlobalVariable *GV) const {
const TargetData *TD = TM.getTargetData();
Constant *C = cast<GlobalVariable>(GV)->getInitializer();
- const ConstantArray *CVA = cast<ConstantArray>(C);
- const Type *Ty = CVA->getType()->getElementType();
+ const Type *Ty = cast<ArrayType>(C->getType())->getElementType();
unsigned Size = TD->getTypePaddedSize(Ty);
if (Size <= 16) {
diff --git a/lib/Target/TargetAsmInfo.cpp b/lib/Target/TargetAsmInfo.cpp
index 4666875..d687e2f 100644
--- a/lib/Target/TargetAsmInfo.cpp
+++ b/lib/Target/TargetAsmInfo.cpp
@@ -13,6 +13,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/Constants.h"
+#include "llvm/DerivedTypes.h"
#include "llvm/GlobalVariable.h"
#include "llvm/Function.h"
#include "llvm/Module.h"
@@ -170,6 +171,25 @@ static bool isSuitableForBSS(const GlobalVariable *GV) {
return (C->isNullValue() && !GV->isConstant() && !NoZerosInBSS);
}
+static bool isConstantString(const Constant *C) {
+ // First check: is we have constant array of i8 terminated with zero
+ const ConstantArray *CVA = dyn_cast<ConstantArray>(C);
+ // Check, if initializer is a null-terminated string
+ if (CVA && CVA->isCString())
+ return true;
+
+ // Another possibility: [1 x i8] zeroinitializer
+ if (isa<ConstantAggregateZero>(C)) {
+ if (const ArrayType *Ty = dyn_cast<ArrayType>(C->getType())) {
+ return (Ty->getElementType() == Type::Int8Ty &&
+ Ty->getNumElements() == 1);
+ }
+ }
+
+ return false;
+}
+
+
SectionKind::Kind
TargetAsmInfo::SectionKindForGlobal(const GlobalValue *GV) const {
// Early exit - functions should be always in text sections.
@@ -191,9 +211,8 @@ TargetAsmInfo::SectionKindForGlobal(const GlobalValue *GV) const {
if (C->ContainsRelocations())
return SectionKind::ROData;
else {
- const ConstantArray *CVA = dyn_cast<ConstantArray>(C);
// Check, if initializer is a null-terminated string
- if (CVA && CVA->isCString())
+ if (isConstantString(C))
return SectionKind::RODataMergeStr;
else
return SectionKind::RODataMergeConst;