summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Target/TargetLoweringObjectFile.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2012-01-24 14:17:05 +0000
committerChris Lattner <sabre@nondot.org>2012-01-24 14:17:05 +0000
commit139822fc8344d9d0c036cd03ca4ddf0a4555685c (patch)
treec2ac8a5cce33adb795b9369e4df205c5c20e7cc8 /llvm/lib/Target/TargetLoweringObjectFile.cpp
parent2068393140cc2377e7de97e0fcb93864a40e0436 (diff)
downloadbcm5719-llvm-139822fc8344d9d0c036cd03ca4ddf0a4555685c.tar.gz
bcm5719-llvm-139822fc8344d9d0c036cd03ca4ddf0a4555685c.zip
C++, CBE, and TLOF support for ConstantDataSequential
llvm-svn: 148805
Diffstat (limited to 'llvm/lib/Target/TargetLoweringObjectFile.cpp')
-rw-r--r--llvm/lib/Target/TargetLoweringObjectFile.cpp23
1 files changed, 18 insertions, 5 deletions
diff --git a/llvm/lib/Target/TargetLoweringObjectFile.cpp b/llvm/lib/Target/TargetLoweringObjectFile.cpp
index 70abe5a0527..ec3b1946f31 100644
--- a/llvm/lib/Target/TargetLoweringObjectFile.cpp
+++ b/llvm/lib/Target/TargetLoweringObjectFile.cpp
@@ -73,12 +73,12 @@ static bool isSuitableForBSS(const GlobalVariable *GV, bool NoZerosInBSS) {
/// IsNullTerminatedString - Return true if the specified constant (which is
/// known to have a type that is an array of 1/2/4 byte elements) ends with a
-/// nul value and contains no other nuls in it.
+/// nul value and contains no other nuls in it. Note that this is more general
+/// than ConstantDataSequential::isString because we allow 2 & 4 byte strings.
static bool IsNullTerminatedString(const Constant *C) {
- ArrayType *ATy = cast<ArrayType>(C->getType());
-
- // First check: is we have constant array of i8 terminated with zero
+ // First check: is we have constant array terminated with zero
if (const ConstantArray *CVA = dyn_cast<ConstantArray>(C)) {
+ ArrayType *ATy = cast<ArrayType>(C->getType());
if (ATy->getNumElements() == 0) return false;
ConstantInt *Null =
@@ -94,10 +94,23 @@ static bool IsNullTerminatedString(const Constant *C) {
return false;
return true;
}
+ if (const ConstantDataSequential *CDS = dyn_cast<ConstantDataSequential>(C)) {
+ unsigned NumElts = CDS->getNumElements();
+ assert(NumElts != 0 && "Can't have an empty CDS");
+
+ if (CDS->getElementAsInteger(NumElts-1) != 0)
+ return false; // Not null terminated.
+
+ // Verify that the null doesn't occur anywhere else in the string.
+ for (unsigned i = 0; i != NumElts-1; ++i)
+ if (CDS->getElementAsInteger(i) == 0)
+ return false;
+ return true;
+ }
// Another possibility: [1 x i8] zeroinitializer
if (isa<ConstantAggregateZero>(C))
- return ATy->getNumElements() == 1;
+ return cast<ArrayType>(C->getType())->getNumElements() == 1;
return false;
}
OpenPOWER on IntegriCloud