summaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGExprAgg.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-02-28 18:18:58 +0000
committerChris Lattner <sabre@nondot.org>2009-02-28 18:18:58 +0000
commitca4fc2c2620e184e8b96845a87b19d54f9e045c1 (patch)
tree9315064d9d23aec65eecad060162ffa499099be5 /lib/CodeGen/CGExprAgg.cpp
parent066d2ea7521896efc05cce7aa46fdd3a7ba96c28 (diff)
downloadclang-ca4fc2c2620e184e8b96845a87b19d54f9e045c1.tar.gz
clang-ca4fc2c2620e184e8b96845a87b19d54f9e045c1.tar.bz2
clang-ca4fc2c2620e184e8b96845a87b19d54f9e045c1.tar.xz
after going around in circles a few times, finally cave and emit structure
copies with memcpy instead of memmove. This matches what GCC does and if it causes a problem with a particular libc we can always fix it with a target hook. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65699 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExprAgg.cpp')
-rw-r--r--lib/CodeGen/CGExprAgg.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/CodeGen/CGExprAgg.cpp b/lib/CodeGen/CGExprAgg.cpp
index e2f5c79d99..b0596e2fee 100644
--- a/lib/CodeGen/CGExprAgg.cpp
+++ b/lib/CodeGen/CGExprAgg.cpp
@@ -518,7 +518,16 @@ void CodeGenFunction::EmitAggregateCopy(llvm::Value *DestPtr,
llvm::Value *SrcPtr, QualType Ty) {
assert(!Ty->isAnyComplexType() && "Shouldn't happen for complex");
- // Aggregate assignment turns into llvm.memmove.
+ // Aggregate assignment turns into llvm.memset. This is almost valid per
+ // C99 6.5.16.1p3, which states "If the value being stored in an object is
+ // read from another object that overlaps in anyway the storage of the first
+ // object, then the overlap shall be exact and the two objects shall have
+ // qualified or unqualified versions of a compatible type."
+ //
+ // memset is not defined if the source and destination pointers are exactly
+ // equal, but other compilers do this optimization, and almost every memcpy
+ // implementation handles this case safely. If there is a libc that does not
+ // safely handle this, we can add a target hook.
const llvm::Type *BP = llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
if (DestPtr->getType() != BP)
DestPtr = Builder.CreateBitCast(DestPtr, BP, "tmp");
@@ -531,7 +540,7 @@ void CodeGenFunction::EmitAggregateCopy(llvm::Value *DestPtr,
// FIXME: Handle variable sized types.
const llvm::Type *IntPtr = llvm::IntegerType::get(LLVMPointerWidth);
- Builder.CreateCall4(CGM.getMemMoveFn(),
+ Builder.CreateCall4(CGM.getMemCpyFn(),
DestPtr, SrcPtr,
// TypeInfo.first describes size in bits.
llvm::ConstantInt::get(IntPtr, TypeInfo.first/8),