Fix build errors (#3804)

This commit is contained in:
Alastair Donaldson 2020-09-15 21:02:20 +01:00 committed by GitHub
parent 3131686d2e
commit f20b523cb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 19 deletions

View File

@ -166,6 +166,13 @@ void TransformationFlattenConditionalBranch::Apply(
branches = {1, 2};
}
// Keep track of blocks and ids for which we should later add dead block and
// irrelevant id facts. We wait until we have finished applying the
// transformation before adding these facts, so that the fact manager has
// access to the fully up-to-date module.
std::vector<uint32_t> dead_blocks;
std::vector<uint32_t> irrelevant_ids;
// Adjust the conditional branches by enclosing problematic instructions
// within conditionals and get references to the last block in each branch.
for (uint32_t branch : branches) {
@ -248,8 +255,9 @@ void TransformationFlattenConditionalBranch::Apply(
// generated by this operation (this is where all the following
// instructions will be).
current_block = EncloseInstructionInConditional(
ir_context, transformation_context, current_block, instruction,
wrapper_info, condition_id, branch == 1);
ir_context, *transformation_context, current_block, instruction,
wrapper_info, condition_id, branch == 1, &dead_blocks,
&irrelevant_ids);
}
next_block_id = current_block->terminator()->GetSingleWordInOperand(0);
@ -341,6 +349,17 @@ void TransformationFlattenConditionalBranch::Apply(
// Invalidate all analyses
ir_context->InvalidateAnalysesExceptFor(opt::IRContext::kAnalysisNone);
// Now that we have finished adding blocks and ids to the module and
// invalidated existing analyses, update the fact manager regarding dead
// blocks and irrelevant ids.
for (auto dead_block : dead_blocks) {
transformation_context->GetFactManager()->AddFactBlockIsDead(dead_block);
}
for (auto irrelevant_id : irrelevant_ids) {
transformation_context->GetFactManager()->AddFactIdIsIrrelevant(
irrelevant_id, ir_context);
}
}
protobufs::Transformation TransformationFlattenConditionalBranch::ToMessage()
@ -484,10 +503,12 @@ TransformationFlattenConditionalBranch::GetInstructionsToWrapperInfo(
opt::BasicBlock*
TransformationFlattenConditionalBranch::EncloseInstructionInConditional(
opt::IRContext* ir_context, TransformationContext* transformation_context,
opt::BasicBlock* block, opt::Instruction* instruction,
opt::IRContext* ir_context,
const TransformationContext& transformation_context, opt::BasicBlock* block,
opt::Instruction* instruction,
const protobufs::SideEffectWrapperInfo& wrapper_info, uint32_t condition_id,
bool exec_if_cond_true) const {
bool exec_if_cond_true, std::vector<uint32_t>* dead_blocks,
std::vector<uint32_t>* irrelevant_ids) const {
// Get the next instruction (it will be useful for splitting).
auto next_instruction = instruction->NextNode();
@ -511,11 +532,9 @@ TransformationFlattenConditionalBranch::EncloseInstructionInConditional(
fuzzerutil::GetIteratorForInstruction(execute_block, next_instruction));
// Propagate the fact that the block is dead to the newly-created blocks.
if (transformation_context->GetFactManager()->BlockIsDead(block->id())) {
transformation_context->GetFactManager()->AddFactBlockIsDead(
execute_block->id());
transformation_context->GetFactManager()->AddFactBlockIsDead(
merge_block->id());
if (transformation_context.GetFactManager()->BlockIsDead(block->id())) {
dead_blocks->emplace_back(execute_block->id());
dead_blocks->emplace_back(merge_block->id());
}
// Initially, consider the merge block as the alternative block to branch to
@ -578,8 +597,7 @@ TransformationFlattenConditionalBranch::EncloseInstructionInConditional(
}
// Mark |ids.placeholder_result_id| as irrelevant.
transformation_context->GetFactManager()->AddFactIdIsIrrelevant(
wrapper_info.placeholder_result_id());
irrelevant_ids->emplace_back(wrapper_info.placeholder_result_id());
// Add an unconditional branch from the new block to the merge block.
alternative_block_temp->AddInstruction(MakeUnique<opt::Instruction>(
@ -603,9 +621,8 @@ TransformationFlattenConditionalBranch::EncloseInstructionInConditional(
{SPV_OPERAND_TYPE_ID, {alternative_block->id()}}}));
// Propagate the fact that the block is dead to the new block.
if (transformation_context->GetFactManager()->BlockIsDead(block->id())) {
transformation_context->GetFactManager()->AddFactBlockIsDead(
alternative_block->id());
if (transformation_context.GetFactManager()->BlockIsDead(block->id())) {
dead_blocks->emplace_back(alternative_block->id());
}
}

View File

@ -93,11 +93,18 @@ class TransformationFlattenConditionalBranch : public Transformation {
// 2 fresh ids are required if the instruction does not have a result id (the
// first two ids in |wrapper_info| must be valid fresh ids), 5 otherwise.
// Returns the merge block created.
//
// |dead_blocks| and |irrelevant_ids| are used to record the ids of blocks
// and instructions for which dead block and irrelevant id facts should
// ultimately be created.
opt::BasicBlock* EncloseInstructionInConditional(
opt::IRContext* ir_context, TransformationContext* transformation_context,
opt::IRContext* ir_context,
const TransformationContext& transformation_context,
opt::BasicBlock* block, opt::Instruction* instruction,
const protobufs::SideEffectWrapperInfo& wrapper_info,
uint32_t condition_id, bool exec_if_cond_true) const;
uint32_t condition_id, bool exec_if_cond_true,
std::vector<uint32_t>* dead_blocks,
std::vector<uint32_t>* irrelevant_ids) const;
// Returns true if the given instruction either has no side effects or it can
// be handled by being enclosed in a conditional.

View File

@ -14,9 +14,9 @@
#include "source/fuzz/transformation_move_instruction_down.h"
#include "external/spirv-headers/include/spirv/unified1/GLSL.std.450.h"
#include "source/fuzz/fuzzer_util.h"
#include "source/fuzz/instruction_descriptor.h"
#include "spirv/unified1/GLSL.std.450.h"
namespace spvtools {
namespace fuzz {

View File

@ -607,7 +607,7 @@ TEST(TransformationMoveInstructionDownTest, HandlesMemoryInstructions) {
TransformationContext transformation_context(&fact_manager,
validator_options);
fact_manager.AddFactValueOfPointeeIsIrrelevant(22);
fact_manager.AddFactValueOfPointeeIsIrrelevant(22, context.get());
// Invalid swaps.