From e20015186fa2372793650a98005faf88e6f6e0fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20H=C3=B6gberg?= Date: Mon, 8 Jul 2019 14:37:50 +0200 Subject: compiler: Fix broken 'receive' in try/catch blocks This fix is rather ugly and tacked-on, but I'm not comfortable refactoring the pass in an emergency patch. --- lib/compiler/test/beam_ssa_SUITE.erl | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'lib/compiler/test/beam_ssa_SUITE.erl') diff --git a/lib/compiler/test/beam_ssa_SUITE.erl b/lib/compiler/test/beam_ssa_SUITE.erl index a741ebbdf9..256bb95559 100644 --- a/lib/compiler/test/beam_ssa_SUITE.erl +++ b/lib/compiler/test/beam_ssa_SUITE.erl @@ -190,6 +190,12 @@ recv(_Config) -> self() ! {[self(),r1],{2,99,<<"data">>}}, {Parent,r1,<<1:32,2:8,99:8,"data">>} = tricky_recv_4(), + %% Test tricky_recv_5/0. + self() ! 1, + a = tricky_recv_5(), + self() ! 2, + b = tricky_recv_5(), + ok. sync_wait_mon({Pid, Ref}, Timeout) -> @@ -295,6 +301,26 @@ tricky_recv_4() -> end, id({Pid,R,Request}). +%% beam_ssa_pre_codegen would accidentally create phi nodes on critical edges +%% when fixing up receives; the call to id/2 can either succeed or land in the +%% catch block, and we added a phi node to its immediate successor. +tricky_recv_5() -> + try + receive + X=1 -> + id(42), + a; + X=2 -> + b + end, + case X of + 1 -> a; + 2 -> b + end + catch + _:_ -> c + end. + maps(_Config) -> {'EXIT',{{badmatch,#{}},_}} = (catch maps_1(any)), ok. -- cgit v1.2.3