diff options
author | dan sinclair <dj2@everburning.com> | 2018-08-02 16:58:45 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-02 16:58:45 -0400 |
commit | d38a0a3b4476798744c4223acbefab3af97698fd (patch) | |
tree | 253da61b409dc020b6a1c45d37a3397a7f601513 | |
parent | 6aa8a5941562b9fb9a7e2d3e4a418de6b9a85572 (diff) |
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.
-rw-r--r-- | source/val/validate.cpp | 8 | ||||
-rw-r--r-- | test/val/val_layout_test.cpp | 15 |
2 files changed, 22 insertions, 1 deletions
diff --git a/source/val/validate.cpp b/source/val/validate.cpp index 806a0447..7fd9fe85 100644 --- a/source/val/validate.cpp +++ b/source/val/validate.cpp @@ -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())); diff --git a/test/val/val_layout_test.cpp b/test/val/val_layout_test.cpp index 95876b8d..353337eb 100644 --- a/test/val/val_layout_test.cpp +++ b/test/val/val_layout_test.cpp @@ -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) { |