From 583dd6072eed7a446dad8f0e796fa34aec40aa12 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 9 Jan 2009 18:18:43 +0000 Subject: [PATCH] Fix PR3304 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@61995 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/ScalarReplAggregates.cpp | 14 ++++++++++++-- .../ScalarRepl/2009-01-09-scalarrepl-empty.ll | 15 +++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 test/Transforms/ScalarRepl/2009-01-09-scalarrepl-empty.ll diff --git a/lib/Transforms/Scalar/ScalarReplAggregates.cpp b/lib/Transforms/Scalar/ScalarReplAggregates.cpp index 041fd4917b4..d7b8b58ab08 100644 --- a/lib/Transforms/Scalar/ScalarReplAggregates.cpp +++ b/lib/Transforms/Scalar/ScalarReplAggregates.cpp @@ -856,6 +856,10 @@ void SROA::RewriteStoreUserOfWholeAlloca(StoreInst *SI, // Truncate down to an integer of the right size. uint64_t FieldSizeBits = TD->getTypeSizeInBits(FieldTy); + + // Ignore zero sized fields like {}, they obviously contain no data. + if (FieldSizeBits == 0) continue; + if (FieldSizeBits != AllocaSizeBits) EltVal = new TruncInst(EltVal, IntegerType::get(FieldSizeBits), "", SI); Value *DestField = NewElts[i]; @@ -887,6 +891,8 @@ void SROA::RewriteStoreUserOfWholeAlloca(StoreInst *SI, Shift = 0; for (unsigned i = 0, e = NewElts.size(); i != e; ++i) { + // Ignore zero sized fields like {}, they obviously contain no data. + if (ElementSizeBits == 0) continue; Value *EltVal = SrcVal; if (Shift) { @@ -959,8 +965,12 @@ void SROA::RewriteLoadUserOfWholeAlloca(LoadInst *LI, AllocationInst *AI, Value *SrcField = NewElts[i]; const Type *FieldTy = cast(SrcField->getType())->getElementType(); - const IntegerType *FieldIntTy = - IntegerType::get(TD->getTypeSizeInBits(FieldTy)); + uint64_t FieldSizeBits = TD->getTypeSizeInBits(FieldTy); + + // Ignore zero sized fields like {}, they obviously contain no data. + if (FieldSizeBits == 0) continue; + + const IntegerType *FieldIntTy = IntegerType::get(FieldSizeBits); if (!isa(FieldTy) && !FieldTy->isFloatingPoint() && !isa(FieldTy)) SrcField = new BitCastInst(SrcField, PointerType::getUnqual(FieldIntTy), diff --git a/test/Transforms/ScalarRepl/2009-01-09-scalarrepl-empty.ll b/test/Transforms/ScalarRepl/2009-01-09-scalarrepl-empty.ll new file mode 100644 index 00000000000..9cdf4a0ef24 --- /dev/null +++ b/test/Transforms/ScalarRepl/2009-01-09-scalarrepl-empty.ll @@ -0,0 +1,15 @@ +; RUN: llvm-as < %s | opt -scalarrepl | llvm-dis +; PR3304 + + %struct.c37304a__vrec = type { i8, %struct.c37304a__vrec___disc___XVN } + %struct.c37304a__vrec___disc___XVN = type { +%struct.c37304a__vrec___disc___XVN___O } + %struct.c37304a__vrec___disc___XVN___O = type { } + +define void @_ada_c37304a() { +entry: + %v = alloca %struct.c37304a__vrec ; + %0 = getelementptr %struct.c37304a__vrec* %v, i32 0, i32 0 + store i8 8, i8* %0, align 1 + unreachable +}