mirror of
https://github.com/KhronosGroup/SPIRV-Tools
synced 2024-10-18 11:10:05 +00:00
Fix result type check in ValidateImageTexelPointer (#5848)
Fixes https://crbug.com/oss-fuzz/42537207 * Fix check and messages in ValidateImageTexelPointer
This commit is contained in:
parent
fcf994a619
commit
42b315c15b
@ -1134,15 +1134,15 @@ spv_result_t ValidateImageTexelPointer(ValidationState_t& _,
|
|||||||
const Instruction* inst) {
|
const Instruction* inst) {
|
||||||
const auto result_type = _.FindDef(inst->type_id());
|
const auto result_type = _.FindDef(inst->type_id());
|
||||||
if (result_type->opcode() != spv::Op::OpTypePointer &&
|
if (result_type->opcode() != spv::Op::OpTypePointer &&
|
||||||
result_type->opcode() == spv::Op::OpTypeUntypedPointerKHR) {
|
result_type->opcode() != spv::Op::OpTypeUntypedPointerKHR) {
|
||||||
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
||||||
<< "Expected Result Type to be OpTypePointer";
|
<< "Expected Result Type to be a pointer";
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto storage_class = result_type->GetOperandAs<spv::StorageClass>(1);
|
const auto storage_class = result_type->GetOperandAs<spv::StorageClass>(1);
|
||||||
if (storage_class != spv::StorageClass::Image) {
|
if (storage_class != spv::StorageClass::Image) {
|
||||||
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
||||||
<< "Expected Result Type to be OpTypePointer whose Storage Class "
|
<< "Expected Result Type to be a pointer whose Storage Class "
|
||||||
"operand is Image";
|
"operand is Image";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1157,7 +1157,7 @@ spv_result_t ValidateImageTexelPointer(ValidationState_t& _,
|
|||||||
_.HasCapability(spv::Capability::AtomicFloat16VectorNV) &&
|
_.HasCapability(spv::Capability::AtomicFloat16VectorNV) &&
|
||||||
_.IsFloat16Vector2Or4Type(ptr_type))) {
|
_.IsFloat16Vector2Or4Type(ptr_type))) {
|
||||||
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
||||||
<< "Expected Result Type to be OpTypePointer whose Type operand "
|
<< "Expected Result Type to be a pointer whose Type operand "
|
||||||
"must be a scalar numerical type or OpTypeVoid";
|
"must be a scalar numerical type or OpTypeVoid";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1380,7 +1380,7 @@ TEST_F(ValidateImage, ImageTexelPointerResultTypeNotPointer) {
|
|||||||
CompileSuccessfully(GenerateShaderCode(body).c_str());
|
CompileSuccessfully(GenerateShaderCode(body).c_str());
|
||||||
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
|
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
|
||||||
EXPECT_THAT(getDiagnosticString(),
|
EXPECT_THAT(getDiagnosticString(),
|
||||||
HasSubstr("Expected Result Type to be OpTypePointer"));
|
HasSubstr("Expected Result Type to be a pointer"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ValidateImage, ImageTexelPointerResultTypeNotImageClass) {
|
TEST_F(ValidateImage, ImageTexelPointerResultTypeNotImageClass) {
|
||||||
@ -1392,7 +1392,7 @@ TEST_F(ValidateImage, ImageTexelPointerResultTypeNotImageClass) {
|
|||||||
CompileSuccessfully(GenerateShaderCode(body).c_str());
|
CompileSuccessfully(GenerateShaderCode(body).c_str());
|
||||||
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
|
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
|
||||||
EXPECT_THAT(getDiagnosticString(),
|
EXPECT_THAT(getDiagnosticString(),
|
||||||
HasSubstr("Expected Result Type to be OpTypePointer whose "
|
HasSubstr("Expected Result Type to be a pointer whose "
|
||||||
"Storage Class operand is Image"));
|
"Storage Class operand is Image"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1406,7 +1406,7 @@ TEST_F(ValidateImage, ImageTexelPointerResultTypeNotNumericNorVoid) {
|
|||||||
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
|
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
|
||||||
EXPECT_THAT(
|
EXPECT_THAT(
|
||||||
getDiagnosticString(),
|
getDiagnosticString(),
|
||||||
HasSubstr("Expected Result Type to be OpTypePointer whose Type operand "
|
HasSubstr("Expected Result Type to be a pointer whose Type operand "
|
||||||
"must be a scalar numerical type or OpTypeVoid"));
|
"must be a scalar numerical type or OpTypeVoid"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -6310,7 +6310,7 @@ TEST_F(ValidateImage, ImageTexelPointer64ResultTypeNotPointer) {
|
|||||||
.c_str());
|
.c_str());
|
||||||
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
|
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
|
||||||
EXPECT_THAT(getDiagnosticString(),
|
EXPECT_THAT(getDiagnosticString(),
|
||||||
HasSubstr("Expected Result Type to be OpTypePointer"));
|
HasSubstr("Expected Result Type to be a pointer"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ValidateImage, ImageTexelPointer64ResultTypeNotImageClass) {
|
TEST_F(ValidateImage, ImageTexelPointer64ResultTypeNotImageClass) {
|
||||||
@ -6326,7 +6326,7 @@ TEST_F(ValidateImage, ImageTexelPointer64ResultTypeNotImageClass) {
|
|||||||
.c_str());
|
.c_str());
|
||||||
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
|
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
|
||||||
EXPECT_THAT(getDiagnosticString(),
|
EXPECT_THAT(getDiagnosticString(),
|
||||||
HasSubstr("Expected Result Type to be OpTypePointer whose "
|
HasSubstr("Expected Result Type to be a pointer whose "
|
||||||
"Storage Class operand is Image"));
|
"Storage Class operand is Image"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -10875,6 +10875,28 @@ OpFunctionEnd
|
|||||||
"Image operands must match result image operands except for depth"));
|
"Image operands must match result image operands except for depth"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(ValidateImage, ImageTexelPointerNotAPointer) {
|
||||||
|
const std::string code = R"(
|
||||||
|
OpCapability ClipDistance
|
||||||
|
OpMemoryModel Logical Simple
|
||||||
|
%void = OpTypeVoid
|
||||||
|
%57 = OpTypeFunction %void
|
||||||
|
%int = OpTypeInt 32 1
|
||||||
|
%int_538976288 = OpConstant %int 538976288
|
||||||
|
%int_538976288_0 = OpConstant %int 538976288
|
||||||
|
%8224 = OpFunction %void None %57
|
||||||
|
%65312 = OpLabel
|
||||||
|
%2097184 = OpImageTexelPointer %void %int_538976288 %int_538976288 %int_538976288_0
|
||||||
|
OpUnreachable
|
||||||
|
OpFunctionEnd
|
||||||
|
)";
|
||||||
|
|
||||||
|
CompileSuccessfully(code);
|
||||||
|
EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
|
||||||
|
EXPECT_THAT(getDiagnosticString(),
|
||||||
|
HasSubstr("Expected Result Type to be a pointer"));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace val
|
} // namespace val
|
||||||
} // namespace spvtools
|
} // namespace spvtools
|
||||||
|
Loading…
Reference in New Issue
Block a user