mirror of
https://github.com/KhronosGroup/SPIRV-Tools
synced 2024-12-26 01:31:06 +00:00
spirv-fuzz: Fix problem with instruction context (#4394)
Adds an additional validity check to ensure that every instruction's context pointer matches the enclosing IR context. Avoids a redundant copy constructor call in TransformationDuplicateRegionWithSelection that was leading to a bad IR context for some instructions. Related: #4387, #4388. Fixes #4393.
This commit is contained in:
parent
94bcae1344
commit
183fb9fe4c
@ -502,8 +502,12 @@ bool IsValidAndWellFormed(const opt::IRContext* ir_context,
|
||||
// this is a useful aid to debugging.
|
||||
std::unordered_map<uint32_t, opt::Instruction*> unique_ids;
|
||||
bool found_duplicate = false;
|
||||
ir_context->module()->ForEachInst([&consumer, &found_duplicate,
|
||||
ir_context->module()->ForEachInst([&consumer, &found_duplicate, ir_context,
|
||||
&unique_ids](opt::Instruction* inst) {
|
||||
(void)ir_context; // Only used in an assertion; keep release-mode compilers
|
||||
// happy.
|
||||
assert(inst->context() == ir_context &&
|
||||
"Instruction has wrong IR context.");
|
||||
if (unique_ids.count(inst->unique_id()) != 0) {
|
||||
consumer(SPV_MSG_INFO, nullptr, {},
|
||||
"Two instructions have the same unique id (set a breakpoint to "
|
||||
|
@ -309,9 +309,9 @@ void TransformationDuplicateRegionWithSelection::Apply(
|
||||
|
||||
// Construct the merge block.
|
||||
std::unique_ptr<opt::BasicBlock> merge_block =
|
||||
MakeUnique<opt::BasicBlock>(MakeUnique<opt::Instruction>(opt::Instruction(
|
||||
MakeUnique<opt::BasicBlock>(MakeUnique<opt::Instruction>(
|
||||
ir_context, SpvOpLabel, 0, message_.merge_label_fresh_id(),
|
||||
opt::Instruction::OperandList())));
|
||||
opt::Instruction::OperandList()));
|
||||
|
||||
// Get the maps from the protobuf.
|
||||
std::map<uint32_t, uint32_t> original_label_to_duplicate_label =
|
||||
|
Loading…
Reference in New Issue
Block a user