summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Northover <tnorthover@apple.com>2016-07-27 17:47:54 +0000
committerTim Northover <tnorthover@apple.com>2016-07-27 17:47:54 +0000
commit8d2f52e035ceb361d3410d2b76b48a287c529356 (patch)
treeba4097b350146a830a1c97b25515b5e0a3440755
parentebebd6d2ff8430a32d294819ee05001f21a9808b (diff)
downloadbcm5719-llvm-8d2f52e035ceb361d3410d2b76b48a287c529356.tar.gz
bcm5719-llvm-8d2f52e035ceb361d3410d2b76b48a287c529356.zip
GlobalISel: support zero-sized allocas
All allocas must be at least 1 byte at the MachineIR level so we allocate just one byte. llvm-svn: 276897
-rw-r--r--llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp3
-rw-r--r--llvm/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll3
2 files changed, 6 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
index 6a8712e184b..e035c66b24a 100644
--- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
@@ -172,6 +172,9 @@ bool IRTranslator::translateStaticAlloca(const AllocaInst &AI) {
unsigned Size =
ElementSize * cast<ConstantInt>(AI.getArraySize())->getZExtValue();
+ // Always allocate at least one byte.
+ Size = std::max(Size, 1u);
+
unsigned Alignment = AI.getAlignment();
if (!Alignment)
Alignment = DL->getABITypeAlignment(AI.getAllocatedType());
diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll b/llvm/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll
index ac2e744426b..b51a0e56a0a 100644
--- a/llvm/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll
+++ b/llvm/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll
@@ -23,13 +23,16 @@ define i64 @addi64(i64 %arg1, i64 %arg2) {
; CHECK-NEXT: - { id: 0, name: ptr1, offset: 0, size: 8, alignment: 8 }
; CHECK-NEXT: - { id: 1, name: ptr2, offset: 0, size: 8, alignment: 1 }
; CHECK-NEXT: - { id: 2, name: ptr3, offset: 0, size: 128, alignment: 8 }
+; CHECK-NEXT: - { id: 3, name: ptr4, offset: 0, size: 1, alignment: 8 }
; CHECK: %{{[0-9]+}}(64) = G_FRAME_INDEX p0 %stack.0.ptr1
; CHECK: %{{[0-9]+}}(64) = G_FRAME_INDEX p0 %stack.1.ptr2
; CHECK: %{{[0-9]+}}(64) = G_FRAME_INDEX p0 %stack.2.ptr3
+; CHECK: %{{[0-9]+}}(64) = G_FRAME_INDEX p0 %stack.3.ptr4
define void @allocai64() {
%ptr1 = alloca i64
%ptr2 = alloca i64, align 1
%ptr3 = alloca i64, i32 16
+ %ptr4 = alloca [0 x i64]
ret void
}
OpenPOWER on IntegriCloud