summaryrefslogtreecommitdiffstats
path: root/llvm/lib/VMCore/Constants.cpp
diff options
context:
space:
mode:
authorEvan Cheng <evan.cheng@apple.com>2006-10-26 19:15:05 +0000
committerEvan Cheng <evan.cheng@apple.com>2006-10-26 19:15:05 +0000
commit3763c5b1c4e1257400f3b40a0d7d4ccc8185dc94 (patch)
tree6b51772b493edfbf64e97873229a59d01b135a89 /llvm/lib/VMCore/Constants.cpp
parent91386800eaa94eb2048d631eab95cb7327a8e553 (diff)
downloadbcm5719-llvm-3763c5b1c4e1257400f3b40a0d7d4ccc8185dc94.tar.gz
bcm5719-llvm-3763c5b1c4e1257400f3b40a0d7d4ccc8185dc94.zip
Add isCString() - returns true if a ConstantArray is a CString.
llvm-svn: 31201
Diffstat (limited to 'llvm/lib/VMCore/Constants.cpp')
-rw-r--r--llvm/lib/VMCore/Constants.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/llvm/lib/VMCore/Constants.cpp b/llvm/lib/VMCore/Constants.cpp
index 2c996f5301f..ce29a21f86c 100644
--- a/llvm/lib/VMCore/Constants.cpp
+++ b/llvm/lib/VMCore/Constants.cpp
@@ -1073,6 +1073,19 @@ bool ConstantArray::isString() const {
return true;
}
+/// isCString - This method returns true if the array is a string (see
+/// isString) and it ends in a null byte \0 and does not contains any other
+/// null bytes except its terminator.
+bool ConstantArray::isCString() const {
+ if (!isString()) return false;
+ // This is safe because a ConstantArray cannot be a zero array.
+ for (unsigned i = 0, e = getNumOperands()-1; i != e; ++i)
+ if (cast<ConstantInt>(getOperand(i))->getZExtValue() == 0)
+ return false;
+ return true;
+}
+
+
// getAsString - If the sub-element type of this array is either sbyte or ubyte,
// then this method converts the array to an std::string and returns it.
// Otherwise, it asserts out.
OpenPOWER on IntegriCloud