From 477c0cbbf9ad2ea35e4e1ce2f0b18b2549c2457f Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Mon, 21 Jul 2025 11:45:46 -0700 Subject: [PATCH] nir/print: Don't segfault checking has_debug_info For example, divergence analysis can call nir_print_instr with an instruction that doesn't have a block set. When that happens, print_state::shader will be NULL. I stumbled on this while testing !36147. v2: Use nir_instr::has_debug_info instead. Suggested by Konstantin. Reviewed-by: Konstantin Seurer Fixes: ce0f30b2301 ("nir: Add variable debug info to instructions") Fixes: 3aeab4ce405 ("nir/print: Do not print debug information when gathering it") Part-of: --- src/compiler/nir/nir_print.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compiler/nir/nir_print.c b/src/compiler/nir/nir_print.c index 09496bdc89c..db76a9def1d 100644 --- a/src/compiler/nir/nir_print.c +++ b/src/compiler/nir/nir_print.c @@ -148,7 +148,7 @@ print_def(nir_def *def, print_state *state) def->bit_size, sizes[def->num_components], padding, "", state->def_prefix, def->index); - if (state->shader->has_debug_info) { + if (def->parent_instr->has_debug_info) { nir_instr_debug_info *debug_info = nir_instr_get_debug_info(def->parent_instr); if (debug_info->variable_name) fprintf(fp, ".%s", debug_info->variable_name); @@ -409,7 +409,7 @@ print_src(const nir_src *src, print_state *state, nir_alu_type src_type) fprintf(fp, "%s%u", state->def_prefix, src->ssa->index); nir_instr *instr = src->ssa->parent_instr; - if (state->shader->has_debug_info) { + if (instr->has_debug_info) { nir_instr_debug_info *debug_info = nir_instr_get_debug_info(instr); if (debug_info->variable_name) fprintf(fp, ".%s", debug_info->variable_name); @@ -2127,7 +2127,7 @@ print_instr(const nir_instr *instr, print_state *state, unsigned tabs) debug_info->nir_line = (uint32_t)ftell(fp); } - if (state->shader->has_debug_info && !state->gather_debug_info) { + if (instr->has_debug_info && !state->gather_debug_info) { nir_instr_debug_info *debug_info = nir_instr_get_debug_info((nir_instr *)instr); bool changed = state->last_debug_info.spirv_offset != debug_info->spirv_offset;