MCPcopy Create free account
hub / github.com/KhronosGroup/SPIRV-Tools / FindOrCreateLocalVariable

Method FindOrCreateLocalVariable

source/fuzz/fuzzer_pass.cpp:703–745  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

701}
702
703uint32_t FuzzerPass::FindOrCreateLocalVariable(
704 uint32_t pointer_type_id, uint32_t function_id,
705 bool pointee_value_is_irrelevant) {
706 auto pointer_type = GetIRContext()->get_type_mgr()->GetType(pointer_type_id);
707 // No unused variables in release mode.
708 (void)pointer_type;
709 assert(pointer_type && pointer_type->AsPointer() &&
710 pointer_type->AsPointer()->storage_class() ==
711 spv::StorageClass::Function &&
712 "The pointer_type_id must refer to a defined pointer type with "
713 "storage class Function");
714 auto function = fuzzerutil::FindFunction(GetIRContext(), function_id);
715 assert(function && "The function must be defined.");
716
717 // First we try to find a suitable existing variable.
718 // All of the local variable declarations are located in the first block.
719 for (auto& instruction : *function->begin()) {
720 if (instruction.opcode() != spv::Op::OpVariable) {
721 continue;
722 }
723 // The existing OpVariable must have type |pointer_type_id|.
724 if (instruction.type_id() != pointer_type_id) {
725 continue;
726 }
727 // Check if the found variable is marked with PointeeValueIsIrrelevant
728 // according to |pointee_value_is_irrelevant|.
729 if (GetTransformationContext()->GetFactManager()->PointeeValueIsIrrelevant(
730 instruction.result_id()) != pointee_value_is_irrelevant) {
731 continue;
732 }
733 return instruction.result_id();
734 }
735
736 // No such variable was found. Apply a transformation to get one.
737 uint32_t pointee_type_id = fuzzerutil::GetPointeeTypeIdFromPointerType(
738 GetIRContext(), pointer_type_id);
739 uint32_t result_id = GetFuzzerContext()->GetFreshId();
740 ApplyTransformation(TransformationAddLocalVariable(
741 result_id, pointer_type_id, function_id,
742 FindOrCreateZeroConstant(pointee_type_id, pointee_value_is_irrelevant),
743 pointee_value_is_irrelevant));
744 return result_id;
745}
746
747uint32_t FuzzerPass::FindOrCreateGlobalVariable(
748 uint32_t pointer_type_id, bool pointee_value_is_irrelevant) {

Callers

nothing calls this directly

Calls 14

FindFunctionFunction · 0.85
get_type_mgrMethod · 0.80
AsPointerMethod · 0.80
GetFactManagerMethod · 0.80
GetFreshIdMethod · 0.80
GetTypeMethod · 0.45
storage_classMethod · 0.45
beginMethod · 0.45
opcodeMethod · 0.45
type_idMethod · 0.45

Tested by

no test coverage detected