# HG changeset patch # User lindquist # Date 1210182841 -7200 # Node ID 6526cf5bb2bef451e8c60c9bd29445d5d958e86f # Parent ef4108f34db602555a6d6859397ff0573ac3c693 [svn r198] Fixed: doing a length-changing cast of a full slice segfaulted. eg: int[] ia = [1,2,3]; byte[] ba = cast(byte[])ia[]; diff -r ef4108f34db6 -r 6526cf5bb2be gen/arrays.cpp --- a/gen/arrays.cpp Wed May 07 19:34:41 2008 +0200 +++ b/gen/arrays.cpp Wed May 07 19:54:01 2008 +0200 @@ -407,6 +407,7 @@ void DtoArrayCopySlices(DSliceValue* dst, DSliceValue* src) { + Logger::println("ArrayCopySlices"); const llvm::Type* arrty = getPtrToType(llvm::Type::Int8Ty); llvm::Value* sz1; @@ -428,6 +429,7 @@ void DtoArrayCopyToSlice(DSliceValue* dst, DValue* src) { + Logger::println("ArrayCopyToSlice"); const llvm::Type* arrty = getPtrToType(llvm::Type::Int8Ty); llvm::Value* sz1; @@ -786,6 +788,13 @@ ////////////////////////////////////////////////////////////////////////////////////////// llvm::Value* DtoArrayCastLength(llvm::Value* len, const llvm::Type* elemty, const llvm::Type* newelemty) { + Logger::println("DtoArrayCastLength"); + LOG_SCOPE; + + assert(len); + assert(elemty); + assert(newelemty); + size_t esz = getABITypeSize(elemty); size_t nsz = getABITypeSize(newelemty); if (esz == nsz) @@ -909,6 +918,9 @@ ////////////////////////////////////////////////////////////////////////////////////////// DValue* DtoCastArray(DValue* u, Type* to) { + Logger::println("DtoCastArray"); + LOG_SCOPE; + const llvm::Type* tolltype = DtoType(to); Type* totype = DtoDType(to); @@ -943,9 +955,9 @@ Logger::cout() << "from: " << *usl->ptr << " to: " << *ptrty << '\n'; rval = new llvm::BitCastInst(usl->ptr, ptrty, "tmp", gIR->scopebb()); if (fromtype->next->size() == totype->next->size()) - rval2 = usl->len; + rval2 = DtoArrayLen(usl); else - rval2 = DtoArrayCastLength(usl->len, ety, ptrty->getContainedType(0)); + rval2 = DtoArrayCastLength(DtoArrayLen(usl), ety, ptrty->getContainedType(0)); } else { llvm::Value* uval = u->getRVal();