The name-mangled versions of __builtin_new() and __builtin_vec_new() now
don't just call the unmangled versions, but do the appropriate stuff
themselves directly (this was necessary for Massif).  This means that stack
traces for them have one fewer function.  And I was able to gather up several
very similar functions into a macro, reducing the amount of code, which was
nice.  Had to update one regtest's expected output accordingly.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1875 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/coregrind/vg_replace_malloc.c b/coregrind/vg_replace_malloc.c
index 636e851..9c3ca25 100644
--- a/coregrind/vg_replace_malloc.c
+++ b/coregrind/vg_replace_malloc.c
@@ -140,126 +140,50 @@
       while ((n % 4) > 0) n++;      \
    }
 
-/* ALL calls to malloc wind up here. */
-void* malloc ( Int n )
-{
-   void* v;
-
-   MALLOC_TRACE("malloc[simd=%d](%d)", 
-                (UInt)VG_(is_running_on_simd_CPU)(), n );
-   MAYBE_SLOPPIFY(n);
-
-   if (VG_(is_running_on_simd_CPU)()) {
-      v = (void*)VALGRIND_NON_SIMD_CALL1( SK_(malloc), n );
-   } else if (VG_(clo_alignment) != 4) {
-      v = VG_(arena_malloc_aligned)(VG_AR_CLIENT, VG_(clo_alignment), n);
-   } else {
-      v = VG_(arena_malloc)(VG_AR_CLIENT, n);
-   }
-   MALLOC_TRACE(" = %p\n", v );
-   return v;
+/* ALL calls to malloc() and friends wind up here. */
+#define ALLOC(fff, vgfff) \
+void* fff ( Int n ) \
+{ \
+   void* v; \
+ \
+   MALLOC_TRACE(#fff "[simd=%d](%d)",  \
+                (UInt)VG_(is_running_on_simd_CPU)(), n ); \
+   MAYBE_SLOPPIFY(n); \
+ \
+   if (VG_(is_running_on_simd_CPU)()) { \
+      v = (void*)VALGRIND_NON_SIMD_CALL1( vgfff, n ); \
+   } else if (VG_(clo_alignment) != 4) { \
+      v = VG_(arena_malloc_aligned)(VG_AR_CLIENT, VG_(clo_alignment), n); \
+   } else { \
+      v = VG_(arena_malloc)(VG_AR_CLIENT, n); \
+   } \
+   MALLOC_TRACE(" = %p\n", v ); \
+   return v; \
 }
+ALLOC( malloc,            SK_(malloc)            );
+ALLOC( __builtin_new,     SK_(__builtin_new)     );
+ALLOC( _Znwj,             SK_(__builtin_new)     );
+ALLOC( __builtin_vec_new, SK_(__builtin_vec_new) );
+ALLOC( _Znaj,             SK_(__builtin_vec_new) );
 
-void* __builtin_new ( Int n )
-{
-   void* v;
-
-   MALLOC_TRACE("__builtin_new[simd=%d](%d)", 
-                (UInt)VG_(is_running_on_simd_CPU)(), n );
-   MAYBE_SLOPPIFY(n);
-
-   if (VG_(is_running_on_simd_CPU)()) {
-      v = (void*)VALGRIND_NON_SIMD_CALL1( SK_(__builtin_new), n );
-   } else if (VG_(clo_alignment) != 4) {
-      v = VG_(arena_malloc_aligned)(VG_AR_CLIENT, VG_(clo_alignment), n);
-   } else {
-      v = VG_(arena_malloc)(VG_AR_CLIENT, n);
-   }
-   MALLOC_TRACE(" = %p\n", v );
-   return v;
+#define FREE(fff, vgfff) \
+void fff ( void* p ) \
+{ \
+   MALLOC_TRACE(#fff "[simd=%d](%p)\n",  \
+                (UInt)VG_(is_running_on_simd_CPU)(), p ); \
+   if (p == NULL)  \
+      return; \
+   if (VG_(is_running_on_simd_CPU)()) { \
+      (void)VALGRIND_NON_SIMD_CALL1( vgfff, p ); \
+   } else { \
+      VG_(arena_free)(VG_AR_CLIENT, p);       \
+   } \
 }
-
-/* gcc 3.X.X mangles them differently. */
-void* _Znwj ( Int n )
-{
-  return __builtin_new(n);
-}
-
-void* __builtin_vec_new ( Int n )
-{
-   void* v;
-
-   MALLOC_TRACE("__builtin_vec_new[simd=%d](%d)", 
-                (UInt)VG_(is_running_on_simd_CPU)(), n );
-   MAYBE_SLOPPIFY(n);
-
-   if (VG_(is_running_on_simd_CPU)()) {
-      v = (void*)VALGRIND_NON_SIMD_CALL1( SK_(__builtin_vec_new), n );
-   } else if (VG_(clo_alignment) != 4) {
-      v = VG_(arena_malloc_aligned)(VG_AR_CLIENT, VG_(clo_alignment), n);
-   } else {
-      v = VG_(arena_malloc)(VG_AR_CLIENT, n);
-   }
-   MALLOC_TRACE(" = %p\n", v );
-   return v;
-}
-
-/* gcc 3.X.X mangles them differently. */
-void* _Znaj ( Int n )
-{
-  return __builtin_vec_new(n);
-}
-
-void free ( void* p )
-{
-   MALLOC_TRACE("free[simd=%d](%p)\n", 
-                (UInt)VG_(is_running_on_simd_CPU)(), p );
-   if (p == NULL) 
-      return;
-   if (VG_(is_running_on_simd_CPU)()) {
-      (void)VALGRIND_NON_SIMD_CALL1( SK_(free), p );
-   } else {
-      VG_(arena_free)(VG_AR_CLIENT, p);      
-   }
-}
-
-void __builtin_delete ( void* p )
-{
-   MALLOC_TRACE("__builtin_delete[simd=%d](%p)\n", 
-                (UInt)VG_(is_running_on_simd_CPU)(), p );
-   if (p == NULL) 
-      return;
-   if (VG_(is_running_on_simd_CPU)()) {
-      (void)VALGRIND_NON_SIMD_CALL1( SK_(__builtin_delete), p );
-   } else {
-      VG_(arena_free)(VG_AR_CLIENT, p);
-   }
-}
-
-/* gcc 3.X.X mangles them differently. */
-void _ZdlPv ( void* p )
-{
-  __builtin_delete(p);
-}
-
-void __builtin_vec_delete ( void* p )
-{
-   MALLOC_TRACE("__builtin_vec_delete[simd=%d](%p)\n", 
-                (UInt)VG_(is_running_on_simd_CPU)(), p );
-   if (p == NULL) 
-      return;
-   if (VG_(is_running_on_simd_CPU)()) {
-      (void)VALGRIND_NON_SIMD_CALL1( SK_(__builtin_vec_delete), p );
-   } else {
-      VG_(arena_free)(VG_AR_CLIENT, p);
-   }
-}
-
-/* gcc 3.X.X mangles them differently. */
-void _ZdaPv ( void* p )
-{
-  __builtin_vec_delete(p);
-}
+FREE( free,                 SK_(free)                 );
+FREE( __builtin_delete,     SK_(__builtin_delete)     );
+FREE( _ZdlPv,               SK_(__builtin_delete)     );
+FREE( __builtin_vec_delete, SK_(__builtin_vec_delete) );
+FREE( _ZdaPv,               SK_(__builtin_vec_delete) );
 
 void* calloc ( UInt nmemb, UInt size )
 {
diff --git a/memcheck/tests/Makefile.am b/memcheck/tests/Makefile.am
index 7573eda..715ab0c 100644
--- a/memcheck/tests/Makefile.am
+++ b/memcheck/tests/Makefile.am
@@ -3,7 +3,7 @@
 ## - lots more mmap/munmap/mremap/mprotect ones
 ##---------------------------------------------------------------------------
 
-noinst_SCRIPTS = filter_allocs filter_leak_check_size filter_mismatches \
+noinst_SCRIPTS = filter_allocs filter_leak_check_size \
 		 filter_stderr filter_stderr_backtrace filter_pushfpopf \
 		 filter_tronical
 
diff --git a/memcheck/tests/filter_mismatches b/memcheck/tests/filter_mismatches
deleted file mode 100755
index 5c94eda..0000000
--- a/memcheck/tests/filter_mismatches
+++ /dev/null
@@ -1,9 +0,0 @@
-#! /bin/sh
-
-./filter_stderr |
-sed "s/: fooble ([^)]*)/: fooble (...)/" |
-
-sed "/by 0x........: operator .*(.*) (vg_replace_malloc.c:...)/d" |
-sed "/by 0x........: \.\.\./d"
-
-
diff --git a/memcheck/tests/mismatches.stderr.exp b/memcheck/tests/mismatches.stderr.exp
index 388c702..db6a531 100644
--- a/memcheck/tests/mismatches.stderr.exp
+++ b/memcheck/tests/mismatches.stderr.exp
@@ -1,53 +1,65 @@
 Mismatched free() / delete / delete []
-   at 0x........: __builtin_delete (vg_replace_malloc.c:...)
+   at 0x........: operator delete(void*) (vg_replace_malloc.c:...)
    by 0x........: main (mismatches.cpp:6)
    by 0x........: __libc_start_main (...libc...)
+   by 0x........: ...
    Address 0x........ is 0 bytes inside a block of size 10 alloc'd
    at 0x........: malloc (vg_replace_malloc.c:...)
    by 0x........: main (mismatches.cpp:5)
    by 0x........: __libc_start_main (...libc...)
+   by 0x........: ...
 
 Mismatched free() / delete / delete []
-   at 0x........: __builtin_vec_delete (vg_replace_malloc.c:...)
+   at 0x........: operator delete[](void*) (vg_replace_malloc.c:...)
    by 0x........: main (mismatches.cpp:8)
    by 0x........: __libc_start_main (...libc...)
+   by 0x........: ...
    Address 0x........ is 0 bytes inside a block of size 10 alloc'd
    at 0x........: malloc (vg_replace_malloc.c:...)
    by 0x........: main (mismatches.cpp:7)
    by 0x........: __libc_start_main (...libc...)
+   by 0x........: ...
 
 Mismatched free() / delete / delete []
-   at 0x........: __builtin_delete (vg_replace_malloc.c:...)
+   at 0x........: operator delete(void*) (vg_replace_malloc.c:...)
    by 0x........: main (mismatches.cpp:13)
    by 0x........: __libc_start_main (...libc...)
+   by 0x........: ...
    Address 0x........ is 0 bytes inside a block of size 40 alloc'd
-   at 0x........: __builtin_vec_new (vg_replace_malloc.c:...)
+   at 0x........: operator new[](unsigned) (vg_replace_malloc.c:...)
    by 0x........: main (mismatches.cpp:12)
    by 0x........: __libc_start_main (...libc...)
+   by 0x........: ...
 
 Mismatched free() / delete / delete []
    at 0x........: free (vg_replace_malloc.c:...)
    by 0x........: main (mismatches.cpp:15)
    by 0x........: __libc_start_main (...libc...)
+   by 0x........: ...
    Address 0x........ is 0 bytes inside a block of size 40 alloc'd
-   at 0x........: __builtin_vec_new (vg_replace_malloc.c:...)
+   at 0x........: operator new[](unsigned) (vg_replace_malloc.c:...)
    by 0x........: main (mismatches.cpp:14)
    by 0x........: __libc_start_main (...libc...)
+   by 0x........: ...
 
 Mismatched free() / delete / delete []
-   at 0x........: __builtin_vec_delete (vg_replace_malloc.c:...)
+   at 0x........: operator delete[](void*) (vg_replace_malloc.c:...)
    by 0x........: main (mismatches.cpp:20)
    by 0x........: __libc_start_main (...libc...)
+   by 0x........: ...
    Address 0x........ is 0 bytes inside a block of size 4 alloc'd
-   at 0x........: __builtin_new (vg_replace_malloc.c:...)
+   at 0x........: operator new(unsigned) (vg_replace_malloc.c:...)
    by 0x........: main (mismatches.cpp:19)
    by 0x........: __libc_start_main (...libc...)
+   by 0x........: ...
 
 Mismatched free() / delete / delete []
    at 0x........: free (vg_replace_malloc.c:...)
    by 0x........: main (mismatches.cpp:22)
    by 0x........: __libc_start_main (...libc...)
+   by 0x........: ...
    Address 0x........ is 0 bytes inside a block of size 4 alloc'd
-   at 0x........: __builtin_new (vg_replace_malloc.c:...)
+   at 0x........: operator new(unsigned) (vg_replace_malloc.c:...)
    by 0x........: main (mismatches.cpp:21)
    by 0x........: __libc_start_main (...libc...)
+   by 0x........: ...
diff --git a/memcheck/tests/mismatches.vgtest b/memcheck/tests/mismatches.vgtest
index 92e8473..5574afd 100644
--- a/memcheck/tests/mismatches.vgtest
+++ b/memcheck/tests/mismatches.vgtest
@@ -1,3 +1,2 @@
 prog: mismatches
-stderr_filter: filter_mismatches
 vgopts: -q