summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CGExprConstant.cpp
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-07-23 04:50:01 +0000
committerAnders Carlsson <andersca@mac.com>2009-07-23 04:50:01 +0000
commit718a89a50191e57215e37472d19c84a304477eda (patch)
tree96043a5c59ba1c6dcad3dba00e33a87a64b74fd5 /clang/lib/CodeGen/CGExprConstant.cpp
parentdc13b7c637f1268744dca71cdd772b2d2f20d785 (diff)
downloadbcm5719-llvm-718a89a50191e57215e37472d19c84a304477eda.tar.gz
bcm5719-llvm-718a89a50191e57215e37472d19c84a304477eda.zip
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.
llvm-svn: 76854
Diffstat (limited to 'clang/lib/CodeGen/CGExprConstant.cpp')
-rw-r--r--clang/lib/CodeGen/CGExprConstant.cpp17
1 files changed, 10 insertions, 7 deletions
diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp
index 4f1f58fefda..43284b51730 100644
--- a/clang/lib/CodeGen/CGExprConstant.cpp
+++ b/clang/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);
}
OpenPOWER on IntegriCloud