Validate Ids before DataRules. (#1622)

Validate Ids before DataRules.

The DataRule validators call FindDefs with the assumption that they
definitions being looked at can be found. This may not be true if we
have not validated identifiers first.

This CL flips the IdPass and DataRulesPass to fix this issue.
This commit is contained in:
dan sinclair 2018-06-19 09:32:20 -04:00 committed by GitHub
parent ea7239fa73
commit d3ed998222
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -174,8 +174,10 @@ spv_result_t ProcessInstruction(void* user_data,
DebugInstructionPass(_, inst);
if (auto error = CapabilityPass(_, inst)) return error;
if (auto error = DataRulesPass(_, inst)) return error;
// The IdPass check registers instructions and, therefore, must be called
// before any instruction lookups are performed.
if (auto error = IdPass(_, inst)) return error;
if (auto error = DataRulesPass(_, inst)) return error;
if (auto error = ModuleLayoutPass(_, inst)) return error;
if (auto error = CfgPass(_, inst)) return error;
if (auto error = InstructionPass(_, inst)) return error;

View File

@ -343,6 +343,16 @@ TEST_F(ValidateData, matrix_data_type_float) {
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
}
TEST_F(ValidateData, ids_should_be_validated_before_data) {
string str = header + R"(
%f32 = OpTypeFloat 32
%mat33 = OpTypeMatrix %vec3 3
)";
CompileSuccessfully(str.c_str());
ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
EXPECT_THAT(getDiagnosticString(), HasSubstr("ID 3 has not been defined"));
}
TEST_F(ValidateData, matrix_bad_column_type) {
string str = header + R"(
%f32 = OpTypeFloat 32