glsl: prevent spurious Valgrind errors when serializing NIR
authorNicolai Hähnle <nicolai.haehnle@amd.com>
Fri, 23 Mar 2018 14:43:58 +0000 (15:43 +0100)
committerNicolai Hähnle <nicolai.haehnle@amd.com>
Fri, 20 Apr 2018 07:21:23 +0000 (09:21 +0200)
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.

Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
src/compiler/glsl_types.cpp

index 11947c917a2fa05254ec63c6a2bed8a11489c17f..d11c365e1916a87d87c19e4d846546692f4fe16c 100644 (file)
@@ -105,8 +105,10 @@ glsl_type::glsl_type(const glsl_struct_field *fields, unsigned num_fields,
 
    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];