diff --git a/gen/toir.c b/gen/toir.c index fba927f4..ede1ab56 100644 --- a/gen/toir.c +++ b/gen/toir.c @@ -933,6 +933,11 @@ elem* CallExp::toElem(IRState* p) { 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 @@ elem* StructLiteralExp::toElem(IRState* p) 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); - 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; - } - else { - assert(0); + 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; + } + else { + assert(0); } } diff --git a/test/structs6.d b/test/structs6.d new file mode 100644 index 00000000..52b66a92 --- /dev/null +++ b/test/structs6.d @@ -0,0 +1,15 @@ +module structs6; + +struct S +{ + float f; +} + +void func(S s) +{ +} + +void main() +{ + func(S()); +} diff --git a/test/unittest1.d b/test/unittest1.d new file mode 100644 index 00000000..c6d9462c --- /dev/null +++ b/test/unittest1.d @@ -0,0 +1,5 @@ +module unittest1; + +unittest +{ +}