[LLVMbugs] [Bug 159] [llvm-gcc] Aggregate union initialization causes CFE to crash

bugzilla-daemon at zion.cs.uiuc.edu bugzilla-daemon at zion.cs.uiuc.edu
Thu Nov 27 12:48:28 PST 2003


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

sabre at nondot.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED
            Summary|[llvm-gcc] crash when       |[llvm-gcc] Aggregate union
                   |reducing test case from bug |initialization causes CFE to
                   |158 further                 |crash



------- Additional Comments From sabre at nondot.org  2003-11-27 14:48 -------
Fixed.  Testcase here: test/Regression/CFrontend/2003-11-27-ConstructorCast.c

Patched like so:

$ diff -u llvm-expand.c~ llvm-expand.c
--- llvm-expand.c~      2003-11-27 03:18:44.000000000 -0600
+++ llvm-expand.c       2003-11-27 14:43:10.000000000 -0600
@@ -3357,22 +3357,37 @@
     /* If ElTy != ReqTy and we have a function body available, just go through
      * memory to make sure the correct conversion occurs.
      */
-    llvm_value *Val = llvm_expand_expr(Fn, value, 0);
+    llvm_value *Val;
+    llvm_type *ValTy = llvm_type_get_from_tree(TREE_TYPE(value));
+    llvm_value *DestLoc = 0;
+    if (llvm_type_is_composite(ValTy)) {
+      DestLoc = D2V(make_temporary_alloca(Fn, ValTy));
+    }
+
+    Val = llvm_expand_expr(Fn, value, DestLoc);
 
-    if (Val->Ty == ElTy)
+    if (Val && Val->Ty == ElTy)
       return Val;
-    else if (llvm_type_is_integral(Val->Ty) && llvm_type_is_integral(ElTy))
+    else if (Val && llvm_type_is_integral(Val->Ty) &&
+             llvm_type_is_integral(ElTy))
       return cast_if_type_not_equal(Fn, Val, ElTy);
     else {
-      /* Allocate one of the types: either one works, but pick the larger one */
-      llvm_type *LargerTy =
-        llvm_type_get_size(ElTy) > llvm_type_get_size(Val->Ty) ? ElTy : Val->Ty;
-      llvm_value *All = D2V(make_temporary_alloca(Fn, LargerTy));
+      llvm_value *All = DestLoc;
       llvm_value *Tmp;
 
-      /* Store the computed value to memory */
-      Tmp = cast_if_type_not_equal(Fn, All, llvm_type_get_pointer(Val->Ty));
-      append_inst(Fn, create_store_inst(Val, Tmp, 0));
+      if (!DestLoc) {
+        /* Allocate one of the types: either one works, but pick the larger
+         * one.
+         */
+        llvm_type *LargerTy = ElTy;
+        if (llvm_type_get_size(ElTy) < llvm_type_get_size(Val->Ty))
+          LargerTy = Val->Ty;
+
+        All = D2V(make_temporary_alloca(Fn, LargerTy));
+        /* Store the computed value to memory */
+        Tmp = cast_if_type_not_equal(Fn, All, llvm_type_get_pointer(Val->Ty));
+        append_inst(Fn, create_store_inst(Val, Tmp, 0));
+      }
     
       /* Reload the computed value in the right type */
       Tmp = cast_if_type_not_equal(Fn, All, llvm_type_get_pointer(ElTy));

-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