glsl/blob: add valgrind checks that written data is defined
authorNicolai Hähnle <nicolai.haehnle@amd.com>
Sat, 24 Jun 2017 08:26:29 +0000 (10:26 +0200)
committerNicolai Hähnle <nicolai.haehnle@amd.com>
Wed, 5 Jul 2017 10:26:10 +0000 (12:26 +0200)
Undefined data will eventually trigger a valgrind error while computing
its CRC32 while writing it into the disk cache, but at that point, it is
basically impossible to track down where the undefined data came from.

With this change, finding the origin of undefined data becomes easy.

v2: remove duplicate VALGRIND_CFLAGS (Emil)

Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
src/compiler/Makefile.am
src/compiler/glsl/blob.c

index d52da91dab8cea536450af232855a6e9402e54d5..4c83365094b712a9efff67d335e34770478f3587 100644 (file)
@@ -36,6 +36,7 @@ AM_CPPFLAGS = \
        -I$(top_srcdir)/src/gallium/include \
        -I$(top_srcdir)/src/gallium/auxiliary \
        -I$(top_srcdir)/src/gtest/include \
+       $(VALGRIND_CFLAGS) \
        $(DEFINES)
 
 AM_CFLAGS = \
index db3625206508bc477e9c5d98d473008c69815418..3c4aed8524d41ed8e1353d3d7839817fc77dd3f2 100644 (file)
 #include "main/macros.h"
 #include "blob.h"
 
+#ifdef HAVE_VALGRIND
+#include <valgrind.h>
+#include <memcheck.h>
+#define VG(x) x
+#else
+#define VG(x)
+#endif
+
 #define BLOB_INITIAL_SIZE 4096
 
 /* Ensure that \blob will be able to fit an additional object of size
@@ -110,6 +118,8 @@ blob_overwrite_bytes(struct blob *blob,
    if (blob->size < offset + to_write)
       return false;
 
+   VG(VALGRIND_CHECK_MEM_IS_DEFINED(bytes, to_write));
+
    memcpy(blob->data + offset, bytes, to_write);
 
    return true;
@@ -121,6 +131,8 @@ blob_write_bytes(struct blob *blob, const void *bytes, size_t to_write)
    if (! grow_to_fit(blob, to_write))
        return false;
 
+   VG(VALGRIND_CHECK_MEM_IS_DEFINED(bytes, to_write));
+
    memcpy(blob->data + blob->size, bytes, to_write);
    blob->size += to_write;