aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler/test/bs_match_SUITE.erl
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2012-11-25 05:59:34 +0100
committerBjörn Gustavsson <[email protected]>2012-11-26 14:01:02 +0100
commitc38a6726500cd726dd3e605b3be389ee96df131c (patch)
tree854ee2297cc393b03865a850234d40834291a6fc /lib/compiler/test/bs_match_SUITE.erl
parentdebb6589b998b37d02a52d55f12a2117b2dd0e38 (diff)
downloadotp-c38a6726500cd726dd3e605b3be389ee96df131c.tar.gz
otp-c38a6726500cd726dd3e605b3be389ee96df131c.tar.bz2
otp-c38a6726500cd726dd3e605b3be389ee96df131c.zip
beam_bsm: Improve handling of bs_start_match2 instructions
The handling of bs_start_match2 was both too conservative and too careless. It was too conservative in that would not do the optimization if the were copies of the match state in other registers. It was careless in that it did not consider the failure branch. Reorganize the code and fix both these issues. Add a test case to test that the failure branch is considered.
Diffstat (limited to 'lib/compiler/test/bs_match_SUITE.erl')
-rw-r--r--lib/compiler/test/bs_match_SUITE.erl30
1 files changed, 28 insertions, 2 deletions
diff --git a/lib/compiler/test/bs_match_SUITE.erl b/lib/compiler/test/bs_match_SUITE.erl
index e8f5c55c1a..d63d2235d7 100644
--- a/lib/compiler/test/bs_match_SUITE.erl
+++ b/lib/compiler/test/bs_match_SUITE.erl
@@ -33,7 +33,7 @@
matching_meets_construction/1,simon/1,matching_and_andalso/1,
otp_7188/1,otp_7233/1,otp_7240/1,otp_7498/1,
match_string/1,zero_width/1,bad_size/1,haystack/1,
- cover_beam_bool/1,matched_out_size/1]).
+ cover_beam_bool/1,matched_out_size/1,follow_fail_branch/1]).
-export([coverage_id/1,coverage_external_ignore/2]).
@@ -57,7 +57,7 @@ groups() ->
matching_meets_construction,simon,
matching_and_andalso,otp_7188,otp_7233,otp_7240,
otp_7498,match_string,zero_width,bad_size,haystack,
- cover_beam_bool,matched_out_size]}].
+ cover_beam_bool,matched_out_size,follow_fail_branch]}].
init_per_suite(Config) ->
@@ -1108,6 +1108,32 @@ mos_bin(<<L,Bin:L/binary,"abcdefghij">>) ->
L = byte_size(Bin),
Bin.
+follow_fail_branch(_) ->
+ 42 = ffb_1(<<0,1>>, <<0>>),
+ 8 = ffb_1(<<0,1>>, [a]),
+ 42 = ffb_2(<<0,1>>, <<0>>, 17),
+ 8 = ffb_2(<<0,1>>, [a], 0),
+ ok.
+
+ffb_1(<<_,T/bitstring>>, List) ->
+ case List of
+ <<_>> ->
+ 42;
+ [_|_] ->
+ %% The fail branch of the bs_start_match2 instruction
+ %% pointing to here would be ignored, making the compiler
+ %% incorrectly assume that the delayed sub-binary
+ %% optimization was safe.
+ bit_size(T)
+ end.
+
+ffb_2(<<_,T/bitstring>>, List, A) ->
+ case List of
+ <<_>> when A =:= 17 -> 42;
+ [_|_] -> bit_size(T)
+ end.
+
+
check(F, R) ->
R = F().