[LLVMbugs] [Bug 155] [llvm-gcc] crash on union initialization

bugzilla-daemon at zion.cs.uiuc.edu bugzilla-daemon at zion.cs.uiuc.edu
Tue Nov 25 17:14:32 PST 2003


http://llvm.cs.uiuc.edu/bugs/show_bug.cgi?id=155

sabre at nondot.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED



------- Additional Comments From sabre at nondot.org  2003-11-25 19:14 -------
Hrm... the first one was easy:

$ diff -u llvm-expand.c~ llvm-expand.c
--- llvm-expand.c~      2003-11-25 18:19:27.000000000 -0600
+++ llvm-expand.c       2003-11-25 18:25:10.000000000 -0600
@@ -4443,6 +4443,7 @@
     break;
 
   case NOP_EXPR:         /* Cast constant_expr */
+  case NON_LVALUE_EXPR:
   case CONVERT_EXPR:
     Val = D2V(llvm_expand_constant_expr(TREE_OPERAND(exp, 0),
                      llvm_type_get_from_tree(TREE_TYPE(TREE_OPERAND(exp, 0)))));


The second one was more phun:
]$ diff -u llvm-expand.c~ llvm-expand.c
--- llvm-expand.c~      2003-11-25 18:19:27.000000000 -0600
+++ llvm-expand.c       2003-11-25 19:10:27.000000000 -0600
@@ -3167,6 +3167,37 @@
                       ... Expansion of CONSTRUCTOR nodes ...
  *===----------------------------------------------------------------------===*/
 
+static void ExpandConstantInto(llvm_function *Fn, llvm_value *Val,
+                               llvm_type **ElementTypes, llvm_value **Elements,
+                               unsigned *Idx, unsigned Size) {
+  llvm_type *SourceTy = Val->Ty;
+  llvm_value **SrcElements;
+  unsigned i, SourceSize;
+
+  if (llvm_type_is_scalar(SourceTy)) {
+    /* Reexpand the initializer into the current element. */
+    Elements[*Idx] = cast_if_type_not_equal(Fn, Val, ElementTypes[*Idx]);
+    ++*Idx;
+    return;
+  }
+
+  /* If this is an aggregate value, expand each element into the source slot */
+  assert(Val->VTy == ConstantAggregate &&
+         "Constant initializer translation is broken!");
+  SrcElements = ((llvm_constant_aggregate*)Val)->Initializers;
+
+  if (SourceTy->ID == ArrayTyID) {
+    SourceSize = GET_ARRAY_TYPE_SIZE(SourceTy);
+  } else if (SourceTy->ID == StructTyID) {
+    SourceSize = SourceTy->NumElements;
+  } else {
+    assert(0 && "Don't know how to expand this!");
+  }
+
+  for (i = 0; i < SourceSize && *Idx < Size; ++i)
+    ExpandConstantInto(Fn, SrcElements[i], ElementTypes, Elements, Idx, Size);
+}
+
 /* llvm_expand_constructor_element - This function handles the case of
  * initialization of either a contructor constant element or a constructor value
  * element in a function scope.
@@ -3268,30 +3299,8 @@
           ElementTypes[i] = GET_STRUCT_TYPE_ELEMENT(ElTy, i);
       }
 
-      if (llvm_type_is_scalar(SourceTy)) {
-        /* Reexpand the initializer into the zero'th element. */
-        Elements[0] = llvm_expand_constructor_element(Fn, 0, value,
-                                                      ElementTypes[0], 0, 0);
-        i = 1;
-      } else {
-        llvm_value **SrcElements;
-        unsigned SourceSize;
-        assert(Val->VTy == ConstantAggregate &&
-               "Constant initializer translation");
-        SrcElements = ((llvm_constant_aggregate*)Val)->Initializers;
-
-        if (SourceTy->ID == ArrayTyID) {
-          SourceSize = GET_ARRAY_TYPE_SIZE(SourceTy);
-        } else if (SourceTy->ID == StructTyID) {
-          SourceSize = SourceTy->NumElements;
-        } else {
-          assert(0 && "Don't know how to expand this!");
-        }
-
-        for (i = 0; i < SourceSize && i < Size; ++i)
-          Elements[i] = cast_if_type_not_equal(Fn, SrcElements[i],
-                                               ElementTypes[i]);
-      }
+      i = 0;
+      ExpandConstantInto(Fn, Val, ElementTypes, Elements, &i, Size);
 
       /* For the rest of the initializer, expand nulls. */
       for (; i != Size; ++i)

Nevertheless, this is now fixed.

-Chris




------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.



More information about the llvm-bugs mailing list