[cfe-commits] r89173 - in /cfe/trunk/lib/CodeGen: CGCXX.cpp CGCXXExpr.cpp

Eli Friedman eli.friedman at gmail.com
Tue Nov 17 16:50:08 PST 2009


Author: efriedma
Date: Tue Nov 17 18:50:08 2009
New Revision: 89173

URL: http://llvm.org/viewvc/llvm-project?rev=89173&view=rev
Log:
Refactor emitting call to delete operator into common function EmitDeleteCall.


Modified:
    cfe/trunk/lib/CodeGen/CGCXX.cpp
    cfe/trunk/lib/CodeGen/CGCXXExpr.cpp

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Tue Nov 17 18:50:08 2009
@@ -1734,26 +1734,9 @@
   }
     
   // If we have a deleting destructor, emit a call to the delete operator.
-  if (DtorType == Dtor_Deleting) {
-    const FunctionDecl *DeleteFD = DD->getOperatorDelete();
-    assert(DeleteFD && "deleting dtor did not have a delete operator!");
-    
-    const FunctionProtoType *DeleteFTy =
-      DeleteFD->getType()->getAs<FunctionProtoType>();
-
-    CallArgList DeleteArgs;
-
-    QualType ArgTy = DeleteFTy->getArgType(0);
-    llvm::Value *DeletePtr = Builder.CreateBitCast(LoadCXXThis(), 
-                                                   ConvertType(ArgTy));
-    DeleteArgs.push_back(std::make_pair(RValue::get(DeletePtr), ArgTy));
-
-    // Emit the call to delete.
-    EmitCall(CGM.getTypes().getFunctionInfo(DeleteFTy->getResultType(),
-                                            DeleteArgs),
-             CGM.GetAddrOfFunction(DeleteFD),
-             DeleteArgs, DeleteFD);
-  }
+  if (DtorType == Dtor_Deleting)
+    EmitDeleteCall(DD->getOperatorDelete(), LoadCXXThis(),
+                   getContext().getTagDeclType(ClassDecl));
 }
 
 void CodeGenFunction::SynthesizeDefaultDestructor(const CXXDestructorDecl *Dtor,

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXXExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXXExpr.cpp Tue Nov 17 18:50:08 2009
@@ -234,6 +234,33 @@
   return NewPtr;
 }
 
+void CodeGenFunction::EmitDeleteCall(const FunctionDecl *DeleteFD,
+                                     llvm::Value *Ptr,
+                                     QualType DeleteTy) {
+  const FunctionProtoType *DeleteFTy =
+    DeleteFD->getType()->getAs<FunctionProtoType>();
+
+  CallArgList DeleteArgs;
+
+  QualType ArgTy = DeleteFTy->getArgType(0);
+  llvm::Value *DeletePtr = Builder.CreateBitCast(Ptr, ConvertType(ArgTy));
+  DeleteArgs.push_back(std::make_pair(RValue::get(DeletePtr), ArgTy));
+
+  if (DeleteFTy->getNumArgs() == 2) {
+    QualType SizeTy = DeleteFTy->getArgType(1);
+    uint64_t SizeVal = getContext().getTypeSize(DeleteTy) / 8;
+    llvm::Constant *Size = llvm::ConstantInt::get(ConvertType(SizeTy),
+                                                  SizeVal);
+    DeleteArgs.push_back(std::make_pair(RValue::get(Size), SizeTy));
+  }
+
+  // Emit the call to delete.
+  EmitCall(CGM.getTypes().getFunctionInfo(DeleteFTy->getResultType(),
+                                          DeleteArgs),
+           CGM.GetAddrOfFunction(DeleteFD),
+           DeleteArgs, DeleteFD);
+}
+
 void CodeGenFunction::EmitCXXDeleteExpr(const CXXDeleteExpr *E) {
   
   // Get at the argument before we performed the implicit conversion
@@ -313,33 +340,9 @@
     }
   }
 
-  if (ShouldCallDelete) {
-    // Call delete.
-    FunctionDecl *DeleteFD = E->getOperatorDelete();
-    const FunctionProtoType *DeleteFTy =
-      DeleteFD->getType()->getAs<FunctionProtoType>();
-
-    CallArgList DeleteArgs;
-
-    QualType ArgTy = DeleteFTy->getArgType(0);
-    llvm::Value *DeletePtr = Builder.CreateBitCast(Ptr, ConvertType(ArgTy));
-    DeleteArgs.push_back(std::make_pair(RValue::get(DeletePtr), ArgTy));
-
-    if (DeleteFTy->getNumArgs() == 2) {
-      QualType SizeTy = DeleteFTy->getArgType(1);
-      uint64_t SizeVal = getContext().getTypeSize(DeleteTy) / 8;
-      llvm::Constant *Size = llvm::ConstantInt::get(ConvertType(SizeTy),
-                                                    SizeVal);
-      DeleteArgs.push_back(std::make_pair(RValue::get(Size), SizeTy));
-    }
+  if (ShouldCallDelete)
+    EmitDeleteCall(E->getOperatorDelete(), Ptr, DeleteTy);
 
-    // Emit the call to delete.
-    EmitCall(CGM.getTypes().getFunctionInfo(DeleteFTy->getResultType(),
-                                            DeleteArgs),
-             CGM.GetAddrOfFunction(DeleteFD),
-             DeleteArgs, DeleteFD);
-  }
-  
   EmitBlock(DeleteEnd);
 }
 





More information about the cfe-commits mailing list