| 39 | } |
| 40 | |
| 41 | bool TransformationFunctionCall::IsApplicable( |
| 42 | opt::IRContext* ir_context, |
| 43 | const TransformationContext& transformation_context) const { |
| 44 | // The result id must be fresh |
| 45 | if (!fuzzerutil::IsFreshId(ir_context, message_.fresh_id())) { |
| 46 | return false; |
| 47 | } |
| 48 | |
| 49 | // The function must exist |
| 50 | auto callee_inst = |
| 51 | ir_context->get_def_use_mgr()->GetDef(message_.callee_id()); |
| 52 | if (!callee_inst || callee_inst->opcode() != spv::Op::OpFunction) { |
| 53 | return false; |
| 54 | } |
| 55 | |
| 56 | // The function must not be an entry point |
| 57 | if (fuzzerutil::FunctionIsEntryPoint(ir_context, message_.callee_id())) { |
| 58 | return false; |
| 59 | } |
| 60 | |
| 61 | auto callee_type_inst = ir_context->get_def_use_mgr()->GetDef( |
| 62 | callee_inst->GetSingleWordInOperand(1)); |
| 63 | assert(callee_type_inst->opcode() == spv::Op::OpTypeFunction && |
| 64 | "Bad function type."); |
| 65 | |
| 66 | // The number of expected function arguments must match the number of given |
| 67 | // arguments. The number of expected arguments is one less than the function |
| 68 | // type's number of input operands, as one operand is for the return type. |
| 69 | if (callee_type_inst->NumInOperands() - 1 != |
| 70 | static_cast<uint32_t>(message_.argument_id().size())) { |
| 71 | return false; |
| 72 | } |
| 73 | |
| 74 | // The instruction descriptor must refer to a position where it is valid to |
| 75 | // insert the call |
| 76 | auto insert_before = |
| 77 | FindInstruction(message_.instruction_to_insert_before(), ir_context); |
| 78 | if (!insert_before) { |
| 79 | return false; |
| 80 | } |
| 81 | if (!fuzzerutil::CanInsertOpcodeBeforeInstruction(spv::Op::OpFunctionCall, |
| 82 | insert_before)) { |
| 83 | return false; |
| 84 | } |
| 85 | |
| 86 | auto block = ir_context->get_instr_block(insert_before); |
| 87 | auto enclosing_function = block->GetParent(); |
| 88 | |
| 89 | // If the block is not dead, the function must be livesafe |
| 90 | bool block_is_dead = |
| 91 | transformation_context.GetFactManager()->BlockIsDead(block->id()); |
| 92 | if (!block_is_dead && |
| 93 | !transformation_context.GetFactManager()->FunctionIsLivesafe( |
| 94 | message_.callee_id())) { |
| 95 | return false; |
| 96 | } |
| 97 | |
| 98 | // The ids must all match and have the right types and satisfy rules on |
nothing calls this directly
no test coverage detected