[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
This commit is contained in:
Tomas Lindquist Olsen
2007-10-04 11:39:53 +02:00
parent c357c96471
commit 02cf2ac384
3 changed files with 31 additions and 7 deletions

View File

@@ -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) {

View File

@@ -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<const llvm::Type*>(), 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<llvm::FunctionType>(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) {

4
test/bug2.d Normal file
View File

@@ -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()); }