[cfe-commits] r91249 - /cfe/trunk/lib/CodeGen/CGExprCXX.cpp

Anders Carlsson andersca at mac.com
Sun Dec 13 12:10:13 PST 2009


Author: andersca
Date: Sun Dec 13 14:10:12 2009
New Revision: 91249

URL: http://llvm.org/viewvc/llvm-project?rev=91249&view=rev
Log:
Fix regression in my last commit - if a struct has a trivial destructor but no usual deallocation function we don't need a cookie.

Modified:
    cfe/trunk/lib/CodeGen/CGExprCXX.cpp

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprCXX.cpp Sun Dec 13 14:10:12 2009
@@ -27,25 +27,33 @@
   // Check if the class has a trivial destructor.
   if (RD->hasTrivialDestructor()) {
     // Check if the usual deallocation function takes two arguments.
+    const CXXMethodDecl *UsualDeallocationFunction = 0;
+    
     DeclarationName OpName =
       Ctx.DeclarationNames.getCXXOperatorName(OO_Array_Delete);
-    
     DeclContext::lookup_const_iterator Op, OpEnd;
     for (llvm::tie(Op, OpEnd) = RD->lookup(OpName);
          Op != OpEnd; ++Op) {
-      CXXMethodDecl *Delete = cast<CXXMethodDecl>(*Op);
+      const CXXMethodDecl *Delete = cast<CXXMethodDecl>(*Op);
 
       if (Delete->isUsualDeallocationFunction()) {
-        // We don't need a cookie.
-        if (Delete->getNumParams() == 1)
-          return 0;
-        
-        assert(Delete->getNumParams() == 2 && 
-               "Unexpected deallocation function type!");
+        UsualDeallocationFunction = Delete;
         break;
       }
     }
-  }
+    
+    // No usual deallocation function, we don't need a cookie.
+    if (!UsualDeallocationFunction)
+      return 0;
+    
+    // The usual deallocation function doesn't take a size_t argument, so we
+    // don't need a cookie.
+    if (UsualDeallocationFunction->getNumParams() == 1)
+      return 0;
+        
+    assert(UsualDeallocationFunction->getNumParams() == 2 && 
+           "Unexpected deallocation function type!");
+  }  
   
   // Padding is the maximum of sizeof(size_t) and alignof(ElementType)
   return std::max(Ctx.getTypeSize(Ctx.getSizeType()),





More information about the cfe-commits mailing list