mirror of
https://github.com/xenia-project/SPIRV-Tools.git
synced 2024-11-26 20:50:22 +00:00
Fix diagnostic message for layout errors
This commit is contained in:
parent
90a4252aae
commit
11437165d6
@ -288,7 +288,8 @@ Function& ValidationState_t::get_current_function() {
|
||||
bool ValidationState_t::in_function_body() const { return in_function_; }
|
||||
|
||||
bool ValidationState_t::in_block() const {
|
||||
return module_functions_.back().get_current_block() != nullptr;
|
||||
return module_functions_.empty() == false &&
|
||||
module_functions_.back().get_current_block() != nullptr;
|
||||
}
|
||||
|
||||
void ValidationState_t::RegisterCapability(SpvCapability cap) {
|
||||
|
@ -158,7 +158,8 @@ spv_result_t FunctionScopedInstructions(ValidationState_t& _,
|
||||
break;
|
||||
|
||||
default:
|
||||
if (_.getLayoutSection() == kLayoutFunctionDeclarations) {
|
||||
if (_.getLayoutSection() == kLayoutFunctionDeclarations &&
|
||||
_.in_function_body()) {
|
||||
return _.diag(SPV_ERROR_INVALID_LAYOUT)
|
||||
<< "A function must begin with a label";
|
||||
} else {
|
||||
|
@ -47,7 +47,7 @@ using std::tie;
|
||||
using std::tuple;
|
||||
using std::vector;
|
||||
|
||||
using ::testing::HasSubstr;
|
||||
using ::testing::StrEq;
|
||||
|
||||
using libspirv::spvResultToString;
|
||||
|
||||
@ -313,6 +313,25 @@ TEST_F(ValidateLayout, FuncParameterNotImmediatlyAfterFuncBad) {
|
||||
ASSERT_EQ(SPV_ERROR_INVALID_LAYOUT, ValidateInstructions());
|
||||
}
|
||||
|
||||
TEST_F(ValidateLayout, InstructionAppearBeforeFunctionDefinition) {
|
||||
string str = R"(
|
||||
OpCapability Kernel
|
||||
OpMemoryModel Logical OpenCL
|
||||
%voidt = OpTypeVoid
|
||||
%uintt = OpTypeInt 32 0
|
||||
%funct = OpTypeFunction %voidt
|
||||
%udef = OpUndef %uintt
|
||||
%func = OpFunction %voidt None %funct
|
||||
%entry = OpLabel
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
)";
|
||||
|
||||
CompileSuccessfully(str);
|
||||
ASSERT_EQ(SPV_ERROR_INVALID_LAYOUT, ValidateInstructions());
|
||||
EXPECT_THAT(getDiagnosticString(), StrEq("Undef must appear in a block"));
|
||||
}
|
||||
|
||||
using ValidateOpFunctionParameter = spvtest::ValidateBase<int>;
|
||||
|
||||
TEST_F(ValidateOpFunctionParameter, OpLineBetweenParameters) {
|
||||
|
Loading…
Reference in New Issue
Block a user