Doug Gregor wrote:
Thanks for the diagnosis; I'll get this fixed. It sure would have been
nice if it crashed on Mac OS :)

Here's something to help you on the crash department.
The attached patch modifies llvm::MallocAllocator and gets it to fill the object with garbage before free'ing it.
Try applying it and running the tests.
This is what the MS debug CRT does automatically and it works great for catching this kind of bugs.

Is it reasonable to add something like this patch on llvm and have it enabled for debug builds ?

It does seem odd that we're destroying the TypedefDecl before
destroying the FunctionDecl but I'll look into it.

TranslationUnit destroys the decls at the order of receiving them, should that be reverse order ?

-Argiris
Index: include/llvm/Support/Allocator.h
===================================================================
--- include/llvm/Support/Allocator.h	(revision 58098)
+++ include/llvm/Support/Allocator.h	(working copy)
@@ -16,6 +16,7 @@
 
 #include "llvm/Support/AlignOf.h"
 #include <cstdlib>
+#include <memory>
 
 namespace llvm {
     
@@ -26,12 +27,22 @@
   
   void Reset() {}
 
-  void *Allocate(size_t Size, size_t /*Alignment*/) { return malloc(Size); }
+  void *Allocate(size_t Size, size_t /*Alignment*/) {
+    unsigned bufSize = Size+sizeof(unsigned);
+    unsigned *Buf = reinterpret_cast<unsigned*>(malloc(bufSize));
+    *Buf = bufSize;
+    return Buf+1;
+  }
   
   template <typename T>
-  T *Allocate() { return static_cast<T*>(malloc(sizeof(T))); }
+  T *Allocate() { return static_cast<T*>(Allocate(sizeof(T), 0)); }
   
-  void Deallocate(void *Ptr) { free(Ptr); }
+  void Deallocate(void *Ptr) {
+    unsigned *Buf = reinterpret_cast<unsigned*>(Ptr) - 1;
+    unsigned bufSize = *Buf;
+    memset(Buf, 0xff, bufSize);
+    free(Buf);
+  }
 
   void PrintStats() const {}
 };
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to