diff options
author | Anders Carlsson <andersca@mac.com> | 2009-07-23 04:50:01 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-07-23 04:50:01 +0000 |
commit | 20d6d0474efc662924c4ca00a3511aac3782c4b0 (patch) | |
tree | caa62626b7e111d3ee86af161bf5789722f3801a /lib/CodeGen/CGExprConstant.cpp | |
parent | 36292550118ebdd5e0fe8e46df74f7202046d316 (diff) |
Use arrays as union padding. Also, since the resulting struct will always contain a single element and either a single i8 element or an array of i8s, there's no reason to use a packed struct.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@76854 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExprConstant.cpp')
-rw-r--r-- | lib/CodeGen/CGExprConstant.cpp | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp index 4f1f58fefd..43284b5173 100644 --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -243,15 +243,18 @@ public: Types.push_back(C->getType()); unsigned CurSize = CGM.getTargetData().getTypeAllocSize(C->getType()); unsigned TotalSize = CGM.getTargetData().getTypeAllocSize(Ty); - while (CurSize < TotalSize) { - Elts.push_back(VMContext.getNullValue(llvm::Type::Int8Ty)); - Types.push_back(llvm::Type::Int8Ty); - CurSize++; + + assert(CurSize <= TotalSize && "Union size mismatch!"); + if (unsigned NumPadBytes = TotalSize - CurSize) { + const llvm::Type *Ty = llvm::Type::Int8Ty; + if (NumPadBytes > 1) + Ty = VMContext.getArrayType(Ty, NumPadBytes); + + Elts.push_back(VMContext.getNullValue(Ty)); + Types.push_back(Ty); } - // This always generates a packed struct - // FIXME: Try to generate an unpacked struct when we can - llvm::StructType* STy = VMContext.getStructType(Types, true); + llvm::StructType* STy = VMContext.getStructType(Types, false); return VMContext.getConstantStruct(STy, Elts); } |