diff gen/typinf.c @ 69:2b5a2eaa88be trunk

[svn r73] Identity expression for dynamic array and null was broken.
author lindquist
date Sun, 28 Oct 2007 04:23:38 +0100
parents d4a678905d5e
children 53d3086b5ad3
line wrap: on
line diff
--- a/gen/typinf.c	Sun Oct 28 03:14:29 2007 +0100
+++ b/gen/typinf.c	Sun Oct 28 04:23:38 2007 +0100
@@ -312,9 +312,22 @@
     assert(sinits.back()->getType() == initZ->getOperand(2)->getType());
 
     // void[] init
-    //const llvm::PointerType* initpt = llvm::PointerType::get(llvm::Type::Int8Ty);
-    //sinits.push_back(LLVM_DtoConstantSlice(LLVM_DtoConstSize_t(0), llvm::ConstantPointerNull::get(initpt)));
-    sinits.push_back(initZ->getOperand(3));
+    const llvm::PointerType* initpt = llvm::PointerType::get(llvm::Type::Int8Ty);
+    if (tinfo->isZeroInit() || !sd->init) // 0 initializer, or the same as the base type
+    {
+        sinits.push_back(LLVM_DtoConstSlice(LLVM_DtoConstSize_t(0), llvm::ConstantPointerNull::get(initpt)));
+        //sinits.push_back(initZ->getOperand(3));
+    }
+    else
+    {
+        llvm::Constant* ci = LLVM_DtoConstInitializer(sd->basetype, sd->init);
+        std::string ciname(sd->mangle());
+        ciname.append("__init");
+        llvm::GlobalVariable* civar = new llvm::GlobalVariable(LLVM_DtoType(sd->basetype),true,llvm::GlobalValue::InternalLinkage,ci,ciname,gIR->module);
+        llvm::Constant* cicast = llvm::ConstantExpr::getBitCast(civar, initpt);
+        size_t cisize = gTargetData->getTypeSize(LLVM_DtoType(sd->basetype));
+        sinits.push_back(LLVM_DtoConstSlice(LLVM_DtoConstSize_t(cisize), cicast));
+    }
 
     // create the symbol
     llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits);