[llvm-commits] [llvm-gcc-4.2] r51927 - /llvm-gcc-4.2/trunk/gcc/llvm-types.cpp
Duncan Sands
baldrick at free.fr
Wed Jun 4 00:04:38 PDT 2008
Author: baldrick
Date: Wed Jun 4 02:04:38 2008
New Revision: 51927
URL: http://llvm.org/viewvc/llvm-project?rev=51927&view=rev
Log:
If the gcc union type is less aligned than the
LLVM struct, pack the struct. While there,
remove some dead code that creates a filler
for empty unions (this was already handled
by the general case a few lines before) and
remove trailing whitespace. This cures some
testsuite failures caused by fixing the way
the union element is chosen.
Modified:
llvm-gcc-4.2/trunk/gcc/llvm-types.cpp
Modified: llvm-gcc-4.2/trunk/gcc/llvm-types.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-types.cpp?rev=51927&r1=51926&r2=51927&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-types.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-types.cpp Wed Jun 4 02:04:38 2008
@@ -2264,40 +2264,36 @@
}
std::vector<const Type*> UnionElts;
- unsigned UnionSize = 0;
+ unsigned EltAlign = 0;
+ unsigned EltSize = 0;
if (UnionTy) { // Not an empty union.
- UnionSize = TD.getABITypeSize(UnionTy);
+ EltAlign = TD.getABITypeAlignment(UnionTy);
+ EltSize = TD.getABITypeSize(UnionTy);
UnionElts.push_back(UnionTy);
}
-
+
// If the LLVM struct requires explicit tail padding to be the same size as
// the GCC union, insert tail padding now. This handles cases where the union
// has larger alignment than the largest member does, thus requires tail
// padding.
if (TYPE_SIZE(type) && TREE_CODE(TYPE_SIZE(type)) == INTEGER_CST) {
unsigned GCCTypeSize = ((unsigned)TREE_INT_CST_LOW(TYPE_SIZE(type))+7)/8;
-
- if (UnionSize != GCCTypeSize) {
- assert(UnionSize < GCCTypeSize &&
+
+ if (EltSize != GCCTypeSize) {
+ assert(EltSize < GCCTypeSize &&
"LLVM type size doesn't match GCC type size!");
const Type *PadTy = Type::Int8Ty;
- if (GCCTypeSize-UnionSize != 1)
- PadTy = ArrayType::get(PadTy, GCCTypeSize-UnionSize);
+ if (GCCTypeSize-EltSize != 1)
+ PadTy = ArrayType::get(PadTy, GCCTypeSize-EltSize);
UnionElts.push_back(PadTy);
}
}
-
- // If this is an empty union, but there is tail padding, make a filler.
- if (UnionTy == 0) {
- unsigned Size = ((unsigned)TREE_INT_CST_LOW(TYPE_SIZE(type))+7)/8;
- UnionTy = Type::Int8Ty;
- if (Size != 1) UnionTy = ArrayType::get(UnionTy, Size);
- }
-
- const Type *ResultTy = StructType::get(UnionElts, false);
+
+ bool isPacked = EltAlign > TYPE_ALIGN_UNIT(type);
+ const Type *ResultTy = StructType::get(UnionElts, isPacked);
const OpaqueType *OldTy = cast_or_null<OpaqueType>(GET_TYPE_LLVM(type));
TypeDB.setType(type, ResultTy);
-
+
// If there was a forward declaration for this type that is now resolved,
// refine anything that used it to the new type.
if (OldTy)
More information about the llvm-commits
mailing list