diff gen/typinf.c @ 71:53d3086b5ad3 trunk

[svn r75] Fixed the init member in custom enum typeinfo. I don't see any way this could actually need emmision though :/
author lindquist
date Sun, 28 Oct 2007 19:48:57 +0100
parents 2b5a2eaa88be
children d7e764e62462
line wrap: on
line diff
--- a/gen/typinf.c	Sun Oct 28 19:33:50 2007 +0100
+++ b/gen/typinf.c	Sun Oct 28 19:48:57 2007 +0100
@@ -414,9 +414,23 @@
     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->defaultval) // 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
+    {
+        const llvm::Type* memty = LLVM_DtoType(sd->memtype);
+        llvm::Constant* ci = llvm::ConstantInt::get(memty, sd->defaultval, !sd->memtype->isunsigned());
+        std::string ciname(sd->mangle());
+        ciname.append("__init");
+        llvm::GlobalVariable* civar = new llvm::GlobalVariable(memty,true,llvm::GlobalValue::InternalLinkage,ci,ciname,gIR->module);
+        llvm::Constant* cicast = llvm::ConstantExpr::getBitCast(civar, initpt);
+        size_t cisize = gTargetData->getTypeSize(memty);
+        sinits.push_back(LLVM_DtoConstSlice(LLVM_DtoConstSize_t(cisize), cicast));
+    }
 
     // create the symbol
     llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits);