From 9083e8b9844daf8bcf3a6b8b4119eedd57147a0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Sat, 5 Jul 2025 03:00:10 -0400 Subject: [PATCH] glsl: fix a possible crash in gl_nir_lower_xfb_varying If the last block is empty, nir_block_last_instr returns NULL, which sets the cursor to NULL, which crashes. I think this can't crash currently because if xfb is present, there is always at least 1 output store in the last block due to lower_io_vars_to_temporaries, but that won't be true after we stop calling it in a later commit. Fixes: fa9cee4247de153 - glsl: implement lower_xfb_varying() as a NIR pass Reviewed-by: Alyssa Rosenzweig Part-of: --- src/compiler/glsl/gl_nir_lower_xfb_varying.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/glsl/gl_nir_lower_xfb_varying.c b/src/compiler/glsl/gl_nir_lower_xfb_varying.c index 5328b15b16e..4469362c5f0 100644 --- a/src/compiler/glsl/gl_nir_lower_xfb_varying.c +++ b/src/compiler/glsl/gl_nir_lower_xfb_varying.c @@ -182,7 +182,7 @@ gl_nir_lower_xfb_varying(nir_shader *shader, const char *old_var_name, b.cursor = nir_before_instr(nir_block_last_instr(block)); copy_to_new_var(&b, deref, new_var_deref, type); } else if (block == nir_impl_last_block(impl)) { - b.cursor = nir_after_instr(nir_block_last_instr(block)); + b.cursor = nir_after_block(block); copy_to_new_var(&b, deref, new_var_deref, type); } } else {