GlobalISel: support zero-sized allocas
authorTim Northover <tnorthover@apple.com>
Wed, 27 Jul 2016 17:47:54 +0000 (17:47 +0000)
committerTim Northover <tnorthover@apple.com>
Wed, 27 Jul 2016 17:47:54 +0000 (17:47 +0000)
All allocas must be at least 1 byte at the MachineIR level so we allocate just
one byte.

llvm-svn: 276897

llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
llvm/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll

index 6a8712e..e035c66 100644 (file)
@@ -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());
index ac2e744..b51a0e5 100644 (file)
@@ -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
 }