Mesa (main): nir/opt_deref: don't try to cast empty structures

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Dec 1 08:55:40 UTC 2021


Module: Mesa
Branch: main
Commit: 8e568d3f00b31344bc86a7ee1d8e57eb430314a5
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=8e568d3f00b31344bc86a7ee1d8e57eb430314a5

Author: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
Date:   Tue Nov 16 14:25:08 2021 +0200

nir/opt_deref: don't try to cast empty structures

Found while running valgrind :

==3583454== Invalid read of size 4
==3583454==    at 0xF48336: glsl_get_struct_field_offset (nir_types.cpp:84)
==3583454==    by 0xC7CD0D: opt_replace_struct_wrapper_cast (nir_deref.c:1068)
==3583454==    by 0xC7CDD9: opt_deref_cast (nir_deref.c:1087)
==3583454==    by 0xC7DD8E: nir_opt_deref_impl (nir_deref.c:1369)
==3583454==    by 0xC7DF4E: nir_opt_deref (nir_deref.c:1428)
==3583454==    by 0xA63F3C: brw_kernel_from_spirv (brw_kernel.c:325)
==3583454==    by 0xA3BC2C: main (intel_clc.c:481)
==3583454==  Address 0xe4f7e88 is 24 bytes after a block of size 48 in arena "client"

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
Cc: mesa-stable
Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13952>

---

 src/compiler/nir/nir_deref.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/compiler/nir/nir_deref.c b/src/compiler/nir/nir_deref.c
index 39d7b71ca41..cb6847ac9b8 100644
--- a/src/compiler/nir/nir_deref.c
+++ b/src/compiler/nir/nir_deref.c
@@ -1055,6 +1055,10 @@ opt_replace_struct_wrapper_cast(nir_builder *b, nir_deref_instr *cast)
    if (!glsl_type_is_struct(parent->type))
       return false;
 
+   /* Empty struct */
+   if (glsl_get_length(parent->type) < 1)
+      return false;
+
    if (glsl_get_struct_field_offset(parent->type, 0) != 0)
       return false;
 



More information about the mesa-commit mailing list