From a74b51159a1df5aecc2caafd6f65bd4097bfd848 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: (cherry picked from commit 477c0cbbf9ad2ea35e4e1ce2f0b18b2549c2457f) --- .pick_status.json | 2 +- src/compiler/nir/nir_print.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 3b580495ff3..88be2cbe521 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -3604,7 +3604,7 @@ "description": "nir/print: Don't segfault checking has_debug_info", "nominated": true, "nomination_type": 2, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "ce0f30b2301e8a7eb75f9a5fc1fa066bb7ad2569", "notes": null diff --git a/src/compiler/nir/nir_print.c b/src/compiler/nir/nir_print.c index c393bc3186d..1f5763ba301 100644 --- a/src/compiler/nir/nir_print.c +++ b/src/compiler/nir/nir_print.c @@ -145,7 +145,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); @@ -406,7 +406,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); @@ -2048,7 +2048,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;