From a806b29cb9bb48c4a9628700946231c9150463b5 Mon Sep 17 00:00:00 2001
From: ReinUsesLisp <reinuseslisp@airmail.cc>
Date: Sat, 27 Mar 2021 02:54:32 -0300
Subject: shader: Fix structured control flow on KIL instructions

This could potentially leave unvisited blocks, leading to illegal phi
nodes.
---
 .../frontend/maxwell/structured_control_flow.cpp                 | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

(limited to 'src/shader_recompiler/frontend/maxwell/structured_control_flow.cpp')

diff --git a/src/shader_recompiler/frontend/maxwell/structured_control_flow.cpp b/src/shader_recompiler/frontend/maxwell/structured_control_flow.cpp
index 79e3449863..9d46883902 100644
--- a/src/shader_recompiler/frontend/maxwell/structured_control_flow.cpp
+++ b/src/shader_recompiler/frontend/maxwell/structured_control_flow.cpp
@@ -152,7 +152,9 @@ std::string DumpTree(const Tree& tree, u32 indentation = 0) {
     for (auto stmt = tree.begin(); stmt != tree.end(); ++stmt) {
         switch (stmt->type) {
         case StatementType::Code:
-            ret += fmt::format("{}    Block {:04x};\n", indent, stmt->code->LocationBegin());
+            ret += fmt::format("{}    Block {:04x} -> {:04x} (0x{:016x});\n", indent,
+                               stmt->code->LocationBegin(), stmt->code->LocationEnd(),
+                               reinterpret_cast<uintptr_t>(stmt->code));
             break;
         case StatementType::Goto:
             ret += fmt::format("{}    if ({}) goto L{};\n", indent, DumpExpr(stmt->cond),
@@ -749,8 +751,9 @@ private:
                     current_block = block_pool.Create(inst_pool);
                     block_list.push_back(current_block);
                 }
-                IR::IREmitter{*current_block}.DemoteToHelperInvocation(continue_block);
-                current_block = nullptr;
+                IR::Block* demote_block{MergeBlock(parent, stmt)};
+                IR::IREmitter{*current_block}.DemoteToHelperInvocation(demote_block);
+                current_block = demote_block;
                 break;
             }
             default:
-- 
cgit v1.2.3-70-g09d2