[Mesa-dev] [PATCH 1/5] glsl: prevent spurious Valgrind errors when serializing NIR

Nicolai Hähnle nhaehnle at gmail.com
Wed Apr 11 10:56:30 UTC 2018


From: Nicolai Hähnle <nicolai.haehnle at amd.com>

It looks as if the structure fields array is fully initialized below,
but in fact at least gcc in debug builds will not actually overwrite
the unused bits of bit fields.
---
 src/compiler/glsl_types.cpp | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/compiler/glsl_types.cpp b/src/compiler/glsl_types.cpp
index 9d853caf721..9ebf6a433bd 100644
--- a/src/compiler/glsl_types.cpp
+++ b/src/compiler/glsl_types.cpp
@@ -98,22 +98,24 @@ glsl_type::glsl_type(const glsl_struct_field *fields, unsigned num_fields,
    vector_elements(0), matrix_columns(0),
    length(num_fields)
 {
    unsigned int i;
 
    this->mem_ctx = ralloc_context(NULL);
    assert(this->mem_ctx != NULL);
 
    assert(name != NULL);
    this->name = ralloc_strdup(this->mem_ctx, name);
-   this->fields.structure = ralloc_array(this->mem_ctx,
-                                         glsl_struct_field, length);
+   /* Zero-fill to prevent spurious Valgrind errors when serializing NIR
+    * due to uninitialized unused bits in bit fields. */
+   this->fields.structure = rzalloc_array(this->mem_ctx,
+                                          glsl_struct_field, length);
 
    for (i = 0; i < length; i++) {
       this->fields.structure[i] = fields[i];
       this->fields.structure[i].name = ralloc_strdup(this->fields.structure,
                                                      fields[i].name);
    }
 }
 
 glsl_type::glsl_type(const glsl_struct_field *fields, unsigned num_fields,
                      enum glsl_interface_packing packing,
-- 
2.14.1



More information about the mesa-dev mailing list