r221739 - [clang/asan] Do not emit memcpy for trivial operator= when -fsanitize-address-field-padding >= 1
Kostya Serebryany
kcc at google.com
Tue Nov 11 15:38:14 PST 2014
Author: kcc
Date: Tue Nov 11 17:38:13 2014
New Revision: 221739
URL: http://llvm.org/viewvc/llvm-project?rev=221739&view=rev
Log:
[clang/asan] Do not emit memcpy for trivial operator= when -fsanitize-address-field-padding >= 1
Summary: If we've added poisoned paddings to a type do not emit memcpy for operator=.
Test Plan: regression tests.
Reviewers: majnemer, rsmith
Reviewed By: rsmith
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D6160
Modified:
cfe/trunk/lib/CodeGen/CGExprCXX.cpp
cfe/trunk/test/CodeGen/sanitize-address-field-padding.cpp
Modified: cfe/trunk/lib/CodeGen/CGExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprCXX.cpp?rev=221739&r1=221738&r2=221739&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprCXX.cpp Tue Nov 11 17:38:13 2014
@@ -318,7 +318,7 @@ CodeGenFunction::EmitCXXOperatorMemberCa
llvm::Value *This = LV.getAddress();
if ((MD->isCopyAssignmentOperator() || MD->isMoveAssignmentOperator()) &&
- MD->isTrivial()) {
+ MD->isTrivial() && !MD->getParent()->mayInsertExtraPadding()) {
llvm::Value *Src = EmitLValue(E->getArg(1)).getAddress();
QualType Ty = E->getType();
EmitAggregateAssign(This, Src, Ty);
Modified: cfe/trunk/test/CodeGen/sanitize-address-field-padding.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/sanitize-address-field-padding.cpp?rev=221739&r1=221738&r2=221739&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/sanitize-address-field-padding.cpp (original)
+++ cfe/trunk/test/CodeGen/sanitize-address-field-padding.cpp Tue Nov 11 17:38:13 2014
@@ -217,3 +217,20 @@ void Create_InheritsFrom_WithVirtualDtor
// WITH_CTOR_ALIASES-NOT: call void @_ZN15WithVirtualDtorD2Ev
// WITH_CTOR_ALIASES: call void @_ZN28InheritsFrom_WithVirtualDtorD2Ev
// WITH_CTOR_ALIASES: ret void
+
+// Make sure we don't emit memcpy for operator= if paddings are inserted.
+struct ClassWithTrivialCopy {
+ ClassWithTrivialCopy();
+ ~ClassWithTrivialCopy();
+ void *a;
+ private:
+ void *c;
+};
+
+void MakeTrivialCopy(ClassWithTrivialCopy *s1, ClassWithTrivialCopy *s2) {
+ *s1 = *s2;
+}
+
+// CHECK-LABEL: define void @_Z15MakeTrivialCopyP20ClassWithTrivialCopyS0_
+// CHECK-NOT: memcpy
+// CHECK: ret void
More information about the cfe-commits
mailing list