diff options
author | Lionel Landwerlin <lionel.g.landwerlin@intel.com> | 2021-11-16 14:25:08 +0200 |
---|---|---|
committer | Eric Engestrom <eric@engestrom.ch> | 2021-12-17 22:30:48 +0000 |
commit | 04ccbf5fead10904836aa504079c4c92bbe16c20 (patch) | |
tree | 837c4ef4b0eb07cd5860df6933023c757c59506c | |
parent | 16e281c4aa72e7af15de775b7c0b526e9fa7a37b (diff) |
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@intel.com>
Cc: mesa-stable
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13952>
(cherry picked from commit 8e568d3f00b31344bc86a7ee1d8e57eb430314a5)
-rw-r--r-- | .pick_status.json | 2 | ||||
-rw-r--r-- | src/compiler/nir/nir_deref.c | 4 |
2 files changed, 5 insertions, 1 deletions
diff --git a/.pick_status.json b/.pick_status.json index f34434a62f1..ace3158746e 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -5341,7 +5341,7 @@ "description": "nir/opt_deref: don't try to cast empty structures", "nominated": true, "nomination_type": 0, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null }, diff --git a/src/compiler/nir/nir_deref.c b/src/compiler/nir/nir_deref.c index 1d559a7f117..42d10cd8783 100644 --- a/src/compiler/nir/nir_deref.c +++ b/src/compiler/nir/nir_deref.c @@ -1052,6 +1052,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; |