Skip to content

Commit

Permalink
Merge branch 'maint'
Browse files Browse the repository at this point in the history
* maint:
  Eliminate unsafe fusion of BEAM instructions
  • Loading branch information
bjorng committed Oct 4, 2024
2 parents 088d904 + 9e50cb3 commit 0c610c9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
4 changes: 2 additions & 2 deletions erts/emulator/beam/jit/arm/ops.tab
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,11 @@ current_tuple/1
current_tuple/2

is_tuple Fail=f Src | test_arity Fail2 Src2 Arity |
equal(Fail, Fail2) | equal(Src, Src) =>
equal(Fail, Fail2) | equal(Src, Src2) =>
i_is_tuple_of_arity Fail Src Arity | current_tuple Src

is_tuple Fail1=f Src | test_arity Fail2 Src2 Arity |
equal(Src, Src) =>
equal(Src, Src2) =>
i_is_tuple_of_arity_ff Fail1 Fail2 Src Arity | current_tuple Src

test_arity Fail Src Arity => i_test_arity Fail Src Arity | current_tuple Src
Expand Down
2 changes: 1 addition & 1 deletion erts/emulator/beam/jit/x86/ops.tab
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ is_tuple Fail=f Src | test_arity Fail2 Src2 Arity |
i_is_tuple_of_arity Fail Src Arity | current_tuple Src

is_tuple Fail1=f Src | test_arity Fail2 Src2 Arity |
equal(Src, Src) =>
equal(Src, Src2) =>
i_is_tuple_of_arity_ff Fail1 Fail2 Src Arity | current_tuple Src

test_arity Fail Src Arity => i_test_arity Fail Src Arity | current_tuple Src
Expand Down
38 changes: 36 additions & 2 deletions erts/emulator/test/tuple_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
t_append_element/1, t_append_element_upper_boundry/1,
build_and_match/1, tuple_with_case/1, tuple_in_guard/1,
get_two_tuple_elements/1,
record_update/1]).
record_update/1,
bad_tuple_match/1]).
-include_lib("common_test/include/ct.hrl").

%% Tests tuples and the BIFs:
Expand All @@ -51,7 +52,8 @@ all() ->
t_insert_element, t_delete_element,
tuple_with_case, tuple_in_guard,
get_two_tuple_elements,
record_update].
record_update,
bad_tuple_match].

groups() ->
[].
Expand Down Expand Up @@ -701,6 +703,38 @@ do_record_update_3(L, N, R0) ->
R
end.

%% GH-8875
bad_tuple_match(_Config) ->
ContentName = id(~"content-name"),
Content = id(#{ContentName => value}),

Find = case maps:find(ContentName, Content) of
{ok, _} -> {ok1, aa};
error -> ok
end,

Details = try id(good) of
good ->
{ok2, bb, cc}
catch
_:_ ->
{error, some_reason}
end,

%% Compiler optimizations will turn the following two lines into:
%%
%% {test,is_tuple,Fail1,[{y,0}]}
%% {test,test_arity,Fail2,[{x,0},3]}.
%%
%% The JIT would rewrite that to:
%%
%% {i_is_tuple_of_arity_ff,Fail1,Fail2,{y,0},3}
%%
%% That is unsafe because the source tuples are distinct.
{ok1, _} = Find,
{ok2, _, _} = Details,

ok.

%% Use this function to avoid compile-time evaluation of an expression.
id(I) -> I.
Expand Down

0 comments on commit 0c610c9

Please sign in to comment.