[cfe-commits] r90409 - in /cfe/trunk/lib/CodeGen: CGCXX.cpp CGVtable.cpp CodeGenFunction.h CodeGenModule.h

Mike Stump mrs at apple.com
Wed Dec 2 19:47:56 PST 2009


Author: mrs
Date: Wed Dec  2 21:47:56 2009
New Revision: 90409

URL: http://llvm.org/viewvc/llvm-project?rev=90409&view=rev
Log:
Add support for thunking dtors.  Oh why does this make my head hurt?

Modified:
    cfe/trunk/lib/CodeGen/CGCXX.cpp
    cfe/trunk/lib/CodeGen/CGVtable.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.h
    cfe/trunk/lib/CodeGen/CodeGenModule.h

Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=90409&r1=90408&r2=90409&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Wed Dec  2 21:47:56 2009
@@ -829,10 +829,10 @@
 }
 
 llvm::Constant *
-CodeGenFunction::GenerateThunk(llvm::Function *Fn, const CXXMethodDecl *MD,
+CodeGenFunction::GenerateThunk(llvm::Function *Fn, const GlobalDecl &GD,
                                bool Extern, 
                                const ThunkAdjustment &ThisAdjustment) {
-  return GenerateCovariantThunk(Fn, MD, Extern, 
+  return GenerateCovariantThunk(Fn, GD, Extern,
                                 CovariantThunkAdjustment(ThisAdjustment,
                                                          ThunkAdjustment()));
 }
@@ -875,8 +875,10 @@
 
 llvm::Constant *
 CodeGenFunction::GenerateCovariantThunk(llvm::Function *Fn,
-                                   const CXXMethodDecl *MD, bool Extern,
+                                   const GlobalDecl &GD, bool Extern,
                                    const CovariantThunkAdjustment &Adjustment) {
+  
+  const CXXMethodDecl *MD = cast<CXXMethodDecl>(GD.getDecl());
   QualType ResultType = MD->getType()->getAs<FunctionType>()->getResultType();
 
   FunctionArgList Args;
@@ -906,7 +908,12 @@
   const llvm::Type *Ty =
     CGM.getTypes().GetFunctionType(CGM.getTypes().getFunctionInfo(MD),
                                    FPT->isVariadic());
-  llvm::Value *Callee = CGM.GetAddrOfFunction(MD, Ty);
+  llvm::Value *Callee;
+  if (const CXXDestructorDecl *Dtor = dyn_cast<CXXDestructorDecl>(MD))
+    Callee = CGM.GetAddrOfCXXDestructor(Dtor, GD.getDtorType());
+  else
+    Callee = CGM.GetAddrOfFunction(MD, Ty);
+
   CallArgList CallArgs;
 
   bool ShouldAdjustReturnPointer = true;
@@ -922,7 +929,7 @@
         CovariantThunkAdjustment(ThunkAdjustment(),
                                  Adjustment.ReturnAdjustment);
       
-      Callee = CGM.BuildCovariantThunk(MD, Extern, ReturnAdjustment);
+      Callee = CGM.BuildCovariantThunk(GD, Extern, ReturnAdjustment);
       
       Callee = Builder.CreateBitCast(Callee, OrigTy);
       ShouldAdjustReturnPointer = false;
@@ -983,11 +990,15 @@
 }
 
 llvm::Constant *
-CodeGenModule::BuildThunk(const CXXMethodDecl *MD, bool Extern,
+CodeGenModule::BuildThunk(const GlobalDecl &GD, bool Extern,
                           const ThunkAdjustment &ThisAdjustment) {
-  
+  const CXXMethodDecl *MD = cast<CXXMethodDecl>(GD.getDecl());
   llvm::SmallString<256> OutName;
-  getMangleContext().mangleThunk(MD, ThisAdjustment, OutName);
+  if (const CXXDestructorDecl *D = dyn_cast<CXXDestructorDecl>(MD)) {
+    getMangleContext().mangleCXXDtorThunk(D, GD.getDtorType(), ThisAdjustment,
+                                          OutName);
+  } else 
+    getMangleContext().mangleThunk(MD, ThisAdjustment, OutName);
   
   llvm::GlobalVariable::LinkageTypes linktype;
   linktype = llvm::GlobalValue::WeakAnyLinkage;
@@ -1001,14 +1012,15 @@
 
   llvm::Function *Fn = llvm::Function::Create(FTy, linktype, OutName.str(),
                                               &getModule());
-  CodeGenFunction(*this).GenerateThunk(Fn, MD, Extern, ThisAdjustment);
+  CodeGenFunction(*this).GenerateThunk(Fn, GD, Extern, ThisAdjustment);
   llvm::Constant *m = llvm::ConstantExpr::getBitCast(Fn, Ptr8Ty);
   return m;
 }
 
 llvm::Constant *
-CodeGenModule::BuildCovariantThunk(const CXXMethodDecl *MD, bool Extern,
+CodeGenModule::BuildCovariantThunk(const GlobalDecl &GD, bool Extern,
                                    const CovariantThunkAdjustment &Adjustment) {
+  const CXXMethodDecl *MD = cast<CXXMethodDecl>(GD.getDecl());
   llvm::SmallString<256> OutName;
   getMangleContext().mangleCovariantThunk(MD, Adjustment, OutName);
   llvm::GlobalVariable::LinkageTypes linktype;

Modified: cfe/trunk/lib/CodeGen/CGVtable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGVtable.cpp?rev=90409&r1=90408&r2=90409&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGVtable.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGVtable.cpp Wed Dec  2 21:47:56 2009
@@ -303,7 +303,7 @@
 
       assert(Index == VtableBuilder::Index[GD] && "Thunk index mismatch!");
              
-      submethods[Index] = CGM.BuildThunk(MD, Extern, Thunk.Adjustment);
+      submethods[Index] = CGM.BuildThunk(GD, Extern, Thunk.Adjustment);
     }
     Thunks.clear();
 

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=90409&r1=90408&r2=90409&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Wed Dec  2 21:47:56 2009
@@ -452,11 +452,11 @@
                                  const ThunkAdjustment &Adjustment);
 
   /// GenerateThunk - Generate a thunk for the given method
-  llvm::Constant *GenerateThunk(llvm::Function *Fn, const CXXMethodDecl *MD,
+  llvm::Constant *GenerateThunk(llvm::Function *Fn, const GlobalDecl &GD,
                                 bool Extern, 
                                 const ThunkAdjustment &ThisAdjustment);
   llvm::Constant *
-  GenerateCovariantThunk(llvm::Function *Fn, const CXXMethodDecl *MD, 
+  GenerateCovariantThunk(llvm::Function *Fn, const GlobalDecl &GD, 
                          bool Extern,
                          const CovariantThunkAdjustment &Adjustment);
 

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=90409&r1=90408&r2=90409&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Wed Dec  2 21:47:56 2009
@@ -234,12 +234,12 @@
   llvm::Constant *GenerateRTTI(QualType Ty);
   
   /// BuildThunk - Build a thunk for the given method.
-  llvm::Constant *BuildThunk(const CXXMethodDecl *MD, bool Extern, 
+  llvm::Constant *BuildThunk(const GlobalDecl &GD, bool Extern, 
                              const ThunkAdjustment &ThisAdjustment);
 
   /// BuildCoVariantThunk - Build a thunk for the given method
   llvm::Constant *
-  BuildCovariantThunk(const CXXMethodDecl *MD, bool Extern,
+  BuildCovariantThunk(const GlobalDecl &GD, bool Extern,
                       const CovariantThunkAdjustment &Adjustment);
 
   typedef std::pair<const CXXRecordDecl *, uint64_t> CtorVtable_t;





More information about the cfe-commits mailing list