# HG changeset patch # User lindquist # Date 1191500154 -7200 # Node ID 881158a93592ec7f6a00d20d72888830da97b2f2 # Parent 253a5fc4033a0b7be58a19d088536c76c1be4be5 [svn r34] * Fixed passing a struct literal as function argument diff -r 253a5fc4033a -r 881158a93592 gen/toir.c --- a/gen/toir.c Thu Oct 04 13:45:22 2007 +0200 +++ b/gen/toir.c Thu Oct 04 14:15:54 2007 +0200 @@ -933,6 +933,11 @@ { Expression* argexp = (Expression*)arguments->data[i]; elem* arg = argexp->toElem(p); + if (arg->inplace) { + assert(arg->mem); + llargs[j] = arg->mem; + continue; + } Argument* fnarg = Argument::getNth(tf->parameters, i); @@ -1385,42 +1390,46 @@ LOG_SCOPE; elem* e = new elem; - // if there is no lval, this must be a static initializer for a global. correct? + llvm::Value* sptr = 0; + + // if there is no lval, this is probably a temporary struct literal. correct? if (p->lvals.empty()) { - // TODO - assert(0); + sptr = new llvm::AllocaInst(LLVM_DtoType(type),"tmpstructliteral",p->topallocapoint()); + e->mem = sptr; + e->type = elem::VAR; } - // otherwise write directly in the lvalue + // already has memory else { - llvm::Value* sptr = p->toplval(); - assert(sptr); + sptr = p->toplval(); + } - llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); + assert(sptr); - unsigned n = elements->dim; - for (unsigned i=0; iscopebb()); + llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); + + unsigned n = elements->dim; + for (unsigned i=0; iscopebb()); - Expression* vx = (Expression*)elements->data[i]; - if (vx != 0) { - elem* ve = vx->toElem(p); - llvm::Value* val = ve->getValue(); - Logger::cout() << *val << " | " << *arrptr << '\n'; - if (vx->type->ty == Tstruct) { - TypeStruct* ts = (TypeStruct*)vx->type; - LLVM_DtoStructCopy(ts,arrptr,val); - } - else - new llvm::StoreInst(val, arrptr, p->scopebb()); - delete ve; + Expression* vx = (Expression*)elements->data[i]; + if (vx != 0) { + elem* ve = vx->toElem(p); + llvm::Value* val = ve->getValue(); + Logger::cout() << *val << " | " << *arrptr << '\n'; + if (vx->type->ty == Tstruct) { + TypeStruct* ts = (TypeStruct*)vx->type; + LLVM_DtoStructCopy(ts,arrptr,val); } - else { - assert(0); - } + else + new llvm::StoreInst(val, arrptr, p->scopebb()); + delete ve; + } + else { + assert(0); } } diff -r 253a5fc4033a -r 881158a93592 test/structs6.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/structs6.d Thu Oct 04 14:15:54 2007 +0200 @@ -0,0 +1,15 @@ +module structs6; + +struct S +{ + float f; +} + +void func(S s) +{ +} + +void main() +{ + func(S()); +} diff -r 253a5fc4033a -r 881158a93592 test/unittest1.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/unittest1.d Thu Oct 04 14:15:54 2007 +0200 @@ -0,0 +1,5 @@ +module unittest1; + +unittest +{ +}