]> granicus.if.org Git - clang/commitdiff
Fix PR7097, a bad interaction between -fno-use-cxa-atexit and
authorChris Lattner <sabre@nondot.org>
Sat, 19 Jun 2010 05:52:45 +0000 (05:52 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 19 Jun 2010 05:52:45 +0000 (05:52 +0000)
-mconstructor-aliases by using a WeakVH instead of a raw pointer.

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

lib/CodeGen/CGDeclCXX.cpp
lib/CodeGen/CodeGenFunction.h
lib/CodeGen/CodeGenModule.h
test/CodeGenCXX/global-dtor-no-atexit.cpp

index b890e2f0a47e2348a215d85e33969913a2003fce..a59ed0abe6212be55fb8d5b0634ba208812ba495 100644 (file)
@@ -193,11 +193,6 @@ CodeGenModule::EmitCXXGlobalInitFunc() {
   AddGlobalCtor(Fn);
 }
 
-void CodeGenModule::AddCXXDtorEntry(llvm::Constant *DtorFn,
-                                    llvm::Constant *Object) {
-  CXXGlobalDtors.push_back(std::make_pair(DtorFn, Object));
-}
-
 void CodeGenModule::EmitCXXGlobalDtorFunc() {
   if (CXXGlobalDtors.empty())
     return;
@@ -238,14 +233,14 @@ void CodeGenFunction::GenerateCXXGlobalInitFunc(llvm::Function *Fn,
 }
 
 void CodeGenFunction::GenerateCXXGlobalDtorFunc(llvm::Function *Fn,
-                const std::vector<std::pair<llvm::Constant*, llvm::Constant*> >
+                  const std::vector<std::pair<llvm::WeakVH, llvm::Constant*> >
                                                 &DtorsAndObjects) {
   StartFunction(GlobalDecl(), getContext().VoidTy, Fn, FunctionArgList(),
                 SourceLocation());
 
   // Emit the dtors, in reverse order from construction.
   for (unsigned i = 0, e = DtorsAndObjects.size(); i != e; ++i) {
-    llvm::Constant *Callee = DtorsAndObjects[e - i - 1].first;
+    llvm::Value *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.
index f2a35ac5c7f4c0aebbc15b12bf99dd228e360e5f..0fdb60ccbba91d1b07bc283bf0bac95ad1328786 100644 (file)
@@ -1268,7 +1268,7 @@ public:
   /// GenerateCXXGlobalDtorFunc - Generates code for destroying global
   /// variables.
   void GenerateCXXGlobalDtorFunc(llvm::Function *Fn,
-                                 const std::vector<std::pair<llvm::Constant*,
+                                 const std::vector<std::pair<llvm::WeakVH,
                                    llvm::Constant*> > &DtorsAndObjects);
 
   void GenerateCXXGlobalVarDeclInitFunc(llvm::Function *Fn, const VarDecl *D);
index 45931ce0fd3876050fac5c92e1949eb9545f32bc..35383301e0c6740b643fec2c347d11eafb9e2be2 100644 (file)
@@ -142,7 +142,7 @@ class CodeGenModule : public BlockModule {
 
   /// CXXGlobalDtors - Global destructor functions and arguments that need to
   /// run on termination.
-  std::vector<std::pair<llvm::Constant*,llvm::Constant*> > CXXGlobalDtors;
+  std::vector<std::pair<llvm::WeakVH,llvm::Constant*> > CXXGlobalDtors;
 
   /// CFConstantStringClassRef - Cached reference to the class for constant
   /// strings. This value has type int * but is actually an Obj-C class pointer.
@@ -350,7 +350,9 @@ public:
 
   /// AddCXXDtorEntry - Add a destructor and object to add to the C++ global
   /// destructor function.
-  void AddCXXDtorEntry(llvm::Constant *DtorFn, llvm::Constant *Object);
+  void AddCXXDtorEntry(llvm::Constant *DtorFn, llvm::Constant *Object) {
+    CXXGlobalDtors.push_back(std::make_pair(DtorFn, Object));
+  }
 
   /// CreateRuntimeFunction - Create a new runtime function with the specified
   /// type and name.
index 81e219989800aeb13731b6e25fd46009eaf497f5..1e125e3f7d814f5369aa234f052ce51fc15d2c88 100644 (file)
@@ -1,5 +1,8 @@
 // RUN: %clang_cc1 -triple x86_64 %s -fno-use-cxa-atexit -emit-llvm -o - | FileCheck %s
 
+// PR7097
+// RUN: %clang_cc1 -triple x86_64 %s -fno-use-cxa-atexit -mconstructor-aliases -emit-llvm -o - | FileCheck %s
+
 // CHECK: define internal void @_GLOBAL__D_a()
 // CHECK:   call void @_ZN1AD1Ev(%class.A* @b)
 // CHECK:   call void @_ZN1AD1Ev(%class.A* @a)