Catch invalid input type to OpConvertUToPtr (#2078)

Fixes https://crbug.com/906426

* Fails validation if the input operand is a type
* Added a test
This commit is contained in:
alan-baker 2018-11-19 15:08:38 -05:00 committed by GitHub
parent 8cd2a9d187
commit f5b4a8eee3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -248,7 +248,7 @@ spv_result_t ConversionPass(ValidationState_t& _, const Instruction* inst) {
<< spvOpcodeString(opcode); << spvOpcodeString(opcode);
const uint32_t input_type = _.GetOperandTypeId(inst, 2); const uint32_t input_type = _.GetOperandTypeId(inst, 2);
if (!_.IsIntScalarType(input_type)) if (!input_type || !_.IsIntScalarType(input_type))
return _.diag(SPV_ERROR_INVALID_DATA, inst) return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Expected int scalar as input: " << spvOpcodeString(opcode); << "Expected int scalar as input: " << spvOpcodeString(opcode);
break; break;

View File

@ -1279,6 +1279,29 @@ TEST_F(ValidateConversion, BitcastDifferentTotalBitWidth) {
"Bitcast")); "Bitcast"));
} }
TEST_F(ValidateConversion, ConvertUToPtrInputIsAType) {
const std::string spirv = R"(
OpCapability Addresses
OpCapability Shader
OpCapability Linkage
OpMemoryModel Logical GLSL450
%int = OpTypeInt 32 0
%ptr_int = OpTypePointer Function %int
%void = OpTypeVoid
%voidfn = OpTypeFunction %void
%func = OpFunction %void None %voidfn
%entry = OpLabel
%1 = OpConvertUToPtr %ptr_int %int
OpReturn
OpFunctionEnd
)";
CompileSuccessfully(spirv);
EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
EXPECT_THAT(getDiagnosticString(),
HasSubstr("Expected int scalar as input: ConvertUToPtr"));
}
} // namespace } // namespace
} // namespace val } // namespace val
} // namespace spvtools } // namespace spvtools