[spirv-reader] Test block order dup cases
- branch-conditional where both targets are the same
- switch where the default target is the same as a case target
Bug: tint:3
Change-Id: If5a3e1fead43ae3d528341f3e54dcae959d9eb8c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/20061
Reviewed-by: dan sinclair <dsinclair@google.com>
diff --git a/src/reader/spirv/function_cfg_test.cc b/src/reader/spirv/function_cfg_test.cc
index 255947a..10756a1 100644
--- a/src/reader/spirv/function_cfg_test.cc
+++ b/src/reader/spirv/function_cfg_test.cc
@@ -145,6 +145,29 @@
EXPECT_THAT(fe.rspo(), ElementsAre(10, 20, 30));
}
+TEST_F(SpvParserTest, ComputeBlockOrder_DupConditionalBranch) {
+ auto* p = parser(test::Assemble(CommonTypes() + R"(
+ %100 = OpFunction %void None %voidfn
+
+ %10 = OpLabel
+ OpSelectionMerge %99 None
+ OpBranchConditional %cond %20 %20
+
+ %99 = OpLabel
+ OpReturn
+
+ %20 = OpLabel
+ OpBranch %99
+
+ OpFunctionEnd
+ )"));
+ ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
+ FunctionEmitter fe(p, *spirv_function(100));
+ fe.ComputeBlockOrderAndPositions();
+
+ EXPECT_THAT(fe.rspo(), ElementsAre(10, 20, 99));
+}
+
TEST_F(SpvParserTest, ComputeBlockOrder_RespectConditionalBranchOrder) {
auto* p = parser(test::Assemble(CommonTypes() + R"(
%100 = OpFunction %void None %voidfn
@@ -273,6 +296,36 @@
EXPECT_THAT(fe.rspo(), ElementsAre(10, 30, 20, 80, 99));
}
+TEST_F(SpvParserTest,
+ ComputeBlockOrder_Switch_DefaultSameAsACase) {
+ auto* p = parser(test::Assemble(CommonTypes() + R"(
+ %100 = OpFunction %void None %voidfn
+
+ %10 = OpLabel
+ OpSelectionMerge %99 None
+ OpSwitch %selector %30 20 %20 30 %30 40 %40
+
+ %99 = OpLabel
+ OpReturn
+
+ %30 = OpLabel
+ OpBranch %99
+
+ %20 = OpLabel
+ OpBranch %99
+
+ %40 = OpLabel
+ OpBranch %99
+
+ OpFunctionEnd
+ )"));
+ ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
+ FunctionEmitter fe(p, *spirv_function(100));
+ fe.ComputeBlockOrderAndPositions();
+
+ EXPECT_THAT(fe.rspo(), ElementsAre(10, 40, 20, 30, 99));
+}
+
TEST_F(SpvParserTest, ComputeBlockOrder_RespectSwitchCaseFallthrough) {
auto assembly = CommonTypes() + R"(
%100 = OpFunction %void None %voidfn