[llvm-commits] CVS: llvm-gcc/gcc/llvm-expand.c

Chris Lattner lattner at cs.uiuc.edu
Thu Jan 13 09:16:51 PST 2005



Changes in directory llvm-gcc/gcc:

llvm-expand.c updated: 1.76 -> 1.77
---
Log message:

Implement the case where a CONSTRUCTOR index is null, indicating it should
be emitted to the next element.  This fixes "return 0;" in objc.


---
Diffs of the changes:  (+14 -13)

Index: llvm-gcc/gcc/llvm-expand.c
diff -u llvm-gcc/gcc/llvm-expand.c:1.76 llvm-gcc/gcc/llvm-expand.c:1.77
--- llvm-gcc/gcc/llvm-expand.c:1.76	Sun Jan  2 22:34:28 2005
+++ llvm-gcc/gcc/llvm-expand.c	Thu Jan 13 11:16:36 2005
@@ -3968,6 +3968,7 @@
     tree domain = TYPE_DOMAIN (type);
     llvm_type *FieldType = GET_ARRAY_TYPE_ELEMENT(Ty);
     HOST_WIDE_INT minelt = 0;
+    int NextFieldToFill = 0;
 
     /* Vectors are like arrays, but the domain is stored via an array
        type indirectly.  */
@@ -4002,22 +4003,23 @@
        */
       tree index = TREE_PURPOSE (elt);
 
-      /* TODO: Handle the case where it is NULL_TREE! */
-      assert (index != NULL_TREE);
-
       if (index && TREE_CODE(index) == RANGE_EXPR) {
         LLVM_TODO_TREE(exp);
       } else {
         int FieldOffset;
-        if (minelt)
+        if (minelt && index)
           index = convert (ssizetype,
                            fold (build (MINUS_EXPR, index,
                                         TYPE_MIN_VALUE (domain))));
 
         /* TODO: There is probably a better way to do this. */
-        assert(TREE_CODE(index) == INTEGER_CST);
-        assert ((TREE_INT_CST_HIGH(index)) == 0);
-        FieldOffset = TREE_INT_CST_LOW(index);
+        if (index) {
+          assert(TREE_CODE(index) == INTEGER_CST);
+          assert ((TREE_INT_CST_HIGH(index)) == 0);
+          FieldOffset = TREE_INT_CST_LOW(index);
+        } else {
+          FieldOffset = NextFieldToFill;
+        }
 
         /*
          * If the size of the array is too small (i.e. we didn't know the size,
@@ -4028,23 +4030,21 @@
           /*
            * Increase the size of the LLVM array type.
            */
-          (Ty->NumElements) = (FieldOffset + 1);
+          Ty->NumElements = FieldOffset + 1;
 
           /*
            * Create a new result array and copy the elements to it.
            */
-          Result=(llvm_value**) xrealloc(Result,
-                                         Ty->NumElements * sizeof(llvm_value*));
+          Result = (llvm_value**)xrealloc(Result,
+                                         (2*Ty->NumElements) * sizeof(llvm_value*));
 
-          assert (Result);
+          assert(Result && "realloc failed?");
 
           /*
            * Zero out all elements not part of the original array.
            */
           for (i=Size; i < Ty->NumElements; i++)
-          {
             Result[i] = 0;
-          }
 
           /*
            * Record the new size and proceed.
@@ -4056,6 +4056,7 @@
           llvm_expand_constructor_element(Fn, target, value, FieldType,
                                llvm_constant_new_integral(IntPtrTy, FieldOffset),
                                           isVolatile);
+        NextFieldToFill = FieldOffset+1;
       }
     }
 






More information about the llvm-commits mailing list