r241670 - [EH] Fix for clang bug 24005 - no cleanup for array of memcpy-able objects in struct (patch by Denis Zobnin)
Alexey Bataev
a.bataev at hotmail.com
Wed Jul 8 00:31:02 PDT 2015
Author: abataev
Date: Wed Jul 8 02:31:02 2015
New Revision: 241670
URL: http://llvm.org/viewvc/llvm-project?rev=241670&view=rev
Log:
[EH] Fix for clang bug 24005 - no cleanup for array of memcpy-able objects in struct (patch by Denis Zobnin)
The fix is to emit cleanup for arrays of memcpy-able objects in struct if an exception is thrown later during copy-construction.
Differential Revision: http://reviews.llvm.org/D10989
Added:
cfe/trunk/test/CodeGenCXX/eh-aggregate-copy-destroy.cpp (with props)
Modified:
cfe/trunk/lib/CodeGen/CGClass.cpp
Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=241670&r1=241669&r2=241670&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Wed Jul 8 02:31:02 2015
@@ -606,6 +606,11 @@ static void EmitMemberInitializer(CodeGe
// Copy the aggregate.
CGF.EmitAggregateCopy(LHS.getAddress(), Src.getAddress(), FieldType,
LHS.isVolatileQualified());
+ // Ensure that we destroy the objects if an exception is thrown later in
+ // the constructor.
+ QualType::DestructionKind dtorKind = FieldType.isDestructedType();
+ if (CGF.needsEHCleanup(dtorKind))
+ CGF.pushEHDestroy(dtorKind, LHS.getAddress(), FieldType);
return;
}
}
Added: cfe/trunk/test/CodeGenCXX/eh-aggregate-copy-destroy.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/eh-aggregate-copy-destroy.cpp?rev=241670&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/eh-aggregate-copy-destroy.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/eh-aggregate-copy-destroy.cpp Wed Jul 8 02:31:02 2015
@@ -0,0 +1,37 @@
+// Check that in case of copying an array of memcpy-able objects, their
+// destructors will be called if an exception is thrown.
+//
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fexceptions -fcxx-exceptions -O0 -fno-elide-constructors -emit-llvm %s -o - | FileCheck %s
+
+struct ImplicitCopy {
+ int x;
+ ImplicitCopy() { x = 10; }
+ ~ImplicitCopy() { x = 20; }
+};
+
+struct ThrowCopy {
+ ThrowCopy() {}
+ ThrowCopy(const ThrowCopy &) { throw 1; }
+};
+
+struct Container {
+ ImplicitCopy b[2];
+ ThrowCopy c;
+};
+
+int main () {
+ try {
+ Container c1;
+ // CHECK_LABEL: main
+ // CHECK-NOT: call void @_ZN9ThrowCopyC1ERKS_
+ // CHECK: invoke void @_ZN9ThrowCopyC1ERKS_
+ // CHECK: invoke void @_ZN12ImplicitCopyD1Ev
+ Container c2(c1);
+ }
+ catch (...) {
+ return 1;
+ }
+
+ return 0;
+}
+
Propchange: cfe/trunk/test/CodeGenCXX/eh-aggregate-copy-destroy.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cfe/trunk/test/CodeGenCXX/eh-aggregate-copy-destroy.cpp
------------------------------------------------------------------------------
svn:keywords = Author Date Id Rev URL
Propchange: cfe/trunk/test/CodeGenCXX/eh-aggregate-copy-destroy.cpp
------------------------------------------------------------------------------
svn:mime-type = text/plain
More information about the cfe-commits
mailing list