| 37 | } |
| 38 | |
| 39 | bool TransformationStore::IsApplicable( |
| 40 | opt::IRContext* ir_context, |
| 41 | const TransformationContext& transformation_context) const { |
| 42 | // The pointer must exist and have a type. |
| 43 | auto pointer = ir_context->get_def_use_mgr()->GetDef(message_.pointer_id()); |
| 44 | if (!pointer || !pointer->type_id()) { |
| 45 | return false; |
| 46 | } |
| 47 | |
| 48 | // The pointer type must indeed be a pointer. |
| 49 | auto pointer_type = ir_context->get_def_use_mgr()->GetDef(pointer->type_id()); |
| 50 | assert(pointer_type && "Type id must be defined."); |
| 51 | if (pointer_type->opcode() != spv::Op::OpTypePointer) { |
| 52 | return false; |
| 53 | } |
| 54 | |
| 55 | // The pointer must not be read only. |
| 56 | if (pointer->IsReadOnlyPointer()) { |
| 57 | return false; |
| 58 | } |
| 59 | |
| 60 | // We do not want to allow storing to null or undefined pointers. |
| 61 | switch (pointer->opcode()) { |
| 62 | case spv::Op::OpConstantNull: |
| 63 | case spv::Op::OpUndef: |
| 64 | return false; |
| 65 | default: |
| 66 | break; |
| 67 | } |
| 68 | |
| 69 | // Determine which instruction we should be inserting before. |
| 70 | auto insert_before = |
| 71 | FindInstruction(message_.instruction_to_insert_before(), ir_context); |
| 72 | // It must exist, ... |
| 73 | if (!insert_before) { |
| 74 | return false; |
| 75 | } |
| 76 | // ... and it must be legitimate to insert a store before it. |
| 77 | if (!message_.is_atomic() && !fuzzerutil::CanInsertOpcodeBeforeInstruction( |
| 78 | spv::Op::OpStore, insert_before)) { |
| 79 | return false; |
| 80 | } |
| 81 | if (message_.is_atomic() && !fuzzerutil::CanInsertOpcodeBeforeInstruction( |
| 82 | spv::Op::OpAtomicStore, insert_before)) { |
| 83 | return false; |
| 84 | } |
| 85 | |
| 86 | // The block we are inserting into needs to be dead, or else the pointee type |
| 87 | // of the pointer we are storing to needs to be irrelevant (otherwise the |
| 88 | // store could impact on the observable behaviour of the module). |
| 89 | if (!transformation_context.GetFactManager()->BlockIsDead( |
| 90 | ir_context->get_instr_block(insert_before)->id()) && |
| 91 | !transformation_context.GetFactManager()->PointeeValueIsIrrelevant( |
| 92 | message_.pointer_id())) { |
| 93 | return false; |
| 94 | } |
| 95 | |
| 96 | // The value being stored needs to exist and have a type. |
nothing calls this directly
no test coverage detected