]> granicus.if.org Git - clang/commitdiff
The delete argument should not be converted to void*.
authorAbramo Bagnara <abramo.bagnara@gmail.com>
Mon, 9 Jul 2012 21:15:43 +0000 (21:15 +0000)
committerAbramo Bagnara <abramo.bagnara@gmail.com>
Mon, 9 Jul 2012 21:15:43 +0000 (21:15 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159961 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ExprCXX.cpp
lib/CodeGen/CGExprCXX.cpp
lib/Sema/SemaExprCXX.cpp

index a7240e6978ada5a0a3b2c49eea4a27020385098c..73347b2e01d68a7db1422d7732fa51be51037c10 100644 (file)
@@ -127,13 +127,6 @@ SourceLocation CXXNewExpr::getEndLoc() const {
 // CXXDeleteExpr
 QualType CXXDeleteExpr::getDestroyedType() const {
   const Expr *Arg = getArgument();
-  while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Arg)) {
-    if (ICE->getCastKind() != CK_UserDefinedConversion &&
-        ICE->getType()->isVoidPointerType())
-      Arg = ICE->getSubExpr();
-    else
-      break;
-  }
   // The type-to-delete may not be a pointer if it's a dependent type.
   const QualType ArgType = Arg->getType();
 
index d9dd77641034fa253cd7310121a5fcc6f81f0087..79ebe515b0e79dfe40e60cbe854743b12214cb4c 100644 (file)
@@ -1533,18 +1533,7 @@ static void EmitArrayDelete(CodeGenFunction &CGF,
 }
 
 void CodeGenFunction::EmitCXXDeleteExpr(const CXXDeleteExpr *E) {
-  
-  // Get at the argument before we performed the implicit conversion
-  // to void*.
   const Expr *Arg = E->getArgument();
-  while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Arg)) {
-    if (ICE->getCastKind() != CK_UserDefinedConversion &&
-        ICE->getType()->isVoidPointerType())
-      Arg = ICE->getSubExpr();
-    else
-      break;
-  }
-
   llvm::Value *Ptr = EmitScalarExpr(Arg);
 
   // Null check the pointer.
index 9657661a03775d33abcf32cd7d3c62ce1205763b..ec4bf8221f9679bc546e86011a4ae982175ae24a 100644 (file)
@@ -2148,9 +2148,6 @@ Sema::ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal,
     //   delete-expression; it is not necessary to cast away the constness
     //   (5.2.11) of the pointer expression before it is used as the operand
     //   of the delete-expression. ]
-    if (!Context.hasSameType(Ex.get()->getType(), Context.VoidPtrTy))
-      Ex = Owned(ImplicitCastExpr::Create(Context, Context.VoidPtrTy,
-                                          CK_BitCast, Ex.take(), 0, VK_RValue));
 
     if (Pointee->isArrayType() && !ArrayForm) {
       Diag(StartLoc, diag::warn_delete_array_type)
@@ -2228,6 +2225,9 @@ Sema::ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal,
       DeclareGlobalNewDelete();
       DeclContext *TUDecl = Context.getTranslationUnitDecl();
       Expr *Arg = Ex.get();
+      if (!Context.hasSameType(Arg->getType(), Context.VoidPtrTy))
+        Arg = ImplicitCastExpr::Create(Context, Context.VoidPtrTy,
+                                       CK_BitCast, Arg, 0, VK_RValue);
       if (FindAllocationOverload(StartLoc, SourceRange(), DeleteName,
                                  &Arg, 1, TUDecl, /*AllowMissing=*/false,
                                  OperatorDelete))