Blame SOURCES/valgrind-3.14.0-undef_malloc_args.patch

560544
commit 262275da43425ba2b8c240e47063e36b39167996
560544
Author: Mark Wielaard <mark@klomp.org>
560544
Date:   Wed Dec 12 13:55:01 2018 +0100
560544
560544
    Fix memcheck/tests/undef_malloc_args testcase.
560544
560544
diff --git a/coregrind/m_replacemalloc/vg_replace_malloc.c b/coregrind/m_replacemalloc/vg_replace_malloc.c
560544
index 28bdb4a..564829a 100644
560544
--- a/coregrind/m_replacemalloc/vg_replace_malloc.c
560544
+++ b/coregrind/m_replacemalloc/vg_replace_malloc.c
560544
@@ -216,9 +216,19 @@ static void init(void);
560544
    Apart of allowing memcheck to detect an error, the macro
560544
    TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED has no effect and
560544
    has a minimal cost for other tools replacing malloc functions.
560544
+
560544
+   Creating an "artificial" use of _x that works reliably is not entirely
560544
+   straightforward.  Simply comparing it against zero often produces no
560544
+   warning if _x contains at least one nonzero bit is defined, because
560544
+   Memcheck knows that the result of the comparison will be defined (cf
560544
+   expensiveCmpEQorNE).
560544
+
560544
+   Really we want to PCast _x, so as to create a value which is entirely
560544
+   undefined if any bit of _x is undefined.  But there's no portable way to do
560544
+   that.
560544
 */
560544
-#define TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(x) \
560544
-   if ((ULong)x == 0) __asm__ __volatile__( "" ::: "memory" )
560544
+#define TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(_x) \
560544
+   if ((UWord)(_x) == 0) __asm__ __volatile__( "" ::: "memory" )
560544
 
560544
 /*---------------------- malloc ----------------------*/
560544
 
560544
@@ -504,7 +514,7 @@ static void init(void);
560544
    void VG_REPLACE_FUNCTION_EZU(10040,soname,fnname) (void *zone, void *p)  \
560544
    { \
560544
       DO_INIT; \
560544
-      TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED((UWord) zone);	\
560544
+      TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED((UWord)zone ^ (UWord)p); \
560544
       MALLOC_TRACE(#fnname "(%p, %p)\n", zone, p ); \
560544
       if (p == NULL)  \
560544
          return; \
560544
diff --git a/memcheck/tests/undef_malloc_args.c b/memcheck/tests/undef_malloc_args.c
560544
index 99e2799..654d70d 100644
560544
--- a/memcheck/tests/undef_malloc_args.c
560544
+++ b/memcheck/tests/undef_malloc_args.c
560544
@@ -11,29 +11,29 @@ int main (int argc, char*argv[])
560544
 
560544
    {
560544
       size_t size = def_size;
560544
-      (void) VALGRIND_MAKE_MEM_UNDEFINED(&size, 1);
560544
+      (void) VALGRIND_MAKE_MEM_UNDEFINED(&size, sizeof(size));
560544
       p = malloc(size);
560544
    }
560544
 
560544
-   (void) VALGRIND_MAKE_MEM_UNDEFINED(&p, 1);
560544
+   (void) VALGRIND_MAKE_MEM_UNDEFINED(&p, sizeof(p));
560544
    new_p = realloc(p, def_size);
560544
 
560544
-   (void) VALGRIND_MAKE_MEM_UNDEFINED(&new_p, 1);
560544
+   (void) VALGRIND_MAKE_MEM_UNDEFINED(&new_p, sizeof(new_p));
560544
    new_p = realloc(new_p, def_size);
560544
 
560544
-   (void) VALGRIND_MAKE_MEM_UNDEFINED(&new_p, 1);
560544
+   (void) VALGRIND_MAKE_MEM_UNDEFINED(&new_p, sizeof(new_p));
560544
    free (new_p);
560544
 
560544
    {
560544
       size_t nmemb = 1;
560544
-      (void) VALGRIND_MAKE_MEM_UNDEFINED(&nmemb, 1);
560544
+      (void) VALGRIND_MAKE_MEM_UNDEFINED(&nmemb, sizeof(nmemb));
560544
       new_p = calloc(nmemb, def_size);
560544
       free (new_p);
560544
    }
560544
 #if 0
560544
    {
560544
       size_t alignment = 1;
560544
-      (void) VALGRIND_MAKE_MEM_UNDEFINED(&alignment, 1);
560544
+      (void) VALGRIND_MAKE_MEM_UNDEFINED(&alignment, sizeof(alignment));
560544
       new_p = memalign(alignment, def_size);
560544
       free(new_p);
560544
    }
560544
@@ -41,14 +41,14 @@ int main (int argc, char*argv[])
560544
    {
560544
       size_t nmemb = 16;
560544
       size_t size = def_size;
560544
-      (void) VALGRIND_MAKE_MEM_UNDEFINED(&size, 1);
560544
+      (void) VALGRIND_MAKE_MEM_UNDEFINED(&size, sizeof(size));
560544
       new_p = memalign(nmemb, size);
560544
       free(new_p);
560544
    }
560544
 
560544
    {
560544
       size_t size = def_size;
560544
-      (void) VALGRIND_MAKE_MEM_UNDEFINED(&size, 1);
560544
+      (void) VALGRIND_MAKE_MEM_UNDEFINED(&size, sizeof(size));
560544
       new_p = valloc(size);
560544
       free (new_p);
560544
    }