[llvm-commits] [llvm] r99818 - in /llvm/trunk: lib/VMCore/Constants.cpp test/Feature/unions.ll

Chris Lattner sabre at nondot.org
Mon Mar 29 10:36:02 PDT 2010


Author: lattner
Date: Mon Mar 29 12:36:02 2010
New Revision: 99818

URL: http://llvm.org/viewvc/llvm-project?rev=99818&view=rev
Log:
add support for zero initialized unions, patch by Tim Northover!


Modified:
    llvm/trunk/lib/VMCore/Constants.cpp
    llvm/trunk/test/Feature/unions.ll

Modified: llvm/trunk/lib/VMCore/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Constants.cpp?rev=99818&r1=99817&r2=99818&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Constants.cpp (original)
+++ llvm/trunk/lib/VMCore/Constants.cpp Mon Mar 29 12:36:02 2010
@@ -59,6 +59,7 @@
   case Type::PointerTyID:
     return ConstantPointerNull::get(cast<PointerType>(Ty));
   case Type::StructTyID:
+  case Type::UnionTyID:
   case Type::ArrayTyID:
   case Type::VectorTyID:
     return ConstantAggregateZero::get(Ty);
@@ -944,7 +945,8 @@
 //                      Factory Function Implementation
 
 ConstantAggregateZero* ConstantAggregateZero::get(const Type* Ty) {
-  assert((Ty->isStructTy() || Ty->isArrayTy() || Ty->isVectorTy()) &&
+  assert((Ty->isStructTy() || Ty->isUnionTy()
+         || Ty->isArrayTy() || Ty->isVectorTy()) &&
          "Cannot create an aggregate zero of non-aggregate type!");
   
   LLVMContextImpl *pImpl = Ty->getContext().pImpl;

Modified: llvm/trunk/test/Feature/unions.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Feature/unions.ll?rev=99818&r1=99817&r2=99818&view=diff
==============================================================================
--- llvm/trunk/test/Feature/unions.ll (original)
+++ llvm/trunk/test/Feature/unions.ll Mon Mar 29 12:36:02 2010
@@ -6,7 +6,9 @@
 
 @union1 = constant union { i32, i8 } { i32 4 }
 @union2 = constant union { i32, i8 } insertvalue(union { i32, i8 } undef, i32 4, 0)
+ at union3 = common global %union.anon zeroinitializer, align 8 
 
 define void @"Unions" () {
   ret void
 }
+





More information about the llvm-commits mailing list