aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralan-baker <alanbaker@google.com>2021-10-15 10:23:15 -0400
committerGitHub <noreply@github.com>2021-10-15 10:23:15 -0400
commit35fd0e17d081b28a0ff15b376329205c20c7d1f8 (patch)
tree78e7df1d4672782c69a326d618713e1a1248bf1b
parent06ebc4806b7de62b01b27f2faacd55d639a20180 (diff)
downloadspirv-tools-35fd0e17d081b28a0ff15b376329205c20c7d1f8.tar.gz
Consider 0xffffffff offset as missing (#4564)
Fixes #4561 * When checking for offsets, don't accept 0xffffffff
-rw-r--r--source/val/validate_decorations.cpp2
-rw-r--r--test/val/val_decoration_test.cpp30
2 files changed, 32 insertions, 0 deletions
diff --git a/source/val/validate_decorations.cpp b/source/val/validate_decorations.cpp
index 8e4c42e4..b7e38a3f 100644
--- a/source/val/validate_decorations.cpp
+++ b/source/val/validate_decorations.cpp
@@ -140,6 +140,8 @@ bool isMissingOffsetInStruct(uint32_t struct_id, ValidationState_t& vstate) {
for (auto& decoration : vstate.id_decorations(struct_id)) {
if (SpvDecorationOffset == decoration.dec_type() &&
Decoration::kInvalidMember != decoration.struct_member_index()) {
+ // Offset 0xffffffff is not valid so ignore it for simplicity's sake.
+ if (decoration.params()[0] == 0xffffffff) return true;
hasOffset[decoration.struct_member_index()] = true;
}
}
diff --git a/test/val/val_decoration_test.cpp b/test/val/val_decoration_test.cpp
index 9fdeb38f..508acfa1 100644
--- a/test/val/val_decoration_test.cpp
+++ b/test/val/val_decoration_test.cpp
@@ -7825,6 +7825,36 @@ OpFunctionEnd
"laid out with Offset decorations"));
}
+TEST_F(ValidateDecorations, AllOnesOffset) {
+ const std::string spirv = R"(
+OpCapability Shader
+OpMemoryModel Logical GLSL450
+OpEntryPoint GLCompute %main "main"
+OpDecorate %var DescriptorSet 0
+OpDecorate %var Binding 0
+OpDecorate %outer Block
+OpMemberDecorate %outer 0 Offset 0
+OpMemberDecorate %struct 0 Offset 4294967295
+%void = OpTypeVoid
+%int = OpTypeInt 32 0
+%struct = OpTypeStruct %int
+%outer = OpTypeStruct %struct
+%ptr = OpTypePointer Uniform %outer
+%var = OpVariable %ptr Uniform
+%void_fn = OpTypeFunction %void
+%main = OpFunction %void None %void_fn
+%entry = OpLabel
+OpReturn
+OpFunctionEnd
+)";
+
+ CompileSuccessfully(spirv);
+ EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
+ EXPECT_THAT(getDiagnosticString(),
+ HasSubstr("decorated as Block must be explicitly laid out with "
+ "Offset decorations"));
+}
+
} // namespace
} // namespace val
} // namespace spvtools