summaryrefslogtreecommitdiffstats
path: root/contrib/llvm/lib/IR/Constants.cpp
diff options
context:
space:
mode:
authordim <dim@FreeBSD.org>2015-02-19 22:20:19 +0000
committerdim <dim@FreeBSD.org>2015-02-19 22:20:19 +0000
commit1e024675bcd5e4ace8bffb2dd6afd3fa8b8ad7f3 (patch)
tree84663adb8262b7962030778aaba745cd98e8b356 /contrib/llvm/lib/IR/Constants.cpp
parent184b3c7999c408b8e298b506ccfdff9d81c9ffd5 (diff)
parent49b6407b6cc89756540e2097c1cf8b9bb4a422e1 (diff)
downloadFreeBSD-src-1e024675bcd5e4ace8bffb2dd6afd3fa8b8ad7f3.zip
FreeBSD-src-1e024675bcd5e4ace8bffb2dd6afd3fa8b8ad7f3.tar.gz
Merge llvm 3.6.0rc4 from ^/vendor/llvm/dist, merge clang 3.6.0rc4 from
^/vendor/clang/dist, resolve conflicts, and update patches.
Diffstat (limited to 'contrib/llvm/lib/IR/Constants.cpp')
-rw-r--r--contrib/llvm/lib/IR/Constants.cpp23
1 files changed, 19 insertions, 4 deletions
diff --git a/contrib/llvm/lib/IR/Constants.cpp b/contrib/llvm/lib/IR/Constants.cpp
index 1d2602a..44052b2 100644
--- a/contrib/llvm/lib/IR/Constants.cpp
+++ b/contrib/llvm/lib/IR/Constants.cpp
@@ -257,11 +257,11 @@ Constant *Constant::getAggregateElement(unsigned Elt) const {
if (const ConstantVector *CV = dyn_cast<ConstantVector>(this))
return Elt < CV->getNumOperands() ? CV->getOperand(Elt) : nullptr;
- if (const ConstantAggregateZero *CAZ =dyn_cast<ConstantAggregateZero>(this))
- return CAZ->getElementValue(Elt);
+ if (const ConstantAggregateZero *CAZ = dyn_cast<ConstantAggregateZero>(this))
+ return Elt < CAZ->getNumElements() ? CAZ->getElementValue(Elt) : nullptr;
if (const UndefValue *UV = dyn_cast<UndefValue>(this))
- return UV->getElementValue(Elt);
+ return Elt < UV->getNumElements() ? UV->getElementValue(Elt) : nullptr;
if (const ConstantDataSequential *CDS =dyn_cast<ConstantDataSequential>(this))
return Elt < CDS->getNumElements() ? CDS->getElementAsConstant(Elt)
@@ -764,6 +764,14 @@ Constant *ConstantAggregateZero::getElementValue(unsigned Idx) const {
return getStructElement(Idx);
}
+unsigned ConstantAggregateZero::getNumElements() const {
+ const Type *Ty = getType();
+ if (const auto *AT = dyn_cast<ArrayType>(Ty))
+ return AT->getNumElements();
+ if (const auto *VT = dyn_cast<VectorType>(Ty))
+ return VT->getNumElements();
+ return Ty->getStructNumElements();
+}
//===----------------------------------------------------------------------===//
// UndefValue Implementation
@@ -797,7 +805,14 @@ UndefValue *UndefValue::getElementValue(unsigned Idx) const {
return getStructElement(Idx);
}
-
+unsigned UndefValue::getNumElements() const {
+ const Type *Ty = getType();
+ if (const auto *AT = dyn_cast<ArrayType>(Ty))
+ return AT->getNumElements();
+ if (const auto *VT = dyn_cast<VectorType>(Ty))
+ return VT->getNumElements();
+ return Ty->getStructNumElements();
+}
//===----------------------------------------------------------------------===//
// ConstantXXX Classes
OpenPOWER on IntegriCloud