summaryrefslogtreecommitdiff
path: root/lib/IR
diff options
context:
space:
mode:
authorBjorn Steinbrink <bsteinbr@gmail.com>2017-12-17 21:20:16 +0000
committerBjorn Steinbrink <bsteinbr@gmail.com>2017-12-17 21:20:16 +0000
commit53f8289df4894f4c5e9775f165b85faab8014afd (patch)
tree554a3ef7e677a87c18965e8970be207ae5b3d5c3 /lib/IR
parent89e36802541d3939ca9e8daa7428df723e70b902 (diff)
Re-commit "Properly handle multi-element and dynamically sized allocas in getPointerDereferenceableBytes()""
llvm-clang-x86_64-expensive-checks-win is still broken, so the failure seems unrelated. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320953 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/IR')
-rw-r--r--lib/IR/Value.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/IR/Value.cpp b/lib/IR/Value.cpp
index 773ed89db04..eae697b2e4b 100644
--- a/lib/IR/Value.cpp
+++ b/lib/IR/Value.cpp
@@ -619,11 +619,11 @@ const Value *Value::stripInBoundsOffsets() const {
return stripPointerCastsAndOffsets<PSK_InBounds>(this);
}
-unsigned Value::getPointerDereferenceableBytes(const DataLayout &DL,
+uint64_t Value::getPointerDereferenceableBytes(const DataLayout &DL,
bool &CanBeNull) const {
assert(getType()->isPointerTy() && "must be pointer");
- unsigned DerefBytes = 0;
+ uint64_t DerefBytes = 0;
CanBeNull = false;
if (const Argument *A = dyn_cast<Argument>(this)) {
DerefBytes = A->getDereferenceableBytes();
@@ -655,8 +655,10 @@ unsigned Value::getPointerDereferenceableBytes(const DataLayout &DL,
CanBeNull = true;
}
} else if (auto *AI = dyn_cast<AllocaInst>(this)) {
- if (AI->getAllocatedType()->isSized()) {
- DerefBytes = DL.getTypeStoreSize(AI->getAllocatedType());
+ const ConstantInt *ArraySize = dyn_cast<ConstantInt>(AI->getArraySize());
+ if (ArraySize && AI->getAllocatedType()->isSized()) {
+ DerefBytes = DL.getTypeStoreSize(AI->getAllocatedType()) *
+ ArraySize->getZExtValue();
CanBeNull = false;
}
} else if (auto *GV = dyn_cast<GlobalVariable>(this)) {