Mercurial > projects > ldc
comparison gen/arrays.cpp @ 182:6526cf5bb2be trunk
[svn r198] Fixed: doing a length-changing cast of a full slice segfaulted. eg:
int[] ia = [1,2,3];
byte[] ba = cast(byte[])ia[];
author | lindquist |
---|---|
date | Wed, 07 May 2008 19:54:01 +0200 |
parents | a074a5ff709c |
children | aca17e55b7a5 |
comparison
equal
deleted
inserted
replaced
181:ef4108f34db6 | 182:6526cf5bb2be |
---|---|
405 return ret; | 405 return ret; |
406 } | 406 } |
407 | 407 |
408 void DtoArrayCopySlices(DSliceValue* dst, DSliceValue* src) | 408 void DtoArrayCopySlices(DSliceValue* dst, DSliceValue* src) |
409 { | 409 { |
410 Logger::println("ArrayCopySlices"); | |
410 const llvm::Type* arrty = getPtrToType(llvm::Type::Int8Ty); | 411 const llvm::Type* arrty = getPtrToType(llvm::Type::Int8Ty); |
411 | 412 |
412 llvm::Value* sz1; | 413 llvm::Value* sz1; |
413 llvm::Value* dstarr = new llvm::BitCastInst(get_slice_ptr(dst,sz1),arrty,"tmp",gIR->scopebb()); | 414 llvm::Value* dstarr = new llvm::BitCastInst(get_slice_ptr(dst,sz1),arrty,"tmp",gIR->scopebb()); |
414 | 415 |
426 new llvm::CallInst(fn, llargs.begin(), llargs.end(), "", gIR->scopebb()); | 427 new llvm::CallInst(fn, llargs.begin(), llargs.end(), "", gIR->scopebb()); |
427 } | 428 } |
428 | 429 |
429 void DtoArrayCopyToSlice(DSliceValue* dst, DValue* src) | 430 void DtoArrayCopyToSlice(DSliceValue* dst, DValue* src) |
430 { | 431 { |
432 Logger::println("ArrayCopyToSlice"); | |
431 const llvm::Type* arrty = getPtrToType(llvm::Type::Int8Ty); | 433 const llvm::Type* arrty = getPtrToType(llvm::Type::Int8Ty); |
432 | 434 |
433 llvm::Value* sz1; | 435 llvm::Value* sz1; |
434 llvm::Value* dstarr = new llvm::BitCastInst(get_slice_ptr(dst,sz1),arrty,"tmp",gIR->scopebb()); | 436 llvm::Value* dstarr = new llvm::BitCastInst(get_slice_ptr(dst,sz1),arrty,"tmp",gIR->scopebb()); |
435 llvm::Value* srcarr = new llvm::BitCastInst(DtoArrayPtr(src),arrty,"tmp",gIR->scopebb()); | 437 llvm::Value* srcarr = new llvm::BitCastInst(DtoArrayPtr(src),arrty,"tmp",gIR->scopebb()); |
784 } | 786 } |
785 | 787 |
786 ////////////////////////////////////////////////////////////////////////////////////////// | 788 ////////////////////////////////////////////////////////////////////////////////////////// |
787 llvm::Value* DtoArrayCastLength(llvm::Value* len, const llvm::Type* elemty, const llvm::Type* newelemty) | 789 llvm::Value* DtoArrayCastLength(llvm::Value* len, const llvm::Type* elemty, const llvm::Type* newelemty) |
788 { | 790 { |
791 Logger::println("DtoArrayCastLength"); | |
792 LOG_SCOPE; | |
793 | |
794 assert(len); | |
795 assert(elemty); | |
796 assert(newelemty); | |
797 | |
789 size_t esz = getABITypeSize(elemty); | 798 size_t esz = getABITypeSize(elemty); |
790 size_t nsz = getABITypeSize(newelemty); | 799 size_t nsz = getABITypeSize(newelemty); |
791 if (esz == nsz) | 800 if (esz == nsz) |
792 return len; | 801 return len; |
793 | 802 |
907 } | 916 } |
908 | 917 |
909 ////////////////////////////////////////////////////////////////////////////////////////// | 918 ////////////////////////////////////////////////////////////////////////////////////////// |
910 DValue* DtoCastArray(DValue* u, Type* to) | 919 DValue* DtoCastArray(DValue* u, Type* to) |
911 { | 920 { |
921 Logger::println("DtoCastArray"); | |
922 LOG_SCOPE; | |
923 | |
912 const llvm::Type* tolltype = DtoType(to); | 924 const llvm::Type* tolltype = DtoType(to); |
913 | 925 |
914 Type* totype = DtoDType(to); | 926 Type* totype = DtoDType(to); |
915 Type* fromtype = DtoDType(u->getType()); | 927 Type* fromtype = DtoDType(u->getType()); |
916 assert(fromtype->ty == Tarray || fromtype->ty == Tsarray); | 928 assert(fromtype->ty == Tarray || fromtype->ty == Tsarray); |
941 if (DSliceValue* usl = u->isSlice()) { | 953 if (DSliceValue* usl = u->isSlice()) { |
942 Logger::println("from slice"); | 954 Logger::println("from slice"); |
943 Logger::cout() << "from: " << *usl->ptr << " to: " << *ptrty << '\n'; | 955 Logger::cout() << "from: " << *usl->ptr << " to: " << *ptrty << '\n'; |
944 rval = new llvm::BitCastInst(usl->ptr, ptrty, "tmp", gIR->scopebb()); | 956 rval = new llvm::BitCastInst(usl->ptr, ptrty, "tmp", gIR->scopebb()); |
945 if (fromtype->next->size() == totype->next->size()) | 957 if (fromtype->next->size() == totype->next->size()) |
946 rval2 = usl->len; | 958 rval2 = DtoArrayLen(usl); |
947 else | 959 else |
948 rval2 = DtoArrayCastLength(usl->len, ety, ptrty->getContainedType(0)); | 960 rval2 = DtoArrayCastLength(DtoArrayLen(usl), ety, ptrty->getContainedType(0)); |
949 } | 961 } |
950 else { | 962 else { |
951 llvm::Value* uval = u->getRVal(); | 963 llvm::Value* uval = u->getRVal(); |
952 if (fromtype->ty == Tsarray) { | 964 if (fromtype->ty == Tsarray) { |
953 Logger::cout() << "uvalTy = " << *uval->getType() << '\n'; | 965 Logger::cout() << "uvalTy = " << *uval->getType() << '\n'; |