From 9e35ded770b0af14d2054a60f18bacc5221c9a5b Mon Sep 17 00:00:00 2001
From: Simeon Schaub <simeondavidschaub99@gmail.com>
Date: Sun, 28 Mar 2021 06:42:48 +0200
Subject: [PATCH] fix IRCode show_ir with verbose linetable (#40240)

fix block number printing with verbose linfo
---
 base/compiler/ssair/show.jl | 5 +++--
 test/show.jl                | 6 ++++++
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/base/compiler/ssair/show.jl b/base/compiler/ssair/show.jl
index c1f4e0f25f5065..851cc46def6ea1 100644
--- a/base/compiler/ssair/show.jl
+++ b/base/compiler/ssair/show.jl
@@ -555,6 +555,7 @@ function show_ir(io::IO, code::IRCode, expr_type_printer=default_expr_type_print
         else
             bb_guard_rail = bb_guard_rail_cont
         end
+        floop = true
         # Print linetable information
         if verbose_linetable
             stack = compute_loc_stack(code.linetable, stmt[:line])
@@ -568,10 +569,11 @@ function show_ir(io::IO, code::IRCode, expr_type_printer=default_expr_type_print
                     printstyled(io, "\e[$(start_column)G$(rail)\e[1G", color = :light_black)
                     print(io, bb_guard_rail)
                     ssa_guard = " "^(maxlength_idx + 4 + (i - 1))
-                    entry_label = "$(ssa_guard)$(method_name(entry)) at $(entry.file):$(entry[:line]) "
+                    entry_label = "$(ssa_guard)$(method_name(entry)) at $(entry.file):$(entry.line) "
                     hline = string("─"^(start_column-length(entry_label)-length(bb_guard_rail)+max_depth-i), "┐")
                     printstyled(io, string(entry_label, hline), "\n"; color=:light_black)
                     bb_guard_rail = bb_guard_rail_cont
+                    floop = false
                 end
             end
             printstyled(io, "\e[$(start_column)G$(rail)\e[1G", color = :light_black)
@@ -602,7 +604,6 @@ function show_ir(io::IO, code::IRCode, expr_type_printer=default_expr_type_print
         if idx == last(bbrange)
             print_sep = true
         end
-        floop = true
         # print new nodes first in the right position
         while perm_idx <= length(new_nodes_perm)
             node_idx = new_nodes_perm[perm_idx]
diff --git a/test/show.jl b/test/show.jl
index c2db37493ab05e..51e6abca85f9bb 100644
--- a/test/show.jl
+++ b/test/show.jl
@@ -1890,6 +1890,12 @@ let src = code_typed(my_fun28173, (Int,), debuginfo=:source)[1][1]
     @test pop!(lines2) == "   │          \$(QuoteNode(4))"
     @test pop!(lines2) == "17 │          \$(QuoteNode(3))" # TODO: this should print after the next statement
     @test lines1 == lines2
+
+    # verbose linetable
+    io = IOBuffer()
+    Base.IRShow.show_ir(io, ir; verbose_linetable=true)
+    seekstart(io)
+    @test count(contains(r"my_fun28173 at none:\d+"), eachline(io)) == 9
 end
 
 # Verify that extra instructions at the end of the IR