diff --git a/src/reader/spirv/function.cc b/src/reader/spirv/function.cc index 0c20f730c5..994cc922e7 100644 --- a/src/reader/spirv/function.cc +++ b/src/reader/spirv/function.cc @@ -1052,9 +1052,13 @@ bool FunctionEmitter::ClassifyCFGEdges() { const bool src_is_loop_header = header_info.continue_for_header != 0; const bool src_is_continue_header = header_info.header_for_continue != 0; - edge_kind = (src_is_loop_header || src_is_continue_header) - ? EdgeKind::kLoopBreak - : EdgeKind::kToMerge; + if (src_is_loop_header || src_is_continue_header) { + edge_kind = EdgeKind::kLoopBreak; + } else if (src_construct.kind == Construct::kSwitchSelection) { + edge_kind = EdgeKind::kSwitchBreak; + } else { + edge_kind = EdgeKind::kToMerge; + } } else { const auto* loop_or_continue_construct = src_construct.enclosing_loop_or_continue; diff --git a/src/reader/spirv/function_cfg_test.cc b/src/reader/spirv/function_cfg_test.cc index 5205d8b322..a37bfabd73 100644 --- a/src/reader/spirv/function_cfg_test.cc +++ b/src/reader/spirv/function_cfg_test.cc @@ -4612,7 +4612,7 @@ TEST_F(SpvParserTest, ClassifyCFGEdges_ToMerge_FromIfThenElse) { EXPECT_EQ(bi50->succ_edge[99], EdgeKind::kToMerge); } -TEST_F(SpvParserTest, ClassifyCFGEdges_ToMerge_FromSwitchCaseDirect) { +TEST_F(SpvParserTest, ClassifyCFGEdges_SwitchBreak_FromSwitchCaseDirect) { auto assembly = CommonTypes() + R"( %100 = OpFunction %void None %voidfn @@ -4634,10 +4634,10 @@ TEST_F(SpvParserTest, ClassifyCFGEdges_ToMerge_FromSwitchCaseDirect) { auto* bi = fe.GetBlockInfo(10); ASSERT_NE(bi, nullptr); EXPECT_EQ(bi->succ_edge.count(99), 1); - EXPECT_EQ(bi->succ_edge[99], EdgeKind::kToMerge); + EXPECT_EQ(bi->succ_edge[99], EdgeKind::kSwitchBreak); } -TEST_F(SpvParserTest, ClassifyCFGEdges_ToMerge_FromSwitchCaseBody) { +TEST_F(SpvParserTest, ClassifyCFGEdges_SwitchBreak_FromSwitchCaseBody) { auto assembly = CommonTypes() + R"( %100 = OpFunction %void None %voidfn @@ -4659,10 +4659,10 @@ TEST_F(SpvParserTest, ClassifyCFGEdges_ToMerge_FromSwitchCaseBody) { auto* bi = fe.GetBlockInfo(20); ASSERT_NE(bi, nullptr); EXPECT_EQ(bi->succ_edge.count(99), 1); - EXPECT_EQ(bi->succ_edge[99], EdgeKind::kToMerge); + EXPECT_EQ(bi->succ_edge[99], EdgeKind::kSwitchBreak); } -TEST_F(SpvParserTest, ClassifyCFGEdges_ToMerge_FromSwitchDefaultBody) { +TEST_F(SpvParserTest, ClassifyCFGEdges_SwitchBreak_FromSwitchDefaultBody) { auto assembly = CommonTypes() + R"( %100 = OpFunction %void None %voidfn @@ -4687,10 +4687,10 @@ TEST_F(SpvParserTest, ClassifyCFGEdges_ToMerge_FromSwitchDefaultBody) { auto* bi = fe.GetBlockInfo(30); ASSERT_NE(bi, nullptr); EXPECT_EQ(bi->succ_edge.count(99), 1); - EXPECT_EQ(bi->succ_edge[99], EdgeKind::kToMerge); + EXPECT_EQ(bi->succ_edge[99], EdgeKind::kSwitchBreak); } -TEST_F(SpvParserTest, ClassifyCFGEdges_ToMerge_FromSwitchDefaultIsMerge) { +TEST_F(SpvParserTest, ClassifyCFGEdges_SwitchBreak_FromSwitchDefaultIsMerge) { auto assembly = CommonTypes() + R"( %100 = OpFunction %void None %voidfn @@ -4712,7 +4712,7 @@ TEST_F(SpvParserTest, ClassifyCFGEdges_ToMerge_FromSwitchDefaultIsMerge) { auto* bi = fe.GetBlockInfo(10); ASSERT_NE(bi, nullptr); EXPECT_EQ(bi->succ_edge.count(99), 1); - EXPECT_EQ(bi->succ_edge[99], EdgeKind::kToMerge); + EXPECT_EQ(bi->succ_edge[99], EdgeKind::kSwitchBreak); } TEST_F(SpvParserTest, ClassifyCFGEdges_LoopBreak_FromLoopBody) {