add support for zero initialized unions, patch by Tim Northover!
authorChris Lattner <sabre@nondot.org>
Mon, 29 Mar 2010 17:36:02 +0000 (17:36 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 29 Mar 2010 17:36:02 +0000 (17:36 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@99818 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/Constants.cpp
test/Feature/unions.ll

index c9c98577eb640950609a1cd373b3bd28b4d99378..bd088802cb52c0deb52e72abeb5dc176e869b185 100644 (file)
@@ -59,6 +59,7 @@ Constant *Constant::getNullValue(const Type *Ty) {
   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 @@ bool ConstantFP::isValueValidForType(const Type *Ty, const APFloat& Val) {
 //                      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;
index 9d6c36bb3c53f186dd95529763e74fe576e74e9d..3cf8c3ce0e979cd96dbd533db60a2bd7737e3f09 100644 (file)
@@ -6,7 +6,9 @@
 
 @union1 = constant union { i32, i8 } { i32 4 }
 @union2 = constant union { i32, i8 } insertvalue(union { i32, i8 } undef, i32 4, 0)
+@union3 = common global %union.anon zeroinitializer, align 8 
 
 define void @"Unions" () {
   ret void
 }
+