[llvm-commits] [llvm-gcc-4.0] r42458 - /llvm-gcc-4.0/trunk/gcc/llvm-types.cpp

Devang Patel dpatel at apple.com
Fri Sep 28 16:54:26 PDT 2007


Author: dpatel
Date: Fri Sep 28 18:54:26 2007
New Revision: 42458

URL: http://llvm.org/viewvc/llvm-project?rev=42458&view=rev
Log:
Do not ignore packed member size while selecting union type.

Modified:
    llvm-gcc-4.0/trunk/gcc/llvm-types.cpp

Modified: llvm-gcc-4.0/trunk/gcc/llvm-types.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.0/trunk/gcc/llvm-types.cpp?rev=42458&r1=42457&r2=42458&view=diff

==============================================================================
--- llvm-gcc-4.0/trunk/gcc/llvm-types.cpp (original)
+++ llvm-gcc-4.0/trunk/gcc/llvm-types.cpp Fri Sep 28 18:54:26 2007
@@ -1826,11 +1826,31 @@
     SET_DECL_LLVM(Field, Idx);
     
     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