<p dir="auto">Reduction from <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="341180436" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/28118" data-hovercard-type="pull_request" data-hovercard-url="/JuliaLang/julia/pull/28118/hovercard?comment_id=408327573&amp;comment_type=issue_comment" href="https://github.com/JuliaLang/julia/pull/28118#issuecomment-408327573">#28118 (comment)</a>. Note: Needs <code class="notranslate">julia -g</code> (or <code class="notranslate">julia-debug</code>) for reproduction to enable the verifier:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="julia&gt; function foo()
           try
           finally
               try
               catch ex
               end
           end
       end
foo (generic function with 1 method)

julia&gt; code_typed(foo, Tuple{})
Block 6 successors (Array{Int64, (2,)}[9, 7]), does not match fall-through terminator
ERROR: 
Stacktrace:
 [1] error() at ./error.jl:42
 [2] verify_ir(::Core.Compiler.IRCode) at ./compiler/ssair/verify.jl:110"><pre class="notranslate">julia<span class="pl-k">&gt;</span> <span class="pl-k">function</span> <span class="pl-en">foo</span>()
           <span class="pl-k">try</span>
           <span class="pl-k">finally</span>
               <span class="pl-k">try</span>
               <span class="pl-k">catch</span> ex
               <span class="pl-k">end</span>
           <span class="pl-k">end</span>
       <span class="pl-k">end</span>
foo (generic <span class="pl-k">function</span> with <span class="pl-c1">1</span> method)

julia<span class="pl-k">&gt;</span> <span class="pl-c1">code_typed</span>(foo, Tuple{})
Block <span class="pl-c1">6</span> successors (Array{Int64, (<span class="pl-c1">2</span>,)}[<span class="pl-c1">9</span>, <span class="pl-c1">7</span>]), does not match fall<span class="pl-k">-</span>through terminator
ERROR<span class="pl-k">:</span> 
Stacktrace<span class="pl-k">:</span>
 [<span class="pl-c1">1</span>] <span class="pl-c1">error</span>() at <span class="pl-k">./</span>error<span class="pl-k">.</span>jl<span class="pl-k">:</span><span class="pl-c1">42</span>
 [<span class="pl-c1">2</span>] <span class="pl-c1">verify_ir</span>(<span class="pl-k">::</span><span class="pl-c1">Core.Compiler.IRCode</span>) at <span class="pl-k">./</span>compiler<span class="pl-k">/</span>ssair<span class="pl-k">/</span>verify<span class="pl-k">.</span>jl<span class="pl-k">:</span><span class="pl-c1">110</span></pre></div>
<p dir="auto">The failing test is this:<br>
</p><div class="Box Box--condensed my-2">
  <div class="Box-header f6">
    <p class="mb-0 text-bold">
      <a href="https://github.com/JuliaLang/julia/blob/4b8c697be086c2830d66413f9c16eb50e0ecc45a/base/compiler/ssair/verify.jl#L108-L109">julia/base/compiler/ssair/verify.jl</a>
    </p>
    <p class="mb-0 color-fg-muted">
        Lines 108 to 109
      in
      <a data-pjax="true" class="commit-tease-sha" href="/JuliaLang/julia/commit/4b8c697be086c2830d66413f9c16eb50e0ecc45a">4b8c697</a>
    </p>
  </div>
  <div itemprop="text" class="Box-body p-0 blob-wrapper blob-wrapper-embedded data">
    <table class="highlight tab-size mb-0 js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">

        <tbody><tr class="border-0">
          <td id="L108" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="108"></td>
          <td id="LC108" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-k">if</span> <span class="pl-c1">length</span>(block<span class="pl-k">.</span>succs) <span class="pl-k">!=</span> <span class="pl-c1">1</span> <span class="pl-k">||</span> block<span class="pl-k">.</span>succs[<span class="pl-c1">1</span>] <span class="pl-k">!=</span> idx <span class="pl-k">+</span> <span class="pl-c1">1</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L109" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="109"></td>
          <td id="LC109" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">     <span class="pl-c1">@verify_error</span> <span class="pl-s"><span class="pl-pds">"</span>Block <span class="pl-v">$idx</span> successors (<span class="pl-v">$(block<span class="pl-k">.</span>succs)</span>), does not match fall-through terminator<span class="pl-pds">"</span></span> </td>
        </tr>
    </tbody></table>
  </div>
</div>
<p></p>
<p dir="auto">The IR looks like this:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="  1 ──       $(Expr(:enter, #4))
  2 ──       $(Expr(:leave, 1))
  3 ──       goto #6
  4 ──       $(Expr(:leave, 1))
  5 ── %5  = $(Expr(:the_exception))::Any
4 6 ┄─ %6  = φ (#3 =&gt; 1, #5 =&gt; 2)::Int64
  │    %7  = φ (#3 =&gt; false, #5 =&gt; true)::Bool
  │    %8  = φ (#3 =&gt; #undef, #5 =&gt; %5)::Core.Compiler.MaybeUndef(Any)
  │          $(Expr(:enter, #9))
  │    %10 = ϒ (%6)::Int64
  └─── %11 = ϒ (%8)::Any
  7 ──       $(Expr(:leave, 1))
  8 ──       goto #11
  9 ── %14 = φᶜ (%10)::Int64
  │    %15 = φᶜ (%11)::Any
  └───       $(Expr(:leave, 1))
  10 ─       nothing::Nothing
6 11 ┄ %18 = φ (#8 =&gt; %6, #10 =&gt; %14)::Int64
  │    %19 = φ (#8 =&gt; %7, #10 =&gt; true)::Bool
  │    %20 = φ (#8 =&gt; %8, #10 =&gt; %15)::Core.Compiler.MaybeUndef(Any)
  │    %21 = (%18 === 2)::Bool
  └───       goto #13 if not %21
  12 ─       $(Expr(:throw_undef_if_not, Symbol(&quot;#temp#&quot;), :(%19)))::Any
  │          $(Expr(:foreigncall, :(:jl_rethrow_other), Union{}, svec(Any), :(:ccall), 1, :(%20)))::Union{}
  └───       unreachable
  13 ─       return nothing"><pre class="notranslate">  <span class="pl-c1">1</span> ──       <span class="pl-k">$</span>(<span class="pl-c1">Expr</span>(<span class="pl-c1">:enter</span>, <span class="pl-c"><span class="pl-c">#</span>4))</span>
  <span class="pl-c1">2</span> ──       <span class="pl-k">$</span>(<span class="pl-c1">Expr</span>(<span class="pl-c1">:leave</span>, <span class="pl-c1">1</span>))
  <span class="pl-c1">3</span> ──       goto <span class="pl-c"><span class="pl-c">#</span>6</span>
  <span class="pl-c1">4</span> ──       <span class="pl-k">$</span>(<span class="pl-c1">Expr</span>(<span class="pl-c1">:leave</span>, <span class="pl-c1">1</span>))
  <span class="pl-c1">5</span> ── <span class="pl-k">%</span><span class="pl-c1">5</span>  <span class="pl-k">=</span> <span class="pl-k">$</span>(<span class="pl-c1">Expr</span>(<span class="pl-c1">:the_exception</span>))<span class="pl-k">::</span><span class="pl-c1">Any</span>
<span class="pl-c1">4</span> <span class="pl-c1">6</span> ┄─ <span class="pl-k">%</span><span class="pl-c1">6</span>  <span class="pl-k">=</span> φ (<span class="pl-c"><span class="pl-c">#</span>3 =&gt; 1, #5 =&gt; 2)::Int64</span>
  │    <span class="pl-k">%</span><span class="pl-c1">7</span>  <span class="pl-k">=</span> φ (<span class="pl-c"><span class="pl-c">#</span>3 =&gt; false, #5 =&gt; true)::Bool</span>
  │    <span class="pl-k">%</span><span class="pl-c1">8</span>  <span class="pl-k">=</span> φ (<span class="pl-c"><span class="pl-c">#</span>3 =&gt; #undef, #5 =&gt; %5)::Core.Compiler.MaybeUndef(Any)</span>
  │          <span class="pl-k">$</span>(<span class="pl-c1">Expr</span>(<span class="pl-c1">:enter</span>, <span class="pl-c"><span class="pl-c">#</span>9))</span>
  │    <span class="pl-k">%</span><span class="pl-c1">10</span> <span class="pl-k">=</span> ϒ (<span class="pl-k">%</span><span class="pl-c1">6</span>)<span class="pl-k">::</span><span class="pl-c1">Int64</span>
  └─── <span class="pl-k">%</span><span class="pl-c1">11</span> <span class="pl-k">=</span> ϒ (<span class="pl-k">%</span><span class="pl-c1">8</span>)<span class="pl-k">::</span><span class="pl-c1">Any</span>
  <span class="pl-c1">7</span> ──       <span class="pl-k">$</span>(<span class="pl-c1">Expr</span>(<span class="pl-c1">:leave</span>, <span class="pl-c1">1</span>))
  <span class="pl-c1">8</span> ──       goto <span class="pl-c"><span class="pl-c">#</span>11</span>
  <span class="pl-c1">9</span> ── <span class="pl-k">%</span><span class="pl-c1">14</span> <span class="pl-k">=</span> φᶜ (<span class="pl-k">%</span><span class="pl-c1">10</span>)<span class="pl-k">::</span><span class="pl-c1">Int64</span>
  │    <span class="pl-k">%</span><span class="pl-c1">15</span> <span class="pl-k">=</span> φᶜ (<span class="pl-k">%</span><span class="pl-c1">11</span>)<span class="pl-k">::</span><span class="pl-c1">Any</span>
  └───       <span class="pl-k">$</span>(<span class="pl-c1">Expr</span>(<span class="pl-c1">:leave</span>, <span class="pl-c1">1</span>))
  <span class="pl-c1">10</span> ─       <span class="pl-c1">nothing</span><span class="pl-k">::</span><span class="pl-c1">Nothing</span>
<span class="pl-c1">6</span> <span class="pl-c1">11</span> ┄ <span class="pl-k">%</span><span class="pl-c1">18</span> <span class="pl-k">=</span> φ (<span class="pl-c"><span class="pl-c">#</span>8 =&gt; %6, #10 =&gt; %14)::Int64</span>
  │    <span class="pl-k">%</span><span class="pl-c1">19</span> <span class="pl-k">=</span> φ (<span class="pl-c"><span class="pl-c">#</span>8 =&gt; %7, #10 =&gt; true)::Bool</span>
  │    <span class="pl-k">%</span><span class="pl-c1">20</span> <span class="pl-k">=</span> φ (<span class="pl-c"><span class="pl-c">#</span>8 =&gt; %8, #10 =&gt; %15)::Core.Compiler.MaybeUndef(Any)</span>
  │    <span class="pl-k">%</span><span class="pl-c1">21</span> <span class="pl-k">=</span> (<span class="pl-k">%</span><span class="pl-c1">18</span> <span class="pl-k">===</span> <span class="pl-c1">2</span>)<span class="pl-k">::</span><span class="pl-c1">Bool</span>
  └───       goto <span class="pl-c"><span class="pl-c">#</span>13 if not %21</span>
  <span class="pl-c1">12</span> ─       <span class="pl-k">$</span>(<span class="pl-c1">Expr</span>(<span class="pl-c1">:throw_undef_if_not</span>, <span class="pl-c1">Symbol</span>(<span class="pl-s"><span class="pl-pds">"</span>#temp#<span class="pl-pds">"</span></span>), :(<span class="pl-k">%</span><span class="pl-c1">19</span>)))<span class="pl-k">::</span><span class="pl-c1">Any</span>
  │          <span class="pl-k">$</span>(<span class="pl-c1">Expr</span>(<span class="pl-c1">:foreigncall</span>, :(<span class="pl-c1">:jl_rethrow_other</span>), Union{}, <span class="pl-c1">svec</span>(Any), :(<span class="pl-c1">:ccall</span>), <span class="pl-c1">1</span>, :(<span class="pl-k">%</span><span class="pl-c1">20</span>)))<span class="pl-k">::</span><span class="pl-c1">Union{}</span>
  └───       unreachable
  <span class="pl-c1">13</span> ─       <span class="pl-k">return</span> <span class="pl-c1">nothing</span></pre></div>
<p dir="auto">IIUC, the <code class="notranslate"> $(Expr(:enter, #9))</code> should terminate that block with these successors.</p>
<p dir="auto">Repro, build <code class="notranslate">julia-debug</code>. Run:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="julia&gt; try
       finally
           try
           catch
           end
       end
Block 6 successors (Array{Int64, (2,)}[9, 7]), does not match fall-through terminator
Internal error: encountered unexpected error in runtime:
MethodError(f=typeof(Base.string)(), args=(), world=0x0000000000000e78)
rec_backtrace at /Users/kristoffer/julia/src/stackwalk.c:94
record_backtrace at /Users/kristoffer/julia/src/task.c:246
jl_throw at /Users/kristoffer/julia/src/task.c:577
jl_method_error_bare at /Users/kristoffer/julia/src/gf.c:1597
jl_method_error at /Users/kristoffer/julia/src/gf.c:1615
jl_lookup_generic_ at /Users/kristoffer/julia/src/gf.c:2142
jl_apply_generic at /Users/kristoffer/julia/src/gf.c:2162
error at ./error.jl:42
jl_fptr_args at /Users/kristoffer/julia/src/gf.c:1822
jl_invoke at /Users/kristoffer/julia/src/gf.c:42
verify_ir at ./compiler/ssair/verify.jl:110
run_passes at ./compiler/ssair/driver.jl:132
optimize at ./compiler/optimize.jl:162
typeinf at ./compiler/typeinfer.jl:35
typeinf_ext at ./compiler/typeinfer.jl:611
jfptr_typeinf_ext_58 at /Users/kristoffer/julia/usr/lib/julia/sys-debug.dylib (unknown line)
jl_apply_generic at /Users/kristoffer/julia/src/gf.c:2165
jl_apply at /Users/kristoffer/julia/src/./julia.h:1538
jl_apply_with_saved_exception_state at /Users/kristoffer/julia/src/rtutils.c:257
jl_type_infer at /Users/kristoffer/julia/src/gf.c:275
jl_toplevel_eval_flex at /Users/kristoffer/julia/src/toplevel.c:822
jl_toplevel_eval at /Users/kristoffer/julia/src/toplevel.c:840
jl_toplevel_eval_in at /Users/kristoffer/julia/src/builtins.c:633
eval at ./boot.jl:319
jl_fptr_args at /Users/kristoffer/julia/src/gf.c:1822
jl_apply_generic at /Users/kristoffer/julia/src/gf.c:2165
eval_user_input at /Users/kristoffer/julia/usr/share/julia/stdlib/v0.7/REPL/src/REPL.jl:87
macro expansion at /Users/kristoffer/julia/usr/share/julia/stdlib/v0.7/REPL/src/REPL.jl:119 [inlined]
#28 at ./task.jl:262
jl_fptr_args at /Users/kristoffer/julia/src/gf.c:1822
jl_fptr_trampoline at /Users/kristoffer/julia/src/gf.c:1812
jl_apply_generic at /Users/kristoffer/julia/src/gf.c:2165
jl_apply at /Users/kristoffer/julia/src/./julia.h:1538
start_task at /Users/kristoffer/julia/src/task.c:268"><pre class="notranslate"><code class="notranslate">julia&gt; try
       finally
           try
           catch
           end
       end
Block 6 successors (Array{Int64, (2,)}[9, 7]), does not match fall-through terminator
Internal error: encountered unexpected error in runtime:
MethodError(f=typeof(Base.string)(), args=(), world=0x0000000000000e78)
rec_backtrace at /Users/kristoffer/julia/src/stackwalk.c:94
record_backtrace at /Users/kristoffer/julia/src/task.c:246
jl_throw at /Users/kristoffer/julia/src/task.c:577
jl_method_error_bare at /Users/kristoffer/julia/src/gf.c:1597
jl_method_error at /Users/kristoffer/julia/src/gf.c:1615
jl_lookup_generic_ at /Users/kristoffer/julia/src/gf.c:2142
jl_apply_generic at /Users/kristoffer/julia/src/gf.c:2162
error at ./error.jl:42
jl_fptr_args at /Users/kristoffer/julia/src/gf.c:1822
jl_invoke at /Users/kristoffer/julia/src/gf.c:42
verify_ir at ./compiler/ssair/verify.jl:110
run_passes at ./compiler/ssair/driver.jl:132
optimize at ./compiler/optimize.jl:162
typeinf at ./compiler/typeinfer.jl:35
typeinf_ext at ./compiler/typeinfer.jl:611
jfptr_typeinf_ext_58 at /Users/kristoffer/julia/usr/lib/julia/sys-debug.dylib (unknown line)
jl_apply_generic at /Users/kristoffer/julia/src/gf.c:2165
jl_apply at /Users/kristoffer/julia/src/./julia.h:1538
jl_apply_with_saved_exception_state at /Users/kristoffer/julia/src/rtutils.c:257
jl_type_infer at /Users/kristoffer/julia/src/gf.c:275
jl_toplevel_eval_flex at /Users/kristoffer/julia/src/toplevel.c:822
jl_toplevel_eval at /Users/kristoffer/julia/src/toplevel.c:840
jl_toplevel_eval_in at /Users/kristoffer/julia/src/builtins.c:633
eval at ./boot.jl:319
jl_fptr_args at /Users/kristoffer/julia/src/gf.c:1822
jl_apply_generic at /Users/kristoffer/julia/src/gf.c:2165
eval_user_input at /Users/kristoffer/julia/usr/share/julia/stdlib/v0.7/REPL/src/REPL.jl:87
macro expansion at /Users/kristoffer/julia/usr/share/julia/stdlib/v0.7/REPL/src/REPL.jl:119 [inlined]
#28 at ./task.jl:262
jl_fptr_args at /Users/kristoffer/julia/src/gf.c:1822
jl_fptr_trampoline at /Users/kristoffer/julia/src/gf.c:1812
jl_apply_generic at /Users/kristoffer/julia/src/gf.c:2165
jl_apply at /Users/kristoffer/julia/src/./julia.h:1538
start_task at /Users/kristoffer/julia/src/task.c:268
</code></pre></div>
<p dir="auto">Changing the <code class="notranslate">finally</code> to <code class="notranslate">catch</code>makes it go away.</p>