From 657baf19ca8a48a926bd3bc148b6ad1b17e53199 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Thu, 28 Apr 2011 22:57:55 +0000 Subject: Cut down unnecessary zero'ing when value-initializing arrays of C++ objects. -C++ objects with user-declared constructor don't need zero'ing. -We can zero-initialize arrays of C++ objects in "bulk" now, in which case don't zero-initialize each object again. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130453 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGExprAgg.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'lib/CodeGen/CGExprAgg.cpp') diff --git a/lib/CodeGen/CGExprAgg.cpp b/lib/CodeGen/CGExprAgg.cpp index 8747562ce5..87d3819e48 100644 --- a/lib/CodeGen/CGExprAgg.cpp +++ b/lib/CodeGen/CGExprAgg.cpp @@ -811,7 +811,16 @@ static void CheckAggExprForMemSetUse(AggValueSlot &Slot, const Expr *E, // If the slot is already known to be zeroed, nothing to do. Don't mess with // volatile stores. if (Slot.isZeroed() || Slot.isVolatile() || Slot.getAddr() == 0) return; - + + // C++ objects with a user-declared constructor don't need zero'ing. + if (CGF.getContext().getLangOptions().CPlusPlus) + if (const RecordType *RT = CGF.getContext() + .getBaseElementType(E->getType())->getAs()) { + const CXXRecordDecl *RD = cast(RT->getDecl()); + if (RD->hasUserDeclaredConstructor()) + return; + } + // If the type is 16-bytes or smaller, prefer individual stores over memset. std::pair TypeInfo = CGF.getContext().getTypeInfoInChars(E->getType()); -- cgit v1.2.3