Disallow forward references in arrays (#3093)

Fixes https://crbug.com/1031049

* Disallow forward references in arrays
* Add a test
This commit is contained in:
alan-baker 2020-01-07 09:38:17 -05:00 committed by GitHub
parent 31acc78821
commit a466b99dbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 3 deletions

View File

@ -503,9 +503,6 @@ std::function<bool(unsigned)> spvOperandCanBeForwardDeclaredFunction(
case SpvOpTypeForwardPointer: case SpvOpTypeForwardPointer:
out = [](unsigned index) { return index == 0; }; out = [](unsigned index) { return index == 0; };
break; break;
case SpvOpTypeArray:
out = [](unsigned index) { return index == 1; };
break;
default: default:
out = [](unsigned) { return false; }; out = [](unsigned) { return false; };
break; break;

View File

@ -6572,6 +6572,25 @@ TEST_F(ValidateIdWithMessage, MissingForwardPointer) {
"Operand 3[%_ptr_Uniform__struct_2] requires a previous definition")); "Operand 3[%_ptr_Uniform__struct_2] requires a previous definition"));
} }
TEST_F(ValidateIdWithMessage, ArrayTypeForwardReference) {
const std::string spirv = R"(
OpCapability Linkage
OpCapability MinLod
OpCapability GenericPointer
OpMemoryModel Logical Simple
OpName %_ptr_Input__arr_9_uint_7 "ptr"
%uint = OpTypeInt 32 0
%uint_7 = OpConstant %uint 7
%_arr_9_uint_7 = OpTypeArray %_ptr_Input__arr_9_uint_7 %uint_7
%_ptr_Input__arr_9_uint_7 = OpTypePointer Input %_arr_9_uint_7
)";
CompileSuccessfully(spirv);
EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
EXPECT_THAT(getDiagnosticString(),
HasSubstr("ID 1[%ptr] has not been defined"));
}
} // namespace } // namespace
} // namespace val } // namespace val
} // namespace spvtools } // namespace spvtools