]> granicus.if.org Git - clang/commitdiff
Don't produce an alias between destructors with different calling conventions.
authorRafael Espindola <rafael.espindola@gmail.com>
Wed, 5 Mar 2014 21:04:41 +0000 (21:04 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Wed, 5 Mar 2014 21:04:41 +0000 (21:04 +0000)
Fixes pr19007.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203007 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGCXX.cpp
test/CodeGenCXX/ctor-dtor-alias.cpp

index ed8c80500b83f75831c9e2a5d6ce4f23c070e93a..9904906571230401ac39a85c4e888edda83426ec 100644 (file)
@@ -92,7 +92,13 @@ bool CodeGenModule::TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D) {
   if (!ClassLayout.getBaseClassOffset(UniqueBase).isZero())
     return true;
 
+  // Give up if the calling conventions don't match. We could update the call,
+  // but it is probably not worth it.
   const CXXDestructorDecl *BaseD = UniqueBase->getDestructor();
+  if (BaseD->getType()->getAs<FunctionType>()->getCallConv() !=
+      D->getType()->getAs<FunctionType>()->getCallConv())
+    return true;
+
   return TryEmitDefinitionAsAlias(GlobalDecl(D, Dtor_Base),
                                   GlobalDecl(BaseD, Dtor_Base),
                                   false);
index c30facf3ab525b4d8ee922575b753827699593b8..d869a2bfd5d9c9c18e232fa4da1bc1b3c2152fe3 100644 (file)
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 %s -triple x86_64-linux -emit-llvm -o - -mconstructor-aliases -O1 -disable-llvm-optzns | FileCheck %s
-// RUN: %clang_cc1 %s -triple x86_64-linux -emit-llvm -o - -mconstructor-aliases | FileCheck --check-prefix=NOOPT %s
+// RUN: %clang_cc1 %s -triple i686-linux -emit-llvm -o - -mconstructor-aliases -O1 -disable-llvm-optzns | FileCheck %s
+// RUN: %clang_cc1 %s -triple i686-linux -emit-llvm -o - -mconstructor-aliases | FileCheck --check-prefix=NOOPT %s
 
 // RUN: %clang_cc1 -triple x86_64--netbsd -emit-llvm \
 // RUN: -mconstructor-aliases -O2 %s -o - | FileCheck --check-prefix=CHECK-RAUW %s
@@ -133,6 +133,22 @@ namespace test8 {
   zed foo;
 }
 
+namespace test9 {
+struct foo {
+  __attribute__((stdcall)) ~foo() {
+  }
+};
+
+struct bar : public foo {};
+
+void zed() {
+  // Test that we produce a call to bar's destructor. We used to call foo's, but
+  // it has a different calling conversion.
+  // CHECK-DAG: call void @_ZN5test93barD2Ev
+  bar ptr;
+}
+}
+
 // CHECK-RAUW: @_ZTV1C = linkonce_odr unnamed_addr constant [4 x i8*] [{{[^@]*}}@_ZTI1C {{[^@]*}}@_ZN1CD2Ev {{[^@]*}}@_ZN1CD0Ev {{[^@]*}}]
 // r194296 replaced C::~C with B::~B without emitting the later.