]> granicus.if.org Git - clang/commitdiff
emit dtors with the right calling convention in -fno-use-cxa-atexit
authorChris Lattner <sabre@nondot.org>
Mon, 26 Apr 2010 20:35:54 +0000 (20:35 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 26 Apr 2010 20:35:54 +0000 (20:35 +0000)
mode.

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

lib/CodeGen/CGDeclCXX.cpp
test/CodeGenCXX/arm.cpp [new file with mode: 0644]

index 40c18ca3c2a3334fb9fbad5b05a6bc40ebdb274f..f6c805fdcaa0357d89a26bcd8c69e7250cb0e1fe 100644 (file)
@@ -219,9 +219,14 @@ void CodeGenFunction::GenerateCXXGlobalDtorFunc(llvm::Function *Fn,
                 SourceLocation());
 
   // Emit the dtors, in reverse order from construction.
-  for (unsigned i = 0, e = DtorsAndObjects.size(); i != e; ++i)
-    Builder.CreateCall(DtorsAndObjects[e - i - 1].first,
-                       DtorsAndObjects[e - i - 1].second);
+  for (unsigned i = 0, e = DtorsAndObjects.size(); i != e; ++i) {
+    llvm::Constant *Callee = DtorsAndObjects[e - i - 1].first;
+    llvm::CallInst *CI = Builder.CreateCall(Callee,
+                                            DtorsAndObjects[e - i - 1].second);
+    // Make sure the call and the callee agree on calling convention.
+    if (llvm::Function *F = dyn_cast<llvm::Function>(Callee))
+      CI->setCallingConv(F->getCallingConv());
+  }
 
   FinishFunction();
 }
diff --git a/test/CodeGenCXX/arm.cpp b/test/CodeGenCXX/arm.cpp
new file mode 100644 (file)
index 0000000..5cca788
--- /dev/null
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 %s -triple=thumbv7-apple-darwin3.0.0-iphoneos -fno-use-cxa-atexit -target-abi apcs-gnu -emit-llvm -o - | FileCheck %s
+
+class foo {
+public:
+    foo();
+    virtual ~foo();
+};
+
+class bar : public foo {
+public:
+       bar();
+};
+
+// The global dtor needs the right calling conv with -fno-use-cxa-atexit
+// rdar://7817590
+bar baz;
+
+// CHECK: @_GLOBAL__D_a()
+// CHECK: call arm_apcscc  void @_ZN3barD1Ev(%class.bar* @baz)
+