From be9aef8908ca9ba315bec0ba8956966f6f34cfae Mon Sep 17 00:00:00 2001 From: Kostya Serebryany Date: Tue, 11 Nov 2014 23:38:13 +0000 Subject: [PATCH] [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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@221739 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGExprCXX.cpp | 2 +- test/CodeGen/sanitize-address-field-padding.cpp | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/CodeGen/CGExprCXX.cpp b/lib/CodeGen/CGExprCXX.cpp index 3d1283f04b..39c77eb8b6 100644 --- a/lib/CodeGen/CGExprCXX.cpp +++ b/lib/CodeGen/CGExprCXX.cpp @@ -318,7 +318,7 @@ CodeGenFunction::EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E, 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); diff --git a/test/CodeGen/sanitize-address-field-padding.cpp b/test/CodeGen/sanitize-address-field-padding.cpp index 9066a5efb0..0683089585 100644 --- a/test/CodeGen/sanitize-address-field-padding.cpp +++ b/test/CodeGen/sanitize-address-field-padding.cpp @@ -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 -- 2.40.0