| 106 | } |
| 107 | |
| 108 | void TransformationCompositeInsert::Apply( |
| 109 | opt::IRContext* ir_context, |
| 110 | TransformationContext* transformation_context) const { |
| 111 | // |message_.struct_fresh_id| must be fresh. |
| 112 | assert(fuzzerutil::IsFreshId(ir_context, message_.fresh_id()) && |
| 113 | "|message_.fresh_id| must be fresh"); |
| 114 | |
| 115 | std::vector<uint32_t> index = |
| 116 | fuzzerutil::RepeatedFieldToVector(message_.index()); |
| 117 | opt::Instruction::OperandList in_operands; |
| 118 | in_operands.push_back({SPV_OPERAND_TYPE_ID, {message_.object_id()}}); |
| 119 | in_operands.push_back({SPV_OPERAND_TYPE_ID, {message_.composite_id()}}); |
| 120 | for (auto i : index) { |
| 121 | in_operands.push_back({SPV_OPERAND_TYPE_LITERAL_INTEGER, {i}}); |
| 122 | } |
| 123 | auto composite_type_id = |
| 124 | fuzzerutil::GetTypeId(ir_context, message_.composite_id()); |
| 125 | |
| 126 | auto insert_before = |
| 127 | FindInstruction(message_.instruction_to_insert_before(), ir_context); |
| 128 | auto new_instruction = MakeUnique<opt::Instruction>( |
| 129 | ir_context, spv::Op::OpCompositeInsert, composite_type_id, |
| 130 | message_.fresh_id(), std::move(in_operands)); |
| 131 | auto new_instruction_ptr = new_instruction.get(); |
| 132 | insert_before->InsertBefore(std::move(new_instruction)); |
| 133 | |
| 134 | fuzzerutil::UpdateModuleIdBound(ir_context, message_.fresh_id()); |
| 135 | |
| 136 | // Inform the def-use manager about the new instruction and record its basic |
| 137 | // block. |
| 138 | ir_context->get_def_use_mgr()->AnalyzeInstDefUse(new_instruction_ptr); |
| 139 | ir_context->set_instr_block(new_instruction_ptr, |
| 140 | ir_context->get_instr_block(insert_before)); |
| 141 | |
| 142 | // Add data synonym facts that arise from the insertion. |
| 143 | AddDataSynonymFacts(ir_context, transformation_context); |
| 144 | } |
| 145 | |
| 146 | protobufs::Transformation TransformationCompositeInsert::ToMessage() const { |
| 147 | protobufs::Transformation result; |
nothing calls this directly
no test coverage detected