]> granicus.if.org Git - clang/commitdiff
Fix bug 12574 - Avoid infinite recursion in constructors and destructors when using...
authorTimur Iskhodzhanov <timurrrr@google.com>
Fri, 20 Apr 2012 08:05:00 +0000 (08:05 +0000)
committerTimur Iskhodzhanov <timurrrr@google.com>
Fri, 20 Apr 2012 08:05:00 +0000 (08:05 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@155189 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGClass.cpp
test/CodeGenCXX/microsoft-abi-constructors.cpp [new file with mode: 0644]

index 2aedf95e6a11e213d8e38e4919f0ee8bc14ad384..a01cdc07830b9c29df0a390147bcfa1a1e1d1c5c 100644 (file)
@@ -717,7 +717,8 @@ void CodeGenFunction::EmitConstructorBody(FunctionArgList &Args) {
 
   // Before we go any further, try the complete->base constructor
   // delegation optimization.
-  if (CtorType == Ctor_Complete && IsConstructorDelegationValid(Ctor)) {
+  if (CtorType == Ctor_Complete && IsConstructorDelegationValid(Ctor) &&
+      CGM.getContext().getTargetInfo().getCXXABI() != CXXABI_Microsoft) {
     if (CGDebugInfo *DI = getDebugInfo()) 
       DI->EmitLocation(Builder, Ctor->getLocEnd());
     EmitDelegateCXXConstructorCall(Ctor, Ctor_Base, Args);
@@ -916,7 +917,7 @@ void CodeGenFunction::EmitDestructorBody(FunctionArgList &Args) {
     // Enter the cleanup scopes for virtual bases.
     EnterDtorCleanups(Dtor, Dtor_Complete);
 
-    if (!isTryBody) {
+    if (!isTryBody && CGM.getContext().getTargetInfo().getCXXABI() != CXXABI_Microsoft) {
       EmitCXXDestructorCall(Dtor, Dtor_Base, /*ForVirtualBase=*/false,
                             LoadCXXThis());
       break;
diff --git a/test/CodeGenCXX/microsoft-abi-constructors.cpp b/test/CodeGenCXX/microsoft-abi-constructors.cpp
new file mode 100644 (file)
index 0000000..ac27f13
--- /dev/null
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - -cxx-abi microsoft -triple=i386-pc-win32 | FileCheck %s
+
+class A {
+ public:
+  A() { }
+  ~A() { }
+};
+
+void no_contstructor_destructor_infinite_recursion() {
+  A a;
+
+// Make sure that the constructor doesn't call itself:
+// CHECK: define {{.*}} @"\01??0A@@QAE@XZ"
+// CHECK-NOT: call void @"\01??0A@@QAE@XZ"
+// CHECK: ret
+
+// Make sure that the destructor doesn't call itself:
+// CHECK: define {{.*}} @"\01??1A@@QAE@XZ"
+// CHECK-NOT: call void @"\01??1A@@QAE@XZ"
+// CHECK: ret
+}