From 02cf2ac38430f0be27e69cd505e719bb928169da Mon Sep 17 00:00:00 2001 From: Tomas Lindquist Olsen Date: Thu, 4 Oct 2007 11:39:53 +0200 Subject: [PATCH] [svn r31] * Fixed returning through hidden pointer was unable to report back the return value * Fixed removed some litter instructions sometimes produced by constructor calls --- gen/toir.c | 12 ++++++++---- gen/tollvm.c | 22 +++++++++++++++++++--- test/bug2.d | 4 ++++ 3 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 test/bug2.d diff --git a/gen/toir.c b/gen/toir.c index 043e9d48..d1cd3207 100644 --- a/gen/toir.c +++ b/gen/toir.c @@ -976,7 +976,10 @@ elem* CallExp::toElem(IRState* p) // call the function llvm::CallInst* call = new llvm::CallInst(funcval, llargs.begin(), llargs.end(), varname, p->scopebb()); - e->val = call; + if (retinptr) + e->mem = llargs[0]; + else + e->val = call; // set calling convention if ((fn->funcdecl && (fn->funcdecl->llvmInternal != LLVMintrinsic)) || delegateCall) @@ -1812,13 +1815,14 @@ elem* NewExp::toElem(IRState* p) Expression* ex = (Expression*)arguments->data[i]; Logger::println("arg=%s", ex->toChars()); elem* exe = ex->toElem(p); - assert(exe->getValue()); - ctorargs.push_back(exe->getValue()); + llvm::Value* v = exe->getValue(); + assert(v); + ctorargs.push_back(v); delete exe; } assert(member); assert(member->llvmValue); - new llvm::CallInst(member->llvmValue, ctorargs.begin(), ctorargs.end(), "", p->scopebb()); + e->mem = new llvm::CallInst(member->llvmValue, ctorargs.begin(), ctorargs.end(), "tmp", p->scopebb()); } } else if (newtype->ty == Tstruct) { diff --git a/gen/tollvm.c b/gen/tollvm.c index 2719b30a..0ad9ca0a 100644 --- a/gen/tollvm.c +++ b/gen/tollvm.c @@ -892,6 +892,25 @@ llvm::Value* LLVM_DtoGEPi(llvm::Value* ptr, unsigned i0, unsigned i1, const std: llvm::Function* LLVM_DtoDeclareFunction(FuncDeclaration* fdecl) { + // mangled name + char* mangled_name = (fdecl->llvmInternal == LLVMintrinsic) ? fdecl->llvmInternal1 : fdecl->mangle(); + + // unit test special handling + if (fdecl->isUnitTestDeclaration()) + { + assert(0 && "no unittests yet"); + /*const llvm::FunctionType* fnty = llvm::FunctionType::get(llvm::Type::VoidTy, std::vector(), false); + // make the function + llvm::Function* func = gIR->module->getFunction(mangled_name); + if (func == 0) + func = new llvm::Function(fnty,llvm::GlobalValue::InternalLinkage,mangled_name,gIR->module); + func->setCallingConv(llvm::CallingConv::Fast); + fdecl->llvmValue = func; + return func; + */ + } + + // regular function TypeFunction* f = (TypeFunction*)fdecl->type; assert(f != 0); @@ -915,9 +934,6 @@ llvm::Function* LLVM_DtoDeclareFunction(FuncDeclaration* fdecl) // construct function const llvm::FunctionType* functype = (f->llvmType == 0) ? LLVM_DtoFunctionType(fdecl) : llvm::cast(f->llvmType); - // mangled name - char* mangled_name = (fdecl->llvmInternal == LLVMintrinsic) ? fdecl->llvmInternal1 : fdecl->mangle(); - // make the function llvm::Function* func = gIR->module->getFunction(mangled_name); if (func == 0) { diff --git a/test/bug2.d b/test/bug2.d new file mode 100644 index 00000000..4ff40ec9 --- /dev/null +++ b/test/bug2.d @@ -0,0 +1,4 @@ +module bug2; +struct Vec { Vec barf() { return Vec(); } } +class test { this(Vec whee) { } } +void main() { Vec whee; new test(whee.barf()); }