Do not generate invalid memcpy() for struct self assignment.

This catches only the most trivial case, need to investigate
this further.

See GitHub #385.
This commit is contained in:
David Nadlinger
2013-06-07 02:17:39 +02:00
parent 63759239fd
commit 1c883c5071

View File

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