[llvm-commits] [llvm-gcc-4.2] r46450 - in /llvm-gcc-4.2/trunk/gcc: llvm-abi.h llvm-internal.h llvm-types.cpp

Evan Cheng evan.cheng at apple.com
Mon Jan 28 01:49:52 PST 2008


Author: evancheng
Date: Mon Jan 28 03:49:51 2008
New Revision: 46450

URL: http://llvm.org/viewvc/llvm-project?rev=46450&view=rev
Log:
1. Only skip over zero sized bit fields which just affects layout, not all zero-sized aggregates.
2. Do not pass zero sized struct and union parameters.

Modified:
    llvm-gcc-4.2/trunk/gcc/llvm-abi.h
    llvm-gcc-4.2/trunk/gcc/llvm-internal.h
    llvm-gcc-4.2/trunk/gcc/llvm-types.cpp

Modified: llvm-gcc-4.2/trunk/gcc/llvm-abi.h
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-abi.h?rev=46450&r1=46449&r2=46450&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-abi.h (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-abi.h Mon Jan 28 03:49:51 2008
@@ -120,6 +120,14 @@
   }
 }
 
+/// isZeroSizedStructOrUnion - Returns true if this is a struct or union 
+/// which is zero bits wide.
+static bool isZeroSizedStructOrUnion(tree type) {
+  if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
+    return false;
+  return int_size_in_bytes(type) == 0;
+}
+
 // LLVM_SHOULD_PASS_AGGREGATE_USING_BYVAL_ATTR - Return true if this aggregate
 // value should be passed by value, i.e. passing its address with the byval
 // attribute bit set. The default is false.
@@ -212,6 +220,8 @@
   /// their fields.
   void HandleArgument(tree type, uint16_t *Attributes = NULL) {
     const Type *Ty = ConvertType(type);
+    // Figure out if this field is zero bits wide, e.g. {} or [0 x int].  Do
+    // not include variable sized fields here.
     std::vector<const Type*> Elts;
     if (isPassedByInvisibleReference(type)) { // variable size -> by-ref.
       C.HandleScalarArgument(PointerType::getUnqual(Ty), type);
@@ -225,8 +235,8 @@
         *Attributes |= ParamAttr::ByVal;
     } else if (LLVM_SHOULD_PASS_AGGREGATE_IN_INTEGER_REGS(type)) {
       PassInIntegerRegisters(type, Ty);
-    } else if (isAggregateOfSizeZero(type)) {
-      // Zero sized aggregate, just drop it!
+    } else if (isZeroSizedStructOrUnion(type)) {
+      // Zero sized struct or union, just drop it!
       ;
     } else if (TREE_CODE(type) == RECORD_TYPE) {
       for (tree Field = TYPE_FIELDS(type); Field; Field = TREE_CHAIN(Field))

Modified: llvm-gcc-4.2/trunk/gcc/llvm-internal.h
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-internal.h?rev=46450&r1=46449&r2=46450&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-internal.h (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-internal.h Mon Jan 28 03:49:51 2008
@@ -118,10 +118,6 @@
 /// element added to match llvm struct type size and gcc struct type size.
 bool isPaddingElement(const Type *T, unsigned N);
 
-/// isAggregateOfSizeZero - Returns true if this is an aggregate with size zero.
-///
-bool isAggregateOfSizeZero(union tree_node*);
-
 /// TypeConverter - Implement the converter from GCC types to LLVM types.
 ///
 class TypeConverter {

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=46450&r1=46449&r2=46450&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-types.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-types.cpp Mon Jan 28 03:49:51 2008
@@ -1612,14 +1612,6 @@
 
 }
 
-/// isAggregateOfSizeZero - Returns true if this is an aggregate with size zero.
-///
-bool isAggregateOfSizeZero(tree type) {
-  if (!isAggregateTreeType(type)) return false;
-  return int_size_in_bytes(type) == 0;
-}
-
-
 /// Mapping from type to type-used-as-base-class and back.
 static DenseMap<tree, tree> BaseTypesMap;
 
@@ -2054,9 +2046,6 @@
       unsigned FieldOffsetInBits = getFieldOffsetInBits(Field);
       tree FieldType = getDeclaredType(Field);
 
-      if (isAggregateOfSizeZero(FieldType))
-        continue;
-
       // If this is a bitfield, we may want to adjust the FieldOffsetInBits to
       // produce safe code.  In particular, bitfields will be loaded/stored as
       // their *declared* type, not the smallest integer type that contains
@@ -2071,6 +2060,11 @@
         // because the FieldOffsetInBits can be lower than it was in the
         // previous iteration.
         CurFieldNo = 0;
+
+        // Skip 'int:0', which just affects layout.
+        unsigned FieldSizeInBits = TREE_INT_CST_LOW(DECL_SIZE(Field));
+        if (FieldSizeInBits == 0)
+          continue;
       }
 
       // Figure out if this field is zero bits wide, e.g. {} or [0 x int].  Do





More information about the llvm-commits mailing list