From 7d9dda27337271ee8cf0d85652c2f941f8a303d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Mon, 1 Aug 2022 12:06:34 +0200 Subject: [PATCH] Eliminate crash in beam_ssa_bool Fixes #6184 --- lib/compiler/src/beam_ssa_bool.erl | 6 +++++- lib/compiler/test/guard_SUITE.erl | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/compiler/src/beam_ssa_bool.erl b/lib/compiler/src/beam_ssa_bool.erl index 7a7209e1973e..fb72a78c29b6 100644 --- a/lib/compiler/src/beam_ssa_bool.erl +++ b/lib/compiler/src/beam_ssa_bool.erl @@ -435,7 +435,11 @@ pre_opt_terminator(#b_switch{arg=Arg0}=Sw0, Sub, Blocks) -> pre_opt_sw(#b_switch{arg=Arg,fail=Fail}=Sw, False, True, Sub, Blocks) -> case Sub of #{Arg:={true_or_any,PhiL}} -> - #{Fail:=FailBlk,False:=FalseBlk,PhiL:=PhiBlk} = Blocks, + #{Fail := FailBlk,False := FalseBlk} = Blocks, + PhiBlk = case Blocks of + #{PhiL := PhiBlk0} -> PhiBlk0; + #{} -> none + end, case {FailBlk,FalseBlk,PhiBlk} of {#b_blk{is=[],last=#b_br{succ=PhiL,fail=PhiL}}, #b_blk{is=[],last=#b_br{succ=PhiL,fail=PhiL}}, diff --git a/lib/compiler/test/guard_SUITE.erl b/lib/compiler/test/guard_SUITE.erl index 9664b4cbfd02..1a96fa4b6ca0 100644 --- a/lib/compiler/test/guard_SUITE.erl +++ b/lib/compiler/test/guard_SUITE.erl @@ -2548,6 +2548,7 @@ beam_bool_SUITE(_Config) -> beam_ssa_bool_coverage(), bad_map_in_guard(), gh_6164(), + gh_6184(), ok. before_and_inside_if() -> @@ -3076,6 +3077,16 @@ do_gh_6164(V1) -> end end. +gh_6184() -> + {'EXIT',{function_clause,_}} = catch do_gh_6184(id(true), id({a,b,c})), + {'EXIT',{function_clause,_}} = catch do_gh_6184(true, true), + {'EXIT',{function_clause,_}} = catch do_gh_6184({a,b,c}, {x,y,z}), + + ok. + +do_gh_6184(V1, V2) when (false and is_tuple(V2)) andalso (V1 orelse V2) -> + V2 orelse V2. + -record(bad_map_in_guard, {name}). bad_map_in_guard() -> error = bad_map_in_guard_1().