diff --git a/gen/llvmhelpers.cpp b/gen/llvmhelpers.cpp index 46047b6b..d9520934 100644 --- a/gen/llvmhelpers.cpp +++ b/gen/llvmhelpers.cpp @@ -380,7 +380,14 @@ void DtoAssign(Loc& loc, DValue* lhs, DValue* rhs, int op, bool canSkipPostblit) } if (t->ty == Tstruct) { - DtoAggrCopy(lhs->getLVal(), rhs->getRVal()); + llvm::Value* src = rhs->getRVal(); + llvm::Value* dst = lhs->getLVal(); + + // Check whether source and destination values are the same at compile + // time as to not emit an invalid (overlapping) memcpy on trivial + // struct self-assignments like 'A a; a = a;'. + if (src != dst) + DtoAggrCopy(dst, src); } else if (t->ty == Tarray) { // lhs is slice