[cfe-commits] r124351 - /cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp

John McCall rjmccall at apple.com
Wed Jan 26 18:46:02 PST 2011


Author: rjmccall
Date: Wed Jan 26 20:46:02 2011
New Revision: 124351

URL: http://llvm.org/viewvc/llvm-project?rev=124351&view=rev
Log:
Notes on dynamic array cookies in MSVC.
My thanks to chapuni for his help in investigating this.


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

Modified: cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp?rev=124351&r1=124350&r2=124351&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp Wed Jan 26 20:46:02 2011
@@ -55,6 +55,29 @@
     EmitThisParam(CGF);
     // TODO: 'for base' flag
   }
+
+  // ==== Notes on array cookies =========
+  //
+  // MSVC seems to only use cookies when the class has a destructor; a
+  // two-argument usual array deallocation function isn't sufficient.
+  //
+  // For example, this code prints "100" and "1":
+  //   struct A {
+  //     char x;
+  //     void *operator new[](size_t sz) {
+  //       printf("%u\n", sz);
+  //       return malloc(sz);
+  //     }
+  //     void operator delete[](void *p, size_t sz) {
+  //       printf("%u\n", sz);
+  //       free(p);
+  //     }
+  //   };
+  //   int main() {
+  //     A *p = new A[100];
+  //     delete[] p;
+  //   }
+  // Whereas it prints "104" and "104" if you give A a destructor.
 };
 
 }





More information about the cfe-commits mailing list