summaryrefslogtreecommitdiffstats
path: root/contrib/llvm/patches/patch-r262809-clang-r203007-destructor-calling-conv.diff
blob: 5341b8bed845865586a395ee73cbeb14099e1726 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
Pull in r203007 from upstream clang trunk (by Rafael Espindola):

  Don't produce an alias between destructors with different calling conventions.

  Fixes pr19007.

Introduced here: http://svn.freebsd.org/changeset/base/262809

Index: tools/clang/lib/CodeGen/CGCXX.cpp
===================================================================
--- tools/clang/lib/CodeGen/CGCXX.cpp
+++ tools/clang/lib/CodeGen/CGCXX.cpp
@@ -92,7 +92,13 @@ bool CodeGenModule::TryEmitBaseDestructorAsAlias(c
   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: tools/clang/test/CodeGenCXX/ctor-dtor-alias.cpp
===================================================================
--- tools/clang/test/CodeGenCXX/ctor-dtor-alias.cpp
+++ tools/clang/test/CodeGenCXX/ctor-dtor-alias.cpp
@@ -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 -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.
 
OpenPOWER on IntegriCloud