[llvm-commits] [126435] Fix PR 1344

dpatel at apple.com dpatel at apple.com
Mon Apr 23 15:07:28 PDT 2007


Revision: 126435
Author:   dpatel
Date:     2007-04-23 15:07:27 -0700 (Mon, 23 Apr 2007)

Log Message:
-----------
Fix PR 1344

Modified Paths:
--------------
    apple-local/branches/llvm/gcc/llvm-types.cpp

Modified: apple-local/branches/llvm/gcc/llvm-types.cpp
===================================================================
--- apple-local/branches/llvm/gcc/llvm-types.cpp	2007-04-23 22:06:28 UTC (rev 126434)
+++ apple-local/branches/llvm/gcc/llvm-types.cpp	2007-04-23 22:07:27 UTC (rev 126435)
@@ -1560,8 +1560,10 @@
   bool OldConvertingStruct = ConvertingStruct;
   ConvertingStruct = true;
   
-  // Find the type with the largest size, and if we have multiple things with
-  // the same size, the thing with the largest alignment.
+  // Find the type with the largest aligment, and if we have multiple types with
+  // the same alignment, select one with largest size. If type with max. align
+  // is smaller then other types then we will add padding later on anyway to 
+  // match union size.
   const TargetData &TD = getTargetData();
   const Type *UnionTy = 0;
   unsigned MaxSize = 0, MaxAlign = 0;
@@ -1576,9 +1578,10 @@
     const Type *TheTy = ConvertType(TREE_TYPE(Field));
     unsigned Size     = TD.getTypeSize(TheTy);
     unsigned Align = TD.getABITypeAlignment(TheTy);
-    if (UnionTy == 0 || Size>MaxSize || (Size == MaxSize && Align > MaxAlign)) {
+    if (UnionTy == 0 || Align > MaxAlign 
+        || (MaxAlign == Align && Size > MaxSize)) {
       UnionTy = TheTy;
-      MaxSize = Size;
+      MaxSize = MAX(MaxSize, Size);
       MaxAlign = Align;
     }
   }





More information about the llvm-commits mailing list