Disallow forward references in arrays (#3093)
Fixes https://crbug.com/1031049
* Disallow forward references in arrays
* Add a test
diff --git a/source/operand.cpp b/source/operand.cpp
index 39d17a6..00782cd 100644
--- a/source/operand.cpp
+++ b/source/operand.cpp
@@ -503,9 +503,6 @@
case SpvOpTypeForwardPointer:
out = [](unsigned index) { return index == 0; };
break;
- case SpvOpTypeArray:
- out = [](unsigned index) { return index == 1; };
- break;
default:
out = [](unsigned) { return false; };
break;
diff --git a/test/val/val_id_test.cpp b/test/val/val_id_test.cpp
index 019d91a..f3240fb 100644
--- a/test/val/val_id_test.cpp
+++ b/test/val/val_id_test.cpp
@@ -6572,6 +6572,25 @@
"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 val
} // namespace spvtools