Notify the context of instructions that are being erased.

Fixes use-after-free error in RemoveDuplicatesPass

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/1004
This commit is contained in:
Alan Baker 2017-11-23 23:08:58 -05:00 committed by David Neto
parent 3e08a3f718
commit 0cae89e79e
2 changed files with 5 additions and 0 deletions

View File

@ -2,6 +2,8 @@ Revision history for SPIRV-Tools
v2017.2-dev 2017-11-23
- Start v2017.2-dev
- Fixes:
#1004: Use after free of an instruction, in remove-duplicates transform
v2017.1 2017-11-23
- Update README with details on the public_spirv_tools_dev@khronos.org mailing list.

View File

@ -58,6 +58,7 @@ bool RemoveDuplicatesPass::RemoveDuplicateCapabilities(
++i;
} else {
// It's a duplicate, remove it.
irContext->KillInst(&*i);
i = i.Erase();
modified = true;
}
@ -82,6 +83,7 @@ bool RemoveDuplicatesPass::RemoveDuplicatesExtInstImports(
} else {
// It's a duplicate, remove it.
irContext->ReplaceAllUsesWith(i->result_id(), res.first->second);
irContext->KillInst(&*i);
i = i.Erase();
modified = true;
}
@ -121,6 +123,7 @@ bool RemoveDuplicatesPass::RemoveDuplicateTypes(ir::IRContext* irContext) const
// The same type has already been seen before, remove this one.
irContext->ReplaceAllUsesWith(i->result_id(), idToKeep);
modified = true;
irContext->KillInst(&*i);
i = i.Erase();
}
}