From 522c06ff7f98850fa7454fdac6893d8665661b9b Mon Sep 17 00:00:00 2001 From: kai Date: Fri, 10 May 2013 12:59:14 +0200 Subject: [PATCH] Do not memcpy with same source and destination. This can happen for sret_args. Drop the assignment in this case. --- gen/statements.cpp | 3 ++- gen/tollvm.cpp | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/gen/statements.cpp b/gen/statements.cpp index 96f7620e..5c5d7165 100644 --- a/gen/statements.cpp +++ b/gen/statements.cpp @@ -82,7 +82,8 @@ void ReturnStatement::toIR(IRState* p) DValue* rvar = new DVarValue(f->type->next, f->decl->ir.irFunc->retArg); DValue* e = exp->toElemDtor(p); // store return value - DtoAssign(loc, rvar, e); + if (rvar->getLVal() != e->getRVal()) + DtoAssign(loc, rvar, e); // call postblit if necessary if (!p->func()->type->isref && !(f->decl->nrvo_can && f->decl->nrvo_var)) diff --git a/gen/tollvm.cpp b/gen/tollvm.cpp index 256a5529..dbee4103 100644 --- a/gen/tollvm.cpp +++ b/gen/tollvm.cpp @@ -545,6 +545,8 @@ void DtoMemSetZero(LLValue* dst, LLValue* nbytes) void DtoMemCpy(LLValue* dst, LLValue* src, LLValue* nbytes, unsigned align) { + assert (src != dst && "src and dst of memcpy must be different"); + LLType* VoidPtrTy = getVoidPtrType(); dst = DtoBitCast(dst, VoidPtrTy);