diff options
author | Björn Gustavsson <[email protected]> | 2016-09-26 15:01:19 +0200 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2016-10-05 13:00:45 +0200 |
commit | 0c599bcad1e7f5f66dd2342ab27791048145e892 (patch) | |
tree | 2f9702b3f3c829d6862df0cc193d5abc394251b4 /lib/compiler/test/beam_block_SUITE.erl | |
parent | 3f3f25b23379b1afb15cc97462cf5d385690f5a0 (diff) | |
download | otp-0c599bcad1e7f5f66dd2342ab27791048145e892.tar.gz otp-0c599bcad1e7f5f66dd2342ab27791048145e892.tar.bz2 otp-0c599bcad1e7f5f66dd2342ab27791048145e892.zip |
beam_block: Avoid unsafe inclusion of get_map_elements in blocks
c2035ebb8b restricted the get_map_elements instruction so that it
could only occur at the beginning of a block. It turns out that
including it anywhere in a block is unsafe.
Therefore, never put get_map_elements instruction in blocks.
(Also remove the beam_utils:join_even/2 function since it is no
longer used.)
ERL-266
Diffstat (limited to 'lib/compiler/test/beam_block_SUITE.erl')
-rw-r--r-- | lib/compiler/test/beam_block_SUITE.erl | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/lib/compiler/test/beam_block_SUITE.erl b/lib/compiler/test/beam_block_SUITE.erl index 9fcb6e497d..55d5f2dbe8 100644 --- a/lib/compiler/test/beam_block_SUITE.erl +++ b/lib/compiler/test/beam_block_SUITE.erl @@ -22,7 +22,7 @@ -export([all/0,suite/0,groups/0,init_per_suite/1,end_per_suite/1, init_per_group/2,end_per_group/2, get_map_elements/1,otp_7345/1,move_opt_across_gc_bif/1, - erl_202/1]). + erl_202/1,repro/1]). %% The only test for the following functions is that %% the code compiles and is accepted by beam_validator. @@ -39,7 +39,8 @@ groups() -> [get_map_elements, otp_7345, move_opt_across_gc_bif, - erl_202 + erl_202, + repro ]}]. init_per_suite(Config) -> @@ -158,6 +159,27 @@ erl_202({{_, _},X}, _) -> erl_202({_, _}, #erl_202_r1{y=R2}) -> {R2#erl_202_r2.x}. +%% See https://bugs.erlang.org/browse/ERL-266. +%% Instructions with failure labels are not safe to include +%% in a block. Including get_map_elements in a block would +%% lead to unsafe code. + +repro(_Config) -> + [] = maps:to_list(repro([], #{}, #{})), + [{tmp1,n}] = maps:to_list(repro([{tmp1,0}], #{}, #{})), + [{tmp1,name}] = maps:to_list(repro([{tmp1,0}], #{}, #{0=>name})), + ok. + +repro([], TempNames, _Slots) -> + TempNames; +repro([{Temp, Slot}|Xs], TempNames, Slots0) -> + {Name, Slots} = + case Slots0 of + #{Slot := Name0} -> {Name0, Slots0}; + #{} -> {n, Slots0#{Slot => n}} + end, + repro(Xs, TempNames#{Temp => Name}, Slots). + %%% %%% The only test of the following code is that it compiles. %%% |