| 32 | } |
| 33 | |
| 34 | bool TransformationAddDeadBlock::IsApplicable( |
| 35 | opt::IRContext* ir_context, |
| 36 | const TransformationContext& transformation_context) const { |
| 37 | // The new block's id must be fresh. |
| 38 | if (!fuzzerutil::IsFreshId(ir_context, message_.fresh_id())) { |
| 39 | return false; |
| 40 | } |
| 41 | |
| 42 | // First, we check that a constant with the same value as |
| 43 | // |message_.condition_value| is present. |
| 44 | if (!fuzzerutil::MaybeGetBoolConstant(ir_context, transformation_context, |
| 45 | message_.condition_value(), false)) { |
| 46 | // The required constant is not present, so the transformation cannot be |
| 47 | // applied. |
| 48 | return false; |
| 49 | } |
| 50 | |
| 51 | // The existing block must indeed exist. |
| 52 | auto existing_block = |
| 53 | fuzzerutil::MaybeFindBlock(ir_context, message_.existing_block()); |
| 54 | if (!existing_block) { |
| 55 | return false; |
| 56 | } |
| 57 | |
| 58 | // It must not head a loop. |
| 59 | if (existing_block->IsLoopHeader()) { |
| 60 | return false; |
| 61 | } |
| 62 | |
| 63 | // It must end with OpBranch. |
| 64 | if (existing_block->terminator()->opcode() != spv::Op::OpBranch) { |
| 65 | return false; |
| 66 | } |
| 67 | |
| 68 | // Its successor must not be a merge block nor continue target. |
| 69 | auto successor_block_id = |
| 70 | existing_block->terminator()->GetSingleWordInOperand(0); |
| 71 | if (fuzzerutil::IsMergeOrContinue(ir_context, successor_block_id)) { |
| 72 | return false; |
| 73 | } |
| 74 | |
| 75 | // The successor must not be a loop header (i.e., |message_.existing_block| |
| 76 | // must not be a back-edge block. |
| 77 | if (ir_context->cfg()->block(successor_block_id)->IsLoopHeader()) { |
| 78 | return false; |
| 79 | } |
| 80 | |
| 81 | // |existing_block| must be reachable. |
| 82 | if (!ir_context->IsReachable(*existing_block)) { |
| 83 | return false; |
| 84 | } |
| 85 | |
| 86 | assert(existing_block->id() != successor_block_id && |
| 87 | "|existing_block| must be different from |successor_block_id|"); |
| 88 | |
| 89 | // Even though we know |successor_block_id| is not a merge block, it might |
| 90 | // still have multiple predecessors because divergent control flow is allowed |
| 91 | // to converge early (before the merge block). In this case, when we create |
nothing calls this directly
no test coverage detected