mirror of
https://gitee.com/openharmony/third_party_spirv-tools
synced 2024-11-26 17:10:52 +00:00
commit
a7fd79e84f
@ -1362,10 +1362,10 @@ spv_result_t ValidateAccessChain(ValidationState_t& _,
|
||||
// should be less than the number of struct members.
|
||||
const uint32_t num_struct_members =
|
||||
static_cast<uint32_t>(type_pointee->words().size() - 2);
|
||||
if (cur_index >= num_struct_members) {
|
||||
if (cur_index >= num_struct_members || cur_index < 0) {
|
||||
return _.diag(SPV_ERROR_INVALID_ID, cur_word_instr)
|
||||
<< "Index is out of bounds: " << instr_name
|
||||
<< " can not find index " << cur_index
|
||||
<< " cannot find index " << cur_index
|
||||
<< " into the structure <id> "
|
||||
<< _.getIdName(type_pointee->id()) << ". This structure has "
|
||||
<< num_struct_members << " members. Largest valid index is "
|
||||
@ -1385,7 +1385,7 @@ spv_result_t ValidateAccessChain(ValidationState_t& _,
|
||||
}
|
||||
}
|
||||
}
|
||||
// At this point, we have fully walked down from the base using the indeces.
|
||||
// At this point, we have fully walked down from the base using the indices.
|
||||
// The type being pointed to should be the same as the result type.
|
||||
if (type_pointee->id() != result_type_pointee->id()) {
|
||||
return _.diag(SPV_ERROR_INVALID_ID, inst)
|
||||
|
@ -4199,7 +4199,7 @@ OpReturn
|
||||
OpFunctionEnd
|
||||
)";
|
||||
const std::string expected_err = "Index is out of bounds: " + instr +
|
||||
" can not find index 3 into the structure "
|
||||
" cannot find index 3 into the structure "
|
||||
"<id> '25[%_struct_25]'. This structure "
|
||||
"has 3 members. Largest valid index is 2.";
|
||||
CompileSuccessfully(spirv);
|
||||
|
@ -4712,6 +4712,61 @@ OpFunctionEnd
|
||||
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
|
||||
}
|
||||
|
||||
TEST_F(ValidateMemory, AccessChainNegativeStructIndex32) {
|
||||
const std::string spirv = R"(
|
||||
OpCapability Shader
|
||||
OpCapability Linkage
|
||||
OpMemoryModel Logical GLSL450
|
||||
%void = OpTypeVoid
|
||||
%void_fn = OpTypeFunction %void
|
||||
%int = OpTypeInt 32 1
|
||||
%_struct_4 = OpTypeStruct %int %int %int
|
||||
%_ptr_Function__struct_4 = OpTypePointer Function %_struct_4
|
||||
%_ptr_Function_int = OpTypePointer Function %int
|
||||
%int_n224 = OpConstant %int -224
|
||||
%fn = OpFunction %void Inline %void_fn
|
||||
%entry = OpLabel
|
||||
%var = OpVariable %_ptr_Function__struct_4 Function
|
||||
%gep = OpInBoundsAccessChain %_ptr_Function_int %var %int_n224
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
)";
|
||||
|
||||
CompileSuccessfully(spirv);
|
||||
EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
|
||||
EXPECT_THAT(getDiagnosticString(), HasSubstr("Index is out of bounds"));
|
||||
EXPECT_THAT(getDiagnosticString(), HasSubstr("cannot find index -224"));
|
||||
}
|
||||
|
||||
TEST_F(ValidateMemory, AccessChainNegativeStructIndex64) {
|
||||
const std::string spirv = R"(
|
||||
OpCapability Shader
|
||||
OpCapability Linkage
|
||||
OpCapability Int64
|
||||
OpMemoryModel Logical GLSL450
|
||||
%void = OpTypeVoid
|
||||
%void_fn = OpTypeFunction %void
|
||||
%int = OpTypeInt 32 1
|
||||
%long = OpTypeInt 64 1
|
||||
%_struct_4 = OpTypeStruct %int %int %int
|
||||
%_ptr_Function__struct_4 = OpTypePointer Function %_struct_4
|
||||
%_ptr_Function_int = OpTypePointer Function %int
|
||||
%long_n224 = OpConstant %long -224
|
||||
%fn = OpFunction %void Inline %void_fn
|
||||
%entry = OpLabel
|
||||
%var = OpVariable %_ptr_Function__struct_4 Function
|
||||
%gep = OpInBoundsAccessChain %_ptr_Function_int %var %long_n224
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
)";
|
||||
|
||||
CompileSuccessfully(spirv);
|
||||
EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
|
||||
EXPECT_THAT(getDiagnosticString(), HasSubstr("Index is out of bounds"));
|
||||
EXPECT_THAT(getDiagnosticString(), HasSubstr("cannot find index -224"));
|
||||
}
|
||||
|
||||
|
||||
} // namespace
|
||||
} // namespace val
|
||||
} // namespace spvtools
|
||||
|
Loading…
Reference in New Issue
Block a user