From 9b41d4f1a56369d1a2b3c8a156329668d4163a23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Thu, 7 Nov 2024 06:01:04 +0100 Subject: [PATCH] Only convert "safe" BIFs to guard BIFs in try/catch --- lib/compiler/src/beam_ssa_opt.erl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/compiler/src/beam_ssa_opt.erl b/lib/compiler/src/beam_ssa_opt.erl index 6bdb57be8126..5c36a792b908 100644 --- a/lib/compiler/src/beam_ssa_opt.erl +++ b/lib/compiler/src/beam_ssa_opt.erl @@ -1895,7 +1895,7 @@ reduce_try_is([#b_set{op={succeeded,body}}=I0|Is], Acc) -> reduce_try_is(Is, [I|Acc]); reduce_try_is([#b_set{op=call,args=[#b_remote{mod=#b_literal{val=M}, name=#b_literal{val=F},arity=A}|Args]}=I0|Is], Acc) -> - case erl_bifs:is_pure(M, F, A) of + case is_safe_as_guard_bif(M, F, A) of true -> I = I0#b_set{op={bif,F},args=Args}, reduce_try_is(Is, [I|Acc]); @@ -1913,6 +1913,12 @@ reduce_try_is([#b_set{op=Op}=I|Is], Acc) -> reduce_try_is([], Acc) -> {safe,reverse(Acc)}. +is_safe_as_guard_bif(erlang, binary_to_atom, 1) -> true; +is_safe_as_guard_bif(erlang, binary_to_existing_atom, 1) -> true; +is_safe_as_guard_bif(erlang, list_to_atom, 1) -> true; +is_safe_as_guard_bif(erlang, list_to_existing_atom, 1) -> true; +is_safe_as_guard_bif(_, _, _) -> false. + %% Removes try/catch expressions whose expressions will never throw. %% %% We walk backwards through all blocks, maintaining a set of potentially