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

Author: Corentin Noël <corentin.n...@collabora.com>
Date:   Fri Nov 10 18:35:22 2023 +0100

glsl: Make sure that the variable is a ir_variable before unreferencing it

While it technically was already only using an ir_instruction field, better make
sure that it is effectively an ir_variable using the dedicated method instead of
relying on an undefined behavior.

Reviewed-by: Erik Faye-Lund <erik.faye-l...@collabora.com>

Signed-off-by: Corentin Noël <corentin.n...@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26144>

---

 src/compiler/glsl/opt_dead_builtin_variables.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/compiler/glsl/opt_dead_builtin_variables.cpp 
b/src/compiler/glsl/opt_dead_builtin_variables.cpp
index 48452fc312e..c03c243ac5d 100644
--- a/src/compiler/glsl/opt_dead_builtin_variables.cpp
+++ b/src/compiler/glsl/opt_dead_builtin_variables.cpp
@@ -36,8 +36,9 @@ void
 optimize_dead_builtin_variables(exec_list *instructions,
                                 enum ir_variable_mode other)
 {
-   foreach_in_list_safe(ir_variable, var, instructions) {
-      if (var->ir_type != ir_type_variable || var->data.used)
+   foreach_in_list_safe(ir_instruction, inst, instructions) {
+      ir_variable *var = inst->as_variable();
+      if (!var || var->data.used)
          continue;
 
       if (var->data.mode != ir_var_uniform

Reply via email to