mirror of
https://github.com/KhronosGroup/SPIRV-Tools
synced 2024-11-27 05:40:06 +00:00
Validation within function body when doing a FunctionCall. (#1790)
When validating a FunctionCall we can trigger an assert if we are not currently within a function body. This CL adds verification that we are within a function before attempting to add a function call. Issue 1789.
This commit is contained in:
parent
6aa8a59415
commit
d38a0a3b44
@ -266,8 +266,14 @@ spv_result_t ValidateBinaryUsingContextAndValidationState(
|
||||
vstate->RegisterEntryPoint(entry_point, execution_model,
|
||||
std::move(desc));
|
||||
}
|
||||
if (inst->opcode() == SpvOpFunctionCall)
|
||||
if (inst->opcode() == SpvOpFunctionCall) {
|
||||
if (!vstate->in_function_body()) {
|
||||
return vstate->diag(SPV_ERROR_INVALID_LAYOUT, &instruction)
|
||||
<< "A FunctionCall must happen within a function body.";
|
||||
}
|
||||
|
||||
vstate->AddFunctionCallTarget(inst->GetOperandAs<uint32_t>(2));
|
||||
}
|
||||
|
||||
if (vstate->in_function_body()) {
|
||||
inst->set_function(&(vstate->current_function()));
|
||||
|
@ -494,6 +494,21 @@ TEST_F(ValidateEntryPoint, FunctionIsTargetOfEntryPointAndFunctionCallBad) {
|
||||
"instruction and an OpFunctionCall instruction."));
|
||||
}
|
||||
|
||||
// Invalid. Must be within a function to make a function call.
|
||||
TEST_F(ValidateEntryPoint, FunctionCallOutsideFunctionBody) {
|
||||
std::string spirv = R"(
|
||||
OpCapability Shader
|
||||
%1 = OpExtInstImport "GLSL.std.450"
|
||||
OpMemoryModel Logical GLSL450
|
||||
OpName %variableName "variableName"
|
||||
%34 = OpFunctionCall %variableName %1
|
||||
)";
|
||||
CompileSuccessfully(spirv);
|
||||
EXPECT_EQ(SPV_ERROR_INVALID_LAYOUT, ValidateInstructions());
|
||||
EXPECT_THAT(getDiagnosticString(),
|
||||
HasSubstr("FunctionCall must happen within a function body."));
|
||||
}
|
||||
|
||||
// Valid. Module with a function but no entry point is valid when Linkage
|
||||
// Capability is used.
|
||||
TEST_F(ValidateEntryPoint, NoEntryPointWithLinkageCapGood) {
|
||||
|
Loading…
Reference in New Issue
Block a user