From 1eb35898c63ad4fa1a1449bda61c90a42eed5fea Mon Sep 17 00:00:00 2001 From: Tomas Lindquist Olsen Date: Tue, 13 May 2008 21:40:39 +0200 Subject: [PATCH] [svn r223] Fixed: assert with message could be broken. Fixed: array length exp could fail on slice. --- gen/toir.cpp | 5 +---- gen/tollvm.cpp | 26 ++++++++++++++++++++++---- ir/irfunction.cpp | 1 + ir/irfunction.h | 1 + 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/gen/toir.cpp b/gen/toir.cpp index 62405f0b..291677d4 100644 --- a/gen/toir.cpp +++ b/gen/toir.cpp @@ -2121,10 +2121,7 @@ DValue* ArrayLengthExp::toElem(IRState* p) } else { - llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); - llvm::Value* ptr = DtoGEP(u->getRVal(),zero,zero,"tmp",p->scopebb()); - ptr = new llvm::LoadInst(ptr, "tmp", p->scopebb()); - return new DImValue(type, ptr); + return new DImValue(type, DtoArrayLen(u)); } } diff --git a/gen/tollvm.cpp b/gen/tollvm.cpp index 9707928c..9e302d3c 100644 --- a/gen/tollvm.cpp +++ b/gen/tollvm.cpp @@ -712,16 +712,35 @@ void DtoAssert(Loc* loc, DValue* msg) // func const char* fname = msg ? "_d_assert_msg" : "_d_assert"; + llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, fname); + + c = DtoConstString(loc->filename); // msg param - if (msg) args.push_back(msg->getRVal()); + if (msg) + { + if (DSliceValue* s = msg->isSlice()) + { + llvm::AllocaInst* alloc = gIR->func()->msgArg; + if (!alloc) + { + alloc = new llvm::AllocaInst(c->getType(), ".assertmsg", gIR->topallocapoint()); + DtoSetArray(alloc, DtoArrayLen(s), DtoArrayPtr(s)); + gIR->func()->msgArg = alloc; + } + args.push_back(alloc); + } + else + { + args.push_back(msg->getRVal()); + } + } // file param - c = DtoConstString(loc->filename); llvm::AllocaInst* alloc = gIR->func()->srcfileArg; if (!alloc) { - alloc = new llvm::AllocaInst(c->getType(), "srcfile", gIR->topallocapoint()); + alloc = new llvm::AllocaInst(c->getType(), ".srcfile", gIR->topallocapoint()); gIR->func()->srcfileArg = alloc; } llvm::Value* ptr = DtoGEPi(alloc, 0,0, "tmp"); @@ -735,7 +754,6 @@ void DtoAssert(Loc* loc, DValue* msg) args.push_back(c); // call - llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, fname); llvm::CallInst* call = llvm::CallInst::Create(fn, args.begin(), args.end(), "", gIR->scopebb()); } diff --git a/ir/irfunction.cpp b/ir/irfunction.cpp index 1f94489b..703a49a7 100644 --- a/ir/irfunction.cpp +++ b/ir/irfunction.cpp @@ -26,6 +26,7 @@ IrFunction::IrFunction(FuncDeclaration* fd) dwarfSubProg = NULL; srcfileArg = NULL; + msgArg = NULL; inVolatile = false; } diff --git a/ir/irfunction.h b/ir/irfunction.h index eb5a8797..1e569eb3 100644 --- a/ir/irfunction.h +++ b/ir/irfunction.h @@ -23,6 +23,7 @@ struct IrFunction : IrBase llvm::Constant* dwarfSubProg; llvm::AllocaInst* srcfileArg; + llvm::AllocaInst* msgArg; bool inVolatile;