mirror of
https://github.com/KhronosGroup/SPIRV-Tools
synced 2024-10-18 11:10:05 +00:00
Error for invalid location type (#5249)
Fixes https://crbug.com/oss-fuzz/56754 * When checking locations, produce an error if the type cannot be assigned a location
This commit is contained in:
parent
673d8bfcb6
commit
cf62673e42
@ -174,7 +174,8 @@ spv_result_t NumConsumedLocations(ValidationState_t& _, const Instruction* type,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
return _.diag(SPV_ERROR_INVALID_DATA, type)
|
||||||
|
<< "Invalid type to assign a location";
|
||||||
}
|
}
|
||||||
|
|
||||||
return SPV_SUCCESS;
|
return SPV_SUCCESS;
|
||||||
@ -363,12 +364,12 @@ spv_result_t GetLocationsForVariable(
|
|||||||
sub_type = _.FindDef(sub_type_id);
|
sub_type = _.FindDef(sub_type_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint32_t array_idx = 0; array_idx < array_size; ++array_idx) {
|
uint32_t num_locations = 0;
|
||||||
uint32_t num_locations = 0;
|
if (auto error = NumConsumedLocations(_, sub_type, &num_locations))
|
||||||
if (auto error = NumConsumedLocations(_, sub_type, &num_locations))
|
return error;
|
||||||
return error;
|
uint32_t num_components = NumConsumedComponents(_, sub_type);
|
||||||
|
|
||||||
uint32_t num_components = NumConsumedComponents(_, sub_type);
|
for (uint32_t array_idx = 0; array_idx < array_size; ++array_idx) {
|
||||||
uint32_t array_location = location + (num_locations * array_idx);
|
uint32_t array_location = location + (num_locations * array_idx);
|
||||||
uint32_t start = array_location * 4;
|
uint32_t start = array_location * 4;
|
||||||
if (kMaxLocations <= start) {
|
if (kMaxLocations <= start) {
|
||||||
|
@ -1570,6 +1570,35 @@ OpFunctionEnd
|
|||||||
"Interface struct has no Block decoration but has BuiltIn members."));
|
"Interface struct has no Block decoration but has BuiltIn members."));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(ValidateInterfacesTest, InvalidLocationTypePointer) {
|
||||||
|
const std::string text = R"(
|
||||||
|
OpCapability Shader
|
||||||
|
OpMemoryModel Logical Simple
|
||||||
|
OpEntryPoint Vertex %1 "Aiqn0" %2 %3
|
||||||
|
OpDecorate %2 Location 0
|
||||||
|
%void = OpTypeVoid
|
||||||
|
%5 = OpTypeFunction %void
|
||||||
|
%float = OpTypeFloat 32
|
||||||
|
%_ptr_Private_void = OpTypePointer Private %void
|
||||||
|
%uint = OpTypeInt 32 0
|
||||||
|
%uint_4278132784 = OpConstant %uint 4278132784
|
||||||
|
%_arr__ptr_Private_void_uint_4278132784 = OpTypeArray %_ptr_Private_void %uint_4278132784
|
||||||
|
%_ptr_Output__arr__ptr_Private_void_uint_4278132784 = OpTypePointer Output %_arr__ptr_Private_void_uint_4278132784
|
||||||
|
%2 = OpVariable %_ptr_Output__arr__ptr_Private_void_uint_4278132784 Output
|
||||||
|
%_ptr_Output__ptr_Private_void = OpTypePointer Output %_ptr_Private_void
|
||||||
|
%3 = OpVariable %_ptr_Output__arr__ptr_Private_void_uint_4278132784 Output
|
||||||
|
%1 = OpFunction %void None %5
|
||||||
|
%15 = OpLabel
|
||||||
|
OpReturn
|
||||||
|
OpFunctionEnd
|
||||||
|
)";
|
||||||
|
|
||||||
|
CompileSuccessfully(text, SPV_ENV_VULKAN_1_1);
|
||||||
|
EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_1));
|
||||||
|
EXPECT_THAT(getDiagnosticString(),
|
||||||
|
HasSubstr("Invalid type to assign a location"));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace val
|
} // namespace val
|
||||||
} // namespace spvtools
|
} // namespace spvtools
|
||||||
|
Loading…
Reference in New Issue
Block a user