From 848ecbed0dd382dfb2e9b032233d7511acbe1ff3 Mon Sep 17 00:00:00 2001 From: Tomas Lindquist Olsen Date: Sun, 28 Oct 2007 19:48:57 +0100 Subject: [PATCH] [svn r75] Fixed the init member in custom enum typeinfo. I don't see any way this could actually need emmision though :/ --- gen/typinf.c | 20 +++++++++++++++++--- test/typeinfo5.d | 1 + 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/gen/typinf.c b/gen/typinf.c index 905ccd8e..2a2d950f 100644 --- a/gen/typinf.c +++ b/gen/typinf.c @@ -414,9 +414,23 @@ void TypeInfoEnumDeclaration::toDt(dt_t **pdt) 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); diff --git a/test/typeinfo5.d b/test/typeinfo5.d index ba57804f..a9a37284 100644 --- a/test/typeinfo5.d +++ b/test/typeinfo5.d @@ -7,4 +7,5 @@ void main() } auto ti = typeid(E); assert(ti.next() is typeid(uint)); + assert(ti.init is null); }