diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2008-05-26 12:59:39 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2008-05-26 12:59:39 +0000 |
commit | 0c99509927a0c7a48490486b9fec287b63e5c09c (patch) | |
tree | 62ff858a189b69f2f239fbd5eca722a525ebd0b7 /lib/CodeGen/CGExprAgg.cpp | |
parent | 1849128c7d88247d914f05efe4c03907f0932174 (diff) |
Emit memmove, not memcpy, for structure copies; this is unfortunately
required for correctness in cases of copying a struct to itself or to
an overlapping struct (itself for cases like *a = *a, and overlapping
is possible with unions).
Hopefully, this won't end up being a perf issue; LLVM *should* be able
to optimize memmove to memcpy in a lot of cases, and for small copies
the generated code *should* be mostly comparable. (In reality, LLVM
is currently horrible at optimizing memmove, but that's a bug, not a
fundamental issue.)
gcc currently generates wrong code; that's
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32667.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51566 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExprAgg.cpp')
-rw-r--r-- | lib/CodeGen/CGExprAgg.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/CodeGen/CGExprAgg.cpp b/lib/CodeGen/CGExprAgg.cpp index f584980d7f..30ff9ecbaf 100644 --- a/lib/CodeGen/CGExprAgg.cpp +++ b/lib/CodeGen/CGExprAgg.cpp @@ -131,7 +131,7 @@ void AggExprEmitter::EmitAggregateCopy(llvm::Value *DestPtr, llvm::Value *SrcPtr, QualType Ty) { assert(!Ty->isAnyComplexType() && "Shouldn't happen for complex"); - // Aggregate assignment turns into llvm.memcpy. + // Aggregate assignment turns into llvm.memmove. const llvm::Type *BP = llvm::PointerType::getUnqual(llvm::Type::Int8Ty); if (DestPtr->getType() != BP) DestPtr = Builder.CreateBitCast(DestPtr, BP, "tmp"); @@ -144,14 +144,14 @@ void AggExprEmitter::EmitAggregateCopy(llvm::Value *DestPtr, // FIXME: Handle variable sized types. const llvm::Type *IntPtr = llvm::IntegerType::get(CGF.LLVMPointerWidth); - llvm::Value *MemCpyOps[4] = { + llvm::Value *MemMoveOps[4] = { DestPtr, SrcPtr, // TypeInfo.first describes size in bits. llvm::ConstantInt::get(IntPtr, TypeInfo.first/8), llvm::ConstantInt::get(llvm::Type::Int32Ty, TypeInfo.second/8) }; - Builder.CreateCall(CGF.CGM.getMemCpyFn(), MemCpyOps, MemCpyOps+4); + Builder.CreateCall(CGF.CGM.getMemMoveFn(), MemMoveOps, MemMoveOps+4); } |