comparison gen/arrays.cpp @ 507:39dbe48d3fe2

Got rid of improper static array compile time index check. It had caused tango.core.Variant to fail to compile.
author Christian Kamm <kamm incasoftware de>
date Wed, 13 Aug 2008 22:31:46 +0200
parents a34078905d01
children fbb1a366cfbc
comparison
equal deleted inserted replaced
506:a6c105aa00d5 507:39dbe48d3fe2
1033 void DtoArrayBoundsCheck(Loc& loc, DValue* arr, DValue* index, bool isslice) 1033 void DtoArrayBoundsCheck(Loc& loc, DValue* arr, DValue* index, bool isslice)
1034 { 1034 {
1035 Type* arrty = arr->getType()->toBasetype(); 1035 Type* arrty = arr->getType()->toBasetype();
1036 assert((arrty->ty == Tsarray || arrty->ty == Tarray) && "Can only array bounds check for static or dynamic arrays"); 1036 assert((arrty->ty == Tsarray || arrty->ty == Tarray) && "Can only array bounds check for static or dynamic arrays");
1037 1037
1038 // static arrays can get static checks for static indices 1038 // static arrays could get static checks for static indices
1039 1039 // but shouldn't since it might be generic code that's never executed
1040 if(arr->getType()->ty == Tsarray)
1041 {
1042 TypeSArray* tsa = (TypeSArray*)arrty;
1043 size_t tdim = tsa->dim->toInteger();
1044
1045 if(llvm::ConstantInt* cindex = llvm::dyn_cast<llvm::ConstantInt>(index->getRVal()))
1046 if(cindex->uge(tdim + (isslice ? 1 : 0))) {
1047 size_t cindexval = cindex->getValue().getZExtValue();
1048 if(!isslice)
1049 error(loc, "index %u is larger or equal array size %u", cindexval, tdim);
1050 else
1051 error(loc, "slice upper bound %u is larger than array size %u", cindexval, tdim);
1052 return;
1053 }
1054 }
1055 1040
1056 // runtime check 1041 // runtime check
1057 1042
1058 llvm::BasicBlock* oldend = gIR->scopeend(); 1043 llvm::BasicBlock* oldend = gIR->scopeend();
1059 llvm::BasicBlock* failbb = llvm::BasicBlock::Create("arrayboundscheckfail", gIR->topfunc(), oldend); 1044 llvm::BasicBlock* failbb = llvm::BasicBlock::Create("arrayboundscheckfail", gIR->topfunc(), oldend);