Call _d_arraybounds for bounds checking instead of _d_array_bounds.

It expects file name as a first argument instead of pointer to Module.
This commit is contained in:
Alexey Prokhin 2014-08-21 16:04:47 +04:00
parent 000663e27e
commit 76f3fd02bd
5 changed files with 33 additions and 27 deletions

View file

@ -93,18 +93,15 @@ DValue* DtoAAIndex(Loc& loc, Type* type, DValue* aa, DValue* key, bool lvalue)
gIR->scope() = IRScope(failbb, okbb); gIR->scope() = IRScope(failbb, okbb);
LLValue *moduleInfoSymbol = gIR->func()->decl->getModule()->moduleInfoSymbol();
LLType *moduleInfoType = DtoType(Module::moduleinfo->type);
LLValue* args[] = { LLValue* args[] = {
// module param // file param
DtoBitCast(moduleInfoSymbol, getPtrToType(moduleInfoType)), DtoModuleFileName(gIR->func()->decl->getModule(), loc),
// line param // line param
DtoConstUint(loc.linnum) DtoConstUint(loc.linnum)
}; };
// call // call
llvm::Function* errorfn = LLVM_D_GetRuntimeFunction(loc, gIR->module, "_d_array_bounds"); llvm::Function* errorfn = LLVM_D_GetRuntimeFunction(loc, gIR->module, "_d_arraybounds");
gIR->CreateCallOrInvoke(errorfn, args); gIR->CreateCallOrInvoke(errorfn, args);
// the function does not return // the function does not return

View file

@ -1167,18 +1167,16 @@ void DtoArrayBoundsCheck(Loc& loc, DValue* arr, DValue* index, DValue* lowerBoun
std::vector<LLValue*> args; std::vector<LLValue*> args;
// file param
Module* funcmodule = gIR->func()->decl->getModule(); Module* funcmodule = gIR->func()->decl->getModule();
// module param args.push_back(DtoModuleFileName(funcmodule, loc));
LLValue *moduleInfoSymbol = funcmodule->moduleInfoSymbol();
LLType *moduleInfoType = DtoType(Module::moduleinfo->type);
args.push_back(DtoBitCast(moduleInfoSymbol, getPtrToType(moduleInfoType)));
// line param // line param
LLConstant* c = DtoConstUint(loc.linnum); LLConstant* c = DtoConstUint(loc.linnum);
args.push_back(c); args.push_back(c);
// call // call
llvm::Function* errorfn = LLVM_D_GetRuntimeFunction(loc, gIR->module, "_d_array_bounds"); llvm::Function* errorfn = LLVM_D_GetRuntimeFunction(loc, gIR->module, "_d_arraybounds");
gIR->CreateCallOrInvoke(errorfn, args); gIR->CreateCallOrInvoke(errorfn, args);
// the function does not return // the function does not return

View file

@ -188,18 +188,7 @@ void DtoAssert(Module* M, Loc& loc, DValue* msg)
} }
// file param // file param
args.push_back(DtoModuleFileName(M, loc));
// we might be generating for an imported template function
const char* cur_file = M->srcfile->name->toChars();
if (loc.filename && strcmp(loc.filename, cur_file) != 0)
{
args.push_back(DtoConstString(loc.filename));
}
else
{
IrModule* irmod = getIrModule(M);
args.push_back(DtoLoad(irmod->fileName));
}
// line param // line param
args.push_back(DtoConstUint(loc.linnum)); args.push_back(DtoConstUint(loc.linnum));
@ -214,6 +203,25 @@ void DtoAssert(Module* M, Loc& loc, DValue* msg)
gIR->ir->CreateUnreachable(); gIR->ir->CreateUnreachable();
} }
/****************************************************************************************/
/*////////////////////////////////////////////////////////////////////////////////////////
// Module file name
////////////////////////////////////////////////////////////////////////////////////////*/
LLValue *DtoModuleFileName(Module* M, const Loc& loc)
{
// we might be generating for an imported template function
const char* cur_file = M->srcfile->name->toChars();
if (loc.filename && strcmp(loc.filename, cur_file) != 0)
{
return DtoConstString(loc.filename);
}
else
{
IrModule* irmod = getIrModule(M);
return DtoLoad(irmod->fileName);
}
}
/****************************************************************************************/ /****************************************************************************************/
/*//////////////////////////////////////////////////////////////////////////////////////// /*////////////////////////////////////////////////////////////////////////////////////////

View file

@ -59,6 +59,9 @@ LLValue* DtoGcMalloc(Loc& loc, LLType* lltype, const char* name = "");
// assertion generator // assertion generator
void DtoAssert(Module* M, Loc& loc, DValue* msg); void DtoAssert(Module* M, Loc& loc, DValue* msg);
// returns module file name
LLValue* DtoModuleFileName(Module* M, const Loc& loc);
// return the LabelStatement from the current function with the given identifier or NULL if not found // return the LabelStatement from the current function with the given identifier or NULL if not found
LabelStatement* DtoLabelStatement(Identifier* ident); LabelStatement* DtoLabelStatement(Identifier* ident);

View file

@ -357,25 +357,25 @@ static void LLVM_D_BuildRuntimeModule()
///////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////
// void _d_assert( char[] file, uint line ) // void _d_assert( char[] file, uint line )
// void _d_arraybounds(ModuleInfo* m, uint line)
{ {
llvm::StringRef fname("_d_assert"); llvm::StringRef fname("_d_assert");
llvm::StringRef fname2("_d_arraybounds");
LLType *types[] = { stringTy, intTy }; LLType *types[] = { stringTy, intTy };
LLFunctionType* fty = llvm::FunctionType::get(voidTy, types, false); LLFunctionType* fty = llvm::FunctionType::get(voidTy, types, false);
llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname, M); llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname, M);
llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname2, M);
} }
// void _d_array_bounds(ModuleInfo* m, uint line)
// void _d_switch_error(ModuleInfo* m, uint line) // void _d_switch_error(ModuleInfo* m, uint line)
{ {
llvm::StringRef fname("_d_array_bounds"); llvm::StringRef fname("_d_switch_error");
llvm::StringRef fname2("_d_switch_error");
LLType *types[] = { LLType *types[] = {
moduleInfoPtrTy, moduleInfoPtrTy,
intTy intTy
}; };
LLFunctionType* fty = llvm::FunctionType::get(voidTy, types, false); LLFunctionType* fty = llvm::FunctionType::get(voidTy, types, false);
llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname, M); llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname, M);
llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname2, M);
} }
// void _d_assert_msg(string msg, string file, uint line) // void _d_assert_msg(string msg, string file, uint line)