mirror of
https://github.com/KhronosGroup/SPIRV-Tools
synced 2025-01-12 17:30:15 +00:00
Better checking of the index operand (#1992)
Fixes https://crbug.com/897069 * Code previously assumed the index instruction had a type * Added a test to reproduce
This commit is contained in:
parent
6e85d1a6fc
commit
89b8e238eb
@ -148,8 +148,8 @@ spv_result_t ValidateVectorExtractDynamic(ValidationState_t& _,
|
||||
<< "Expected Vector component type to be equal to Result Type";
|
||||
}
|
||||
|
||||
const uint32_t index_type = _.GetOperandTypeId(inst, 3);
|
||||
if (!_.IsIntScalarType(index_type)) {
|
||||
const auto index = _.FindDef(inst->GetOperandAs<uint32_t>(3));
|
||||
if (!index || index->type_id() == 0 || !_.IsIntScalarType(index->type_id())) {
|
||||
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
||||
<< "Expected Index to be int scalar";
|
||||
}
|
||||
|
@ -1469,6 +1469,30 @@ OpFunctionEnd
|
||||
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
|
||||
}
|
||||
|
||||
TEST_F(ValidateComposites, ExtractDynamicLabelIndex) {
|
||||
const std::string spirv = R"(
|
||||
OpCapability Shader
|
||||
OpCapability Linkage
|
||||
OpMemoryModel Logical GLSL450
|
||||
%void = OpTypeVoid
|
||||
%float = OpTypeFloat 32
|
||||
%v4float = OpTypeVector %float 4
|
||||
%void_fn = OpTypeFunction %void
|
||||
%float_0 = OpConstant %float 0
|
||||
%v4float_0 = OpConstantComposite %v4float %float_0 %float_0 %float_0 %float_0
|
||||
%func = OpFunction %void None %void_fn
|
||||
%1 = OpLabel
|
||||
%ex = OpVectorExtractDynamic %float %v4float_0 %1
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
)";
|
||||
|
||||
CompileSuccessfully(spirv);
|
||||
EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
|
||||
EXPECT_THAT(getDiagnosticString(),
|
||||
HasSubstr("Expected Index to be int scalar"));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace val
|
||||
} // namespace spvtools
|
||||
|
Loading…
Reference in New Issue
Block a user