From 0aa840000d02f5e30a71be1c34dc12f8d73e13e7 Mon Sep 17 00:00:00 2001 From: Jesse Archer Date: Tue, 27 May 2025 11:31:49 -0700 Subject: [PATCH] Ignore cleared debug instructions Debug instructions can be cleared during debug or non-semantic stripping passes. Check for this before attempting to access their operands. --- source/opt/module.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/source/opt/module.cpp b/source/opt/module.cpp index a9710c6a3c..e1e34ab79b 100644 --- a/source/opt/module.cpp +++ b/source/opt/module.cpp @@ -213,8 +213,12 @@ void Module::ToBinary(std::vector* binary, bool skip_nop) const { ->GetExtInstImportId_OpenCL100DebugInfo()) { // Emit DebugScope |scope| to |binary|. auto dbg_inst = ext_inst_debuginfo_.begin(); - scope.ToBinary(dbg_inst->type_id(), context()->TakeNextId(), - dbg_inst->GetSingleWordOperand(2), binary); + // The dbg_inst may have been cleared to a Nop, in which case + // ignore it. + if (!dbg_inst->IsNop()) { + scope.ToBinary(dbg_inst->type_id(), context()->TakeNextId(), + dbg_inst->GetSingleWordOperand(2), binary); + } } last_scope = scope; }