]> granicus.if.org Git - clang/commitdiff
Notes on dynamic array cookies in MSVC.
authorJohn McCall <rjmccall@apple.com>
Thu, 27 Jan 2011 02:46:02 +0000 (02:46 +0000)
committerJohn McCall <rjmccall@apple.com>
Thu, 27 Jan 2011 02:46:02 +0000 (02:46 +0000)
My thanks to chapuni for his help in investigating this.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124351 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/MicrosoftCXXABI.cpp

index ea2e55fcb28b870414d7a56795712317bb760054..3a63eba39741f6862bf2bbe87fd1bb5514095452 100644 (file)
@@ -55,6 +55,29 @@ public:
     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.
 };
 
 }