diff options
author | Björn Gustavsson <[email protected]> | 2016-02-10 12:34:55 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2016-02-10 12:34:55 +0100 |
commit | 3fd58861e8e42140f93e3f1fb5d5113902a47227 (patch) | |
tree | f687d9c6c9ea05e82a24b6412c13627f25414a26 /lib/compiler | |
parent | 505a69774fe789bbf7c264574f360c683dd0fcc3 (diff) | |
parent | 47c2ace2a036bbc5da7950aa8c59bc78b4e498e1 (diff) | |
download | otp-3fd58861e8e42140f93e3f1fb5d5113902a47227.tar.gz otp-3fd58861e8e42140f93e3f1fb5d5113902a47227.tar.bz2 otp-3fd58861e8e42140f93e3f1fb5d5113902a47227.zip |
Merge branch 'maint'
* maint:
Eliminate crash because of unsafe delaying of sub-binary creation
Diffstat (limited to 'lib/compiler')
-rw-r--r-- | lib/compiler/src/beam_bsm.erl | 5 | ||||
-rw-r--r-- | lib/compiler/test/bs_match_SUITE.erl | 30 |
2 files changed, 31 insertions, 4 deletions
diff --git a/lib/compiler/src/beam_bsm.erl b/lib/compiler/src/beam_bsm.erl index 4f76350269..62356928ae 100644 --- a/lib/compiler/src/beam_bsm.erl +++ b/lib/compiler/src/beam_bsm.erl @@ -421,7 +421,8 @@ btb_follow_branches([], _, D) -> D. btb_follow_branch(0, _Regs, D) -> D; btb_follow_branch(Lbl, Regs, #btb{ok_br=Br0,index=Li}=D) -> - case gb_sets:is_member(Lbl, Br0) of + Key = {Lbl,Regs}, + case gb_sets:is_member(Key, Br0) of true -> %% We have already followed this branch and it was OK. D; @@ -432,7 +433,7 @@ btb_follow_branch(Lbl, Regs, #btb{ok_br=Br0,index=Li}=D) -> btb_reaches_match_1(Is, Regs, D), %% Since we got back, this branch is OK. - D#btb{ok_br=gb_sets:insert(Lbl, Br),must_not_save=MustNotSave, + D#btb{ok_br=gb_sets:insert(Key, Br),must_not_save=MustNotSave, must_save=MustSave} end. diff --git a/lib/compiler/test/bs_match_SUITE.erl b/lib/compiler/test/bs_match_SUITE.erl index 667c6754ee..8725e133fa 100644 --- a/lib/compiler/test/bs_match_SUITE.erl +++ b/lib/compiler/test/bs_match_SUITE.erl @@ -37,7 +37,7 @@ cover_beam_bool/1,matched_out_size/1,follow_fail_branch/1, no_partition/1,calling_a_binary/1,binary_in_map/1, match_string_opt/1,select_on_integer/1, - map_and_binary/1]). + map_and_binary/1,unsafe_branch_caching/1]). -export([coverage_id/1,coverage_external_ignore/2]). @@ -64,7 +64,7 @@ groups() -> cover_beam_bool,matched_out_size,follow_fail_branch, no_partition,calling_a_binary,binary_in_map, match_string_opt,select_on_integer, - map_and_binary]}]. + map_and_binary,unsafe_branch_caching]}]. init_per_suite(Config) -> @@ -1267,6 +1267,32 @@ do_map_and_binary(#{time := _} = T) -> do_map_and_binary(#{hour := Hour, min := Min} = T) -> {Hour, Min, T}. +%% Unsafe caching of branch outcomes in beam_bsm would cause the +%% delayed creation of sub-binaries optimization to be applied even +%% when it was unsafe. + +unsafe_branch_caching(_Config) -> + <<>> = do_unsafe_branch_caching(<<42,1>>), + <<>> = do_unsafe_branch_caching(<<42,2>>), + <<>> = do_unsafe_branch_caching(<<42,3>>), + <<17,18>> = do_unsafe_branch_caching(<<42,3,17,18>>), + <<>> = do_unsafe_branch_caching(<<1,3,42,2>>), + + ok. + +do_unsafe_branch_caching(<<Code/integer, Bin/binary>>) -> + <<C1/integer, B1/binary>> = Bin, + case C1 of + X when X =:= 1 orelse X =:= 2 -> + Bin2 = <<>>; + _ -> + Bin2 = B1 + end, + case Code of + 1 -> do_unsafe_branch_caching(Bin2); + _ -> Bin2 + end. + check(F, R) -> R = F(). |