diff --git a/source/val/validate_conversion.cpp b/source/val/validate_conversion.cpp index 2861c8020..b51eec9a4 100644 --- a/source/val/validate_conversion.cpp +++ b/source/val/validate_conversion.cpp @@ -248,7 +248,7 @@ spv_result_t ConversionPass(ValidationState_t& _, const Instruction* inst) { << spvOpcodeString(opcode); 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) << "Expected int scalar as input: " << spvOpcodeString(opcode); break; diff --git a/test/val/val_conversion_test.cpp b/test/val/val_conversion_test.cpp index cc95abe93..5107bddf8 100644 --- a/test/val/val_conversion_test.cpp +++ b/test/val/val_conversion_test.cpp @@ -1279,6 +1279,29 @@ TEST_F(ValidateConversion, BitcastDifferentTotalBitWidth) { "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 val } // namespace spvtools