Ensure that function parameter's type is not void (#2118)

Fixes #2094
This commit is contained in:
Ryan Harrison 2018-11-27 09:40:19 -05:00 committed by GitHub
parent 48d923907b
commit dab634da93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -266,6 +266,12 @@ spv_result_t ValidateTypeFunction(ValidationState_t& _,
<< "OpTypeFunction Parameter Type <id> '" << _.getIdName(param_id)
<< "' is not a type.";
}
if (param_type->opcode() == SpvOpTypeVoid) {
return _.diag(SPV_ERROR_INVALID_ID, inst)
<< "OpTypeFunction Parameter Type <id> '" << _.getIdName(param_id)
<< "' cannot be OpTypeVoid.";
}
}
const uint32_t num_function_args_limit =
_.options()->universal_limits_.max_function_args;

View File

@ -979,6 +979,18 @@ TEST_F(ValidateIdWithMessage, OpTypeFunctionParameterBad) {
HasSubstr("OpTypeFunction Parameter Type <id> '3' is not a type."));
}
TEST_F(ValidateIdWithMessage, OpTypeFunctionParameterTypeVoidBad) {
std::string spirv = kGLSL450MemoryModel + R"(
%1 = OpTypeVoid
%2 = OpTypeInt 32 0
%4 = OpTypeFunction %1 %2 %1)";
CompileSuccessfully(spirv.c_str());
EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
EXPECT_THAT(getDiagnosticString(),
HasSubstr("OpTypeFunction Parameter Type <id> '1' cannot be "
"OpTypeVoid."));
}
TEST_F(ValidateIdWithMessage, OpTypePipeGood) {
std::string spirv = kGLSL450MemoryModel + R"(
%1 = OpTypeFloat 32