[llvm-commits] [llvm-gcc-4.2] r42464 - /llvm-gcc-4.2/trunk/gcc/llvm-types.cpp
Devang Patel
dpatel at apple.com
Fri Sep 28 18:20:12 PDT 2007
Author: dpatel
Date: Fri Sep 28 20:20:11 2007
New Revision: 42464
URL: http://llvm.org/viewvc/llvm-project?rev=42464&view=rev
Log:
Do not ignore packed member size while selecting union type.
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=42464&r1=42463&r2=42464&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-types.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-types.cpp Fri Sep 28 20:20:11 2007
@@ -1836,11 +1836,31 @@
SetFieldIndex(Field, 0);
const Type *TheTy = ConvertType(TREE_TYPE(Field));
+ bool isPacked = false;
unsigned Size = TD.getTypeSize(TheTy);
unsigned Align = TD.getABITypeAlignment(TheTy);
+ if (const StructType *STy = dyn_cast<StructType>(TheTy))
+ if (STy->isPacked())
+ isPacked = true;
+
adjustPaddingElement(UnionTy, TheTy);
- if (UnionTy == 0 || Align > MaxAlign
- || (MaxAlign == Align && Size > MaxSize)) {
+
+ // Select TheTy as union type if it meets one of the following criteria
+ // 1) UnionTy is 0
+ // 2) TheTy alignment is more then UnionTy
+ // 3) TheTy size is greater than UnionTy size and TheTy alignment is equal to UnionTy
+ // 4) TheTy size is greater then UnionTy size and TheTy is packed
+ bool useTheTy = false;
+ if (UnionTy == 0)
+ useTheTy = true;
+ else if (Align > MaxAlign)
+ useTheTy = true;
+ else if (MaxAlign == Align && Size > MaxSize)
+ useTheTy = true;
+ else if (isPacked && Size > MaxSize)
+ useTheTy = true;
+
+ if (useTheTy) {
UnionTy = TheTy;
MaxSize = MAX(MaxSize, Size);
MaxAlign = Align;
More information about the llvm-commits
mailing list