aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler/test
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2016-05-23 08:40:23 +0200
committerBjörn Gustavsson <[email protected]>2016-05-23 08:40:23 +0200
commitd0554c760abc10f0c90348c8d3b63ca6110c6938 (patch)
tree06d2ce826e524951002883329291c1dfa9c6199f /lib/compiler/test
parentde114bb8523486c0174eb763b939fbdb34aa9421 (diff)
parent69dd6018b7731becda651393b837639746aa63c7 (diff)
downloadotp-d0554c760abc10f0c90348c8d3b63ca6110c6938.tar.gz
otp-d0554c760abc10f0c90348c8d3b63ca6110c6938.tar.bz2
otp-d0554c760abc10f0c90348c8d3b63ca6110c6938.zip
Merge branch 'bjorn/compiler/misc'
* bjorn/compiler/misc: beam_bool_SUITE: Cover one more line beam_utils_SUITE: Cover more lines in beam_utils beam_reorder: Don't confuse beam_validator beam_bool: Reject potentially unsafe optimization v3_core: Don't depend on sys_core_fold for cleaning up beam_type: Eliminate crash beam_type: Correct handling of setelement/3 beam_validator: Handle cons literals better beam_validator: Keep better track of tuple literals
Diffstat (limited to 'lib/compiler/test')
-rw-r--r--lib/compiler/test/beam_bool_SUITE.erl41
-rw-r--r--lib/compiler/test/beam_reorder_SUITE.erl16
-rw-r--r--lib/compiler/test/beam_type_SUITE.erl36
-rw-r--r--lib/compiler/test/beam_utils_SUITE.erl47
-rw-r--r--lib/compiler/test/match_SUITE.erl80
5 files changed, 199 insertions, 21 deletions
diff --git a/lib/compiler/test/beam_bool_SUITE.erl b/lib/compiler/test/beam_bool_SUITE.erl
index 84d634e5ca..e585eaedb5 100644
--- a/lib/compiler/test/beam_bool_SUITE.erl
+++ b/lib/compiler/test/beam_bool_SUITE.erl
@@ -22,7 +22,8 @@
-export([all/0,suite/0,groups/0,init_per_suite/1,end_per_suite/1,
init_per_group/2,end_per_group/2,
before_and_inside_if/1,
- scotland/1,y_registers/1]).
+ scotland/1,y_registers/1,protected/1,
+ maps/1]).
suite() ->
[{ct_hooks,[ts_install_cth]}].
@@ -35,7 +36,9 @@ groups() ->
[{p,[parallel],
[before_and_inside_if,
scotland,
- y_registers
+ y_registers,
+ protected,
+ maps
]}].
init_per_suite(Config) ->
@@ -158,3 +161,37 @@ potter(Modes) ->
_ -> not_ok
end,
{Final,Raw}.
+
+protected(_Config) ->
+ {'EXIT',{if_clause,_}} = (catch photographs({1, surprise, true}, opinions)),
+
+ {{true}} = welcome({perfect, true}),
+ {'EXIT',{if_clause,_}} = (catch welcome({perfect, false})),
+ ok.
+
+photographs({_Violation, surprise, Deep}, opinions) ->
+ {if
+ 0; "here", Deep ->
+ Deep = Deep
+ end}.
+
+welcome({perfect, Profit}) ->
+ if
+ Profit, Profit, Profit; 0 ->
+ {id({Profit})}
+ end.
+
+maps(_Config) ->
+ ok = evidence(#{0 => 42}).
+
+%% Cover handling of put_map in in split_block_label_used/2.
+evidence(#{0 := Charge}) when 0; #{[] => Charge} == #{[] => 42} ->
+ ok.
+
+
+%%%
+%%% Common utilities.
+%%%
+
+id(I) ->
+ I.
diff --git a/lib/compiler/test/beam_reorder_SUITE.erl b/lib/compiler/test/beam_reorder_SUITE.erl
index 4b2262f65b..ff31f2d3bd 100644
--- a/lib/compiler/test/beam_reorder_SUITE.erl
+++ b/lib/compiler/test/beam_reorder_SUITE.erl
@@ -21,7 +21,7 @@
-export([all/0,suite/0,groups/0,init_per_suite/1,end_per_suite/1,
init_per_group/2,end_per_group/2,
- alloc/1]).
+ alloc/1,confused_beam_validator/1]).
suite() -> [{ct_hooks,[ts_install_cth]}].
@@ -31,7 +31,8 @@ all() ->
groups() ->
[{p,[parallel],
- [alloc
+ [alloc,
+ confused_beam_validator
]}].
init_per_suite(Config) ->
@@ -65,5 +66,16 @@ alloc_b(_U1, _U2, R) ->
_ = id(0),
Res.
+confused_beam_validator(_Config) ->
+ {'EXIT',{{badmap,{any}},_}} = (catch efficient({any})),
+ ok.
+
+efficient({Var}=God) ->
+ id(God#{}),
+ catch
+ receive _ ->
+ Var
+ end.
+
id(I) ->
I.
diff --git a/lib/compiler/test/beam_type_SUITE.erl b/lib/compiler/test/beam_type_SUITE.erl
index 8d5c0190ed..69e2f1838d 100644
--- a/lib/compiler/test/beam_type_SUITE.erl
+++ b/lib/compiler/test/beam_type_SUITE.erl
@@ -21,7 +21,8 @@
-export([all/0,suite/0,groups/0,init_per_suite/1,end_per_suite/1,
init_per_group/2,end_per_group/2,
- integers/1,coverage/1,booleans/1]).
+ integers/1,coverage/1,booleans/1,setelement/1,cons/1,
+ tuple/1]).
suite() -> [{ct_hooks,[ts_install_cth]}].
@@ -33,7 +34,10 @@ groups() ->
[{p,[parallel],
[integers,
coverage,
- booleans
+ booleans,
+ setelement,
+ cons,
+ tuple
]}].
init_per_suite(Config) ->
@@ -55,6 +59,8 @@ integers(_Config) ->
a = do_integers_2(<<0:1>>),
{'EXIT',{{case_clause,-1},_}} = (catch do_integers_2(<<1:1>>)),
+ college = do_integers_3(),
+
ok.
do_integers_1(B0) ->
@@ -71,6 +77,12 @@ do_integers_2(Bin) ->
1 -> b
end.
+do_integers_3() ->
+ case try 0 after [] end of
+ 0 -> college;
+ 1 -> 0
+ end.
+
coverage(_Config) ->
{'EXIT',{badarith,_}} = (catch id(1) bsl 0.5),
{'EXIT',{badarith,_}} = (catch id(2.0) bsl 2),
@@ -94,5 +106,25 @@ do_booleans(B) ->
no -> no
end.
+setelement(_Config) ->
+ T0 = id({a,42}),
+ {a,_} = T0,
+ {b,_} = setelement(1, T0, b),
+ ok.
+
+cons(_Config) ->
+ [did] = cons(assigned, did),
+ ok.
+
+cons(assigned, Instrument) ->
+ [Instrument] = [did].
+
+tuple(_Config) ->
+ {'EXIT',{{badmatch,{necessary}},_}} = (catch do_tuple()),
+ ok.
+
+do_tuple() ->
+ {0, _} = {necessary}.
+
id(I) ->
I.
diff --git a/lib/compiler/test/beam_utils_SUITE.erl b/lib/compiler/test/beam_utils_SUITE.erl
index 6353ed3242..ae813d563b 100644
--- a/lib/compiler/test/beam_utils_SUITE.erl
+++ b/lib/compiler/test/beam_utils_SUITE.erl
@@ -23,7 +23,7 @@
init_per_group/2,end_per_group/2,
apply_fun/1,apply_mf/1,bs_init/1,bs_save/1,
is_not_killed/1,is_not_used_at/1,
- select/1,y_catch/1,otp_8949_b/1,liveopt/1]).
+ select/1,y_catch/1,otp_8949_b/1,liveopt/1,coverage/1]).
-export([id/1]).
suite() -> [{ct_hooks,[ts_install_cth]}].
@@ -43,7 +43,8 @@ groups() ->
select,
y_catch,
otp_8949_b,
- liveopt
+ liveopt,
+ coverage
]}].
init_per_suite(Config) ->
@@ -268,6 +269,48 @@ liveopt_fun(Peer, Cause, Origin) ->
void
end.
+%% Thanks to QuickCheck.
+coverage(_Config) ->
+ 42+7 = merchant([[],7,false]),
+
+ {'EXIT',{{try_clause,0},_}} = (catch resulting([0], stone)),
+ 0.0 = resulting([true], stone),
+
+ {'EXIT',{if_clause,_}} = (catch clinic(false)),
+ {'EXIT',{{try_clause,"trials"},_}} = (catch clinic(true)),
+
+ {'EXIT',{function_clause,_}} = (catch town(overall, {{abc},alcohol})),
+
+ ok.
+
+%% Cover check_liveness/3.
+merchant([Merchant, Laws, Electric]) ->
+ id(42),
+ oklahoma([[] || 0 <- Merchant],
+ if true; Electric -> Laws end) + 42.
+oklahoma([], Int) -> Int.
+
+town(overall, {{If}, Healing = alcohol})
+ when Healing#{[] => Healing}; include ->
+ [If || Healing <- awareness].
+
+%% Cover is_reg_used_at/3.
+resulting([Conservation], stone) ->
+ try 0 of
+ Conservation when Conservation -> Conservation;
+ _ when Conservation; 0 -> 0.0
+ after
+ Conservation
+ end.
+
+%% Cover is_reg_used_at_1/3.
+clinic(Damage) ->
+ if
+ Damage ->
+ try "trials" of Damage when Damage -> Damage catch true -> [] end
+ end,
+ carefully.
+
%% The identity function.
id(I) -> I.
diff --git a/lib/compiler/test/match_SUITE.erl b/lib/compiler/test/match_SUITE.erl
index 92a9802cad..31402ac717 100644
--- a/lib/compiler/test/match_SUITE.erl
+++ b/lib/compiler/test/match_SUITE.erl
@@ -21,8 +21,8 @@
-export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1,
init_per_group/2,end_per_group/2,
- pmatch/1,mixed/1,aliases/1,match_in_call/1,
- untuplify/1,shortcut_boolean/1,letify_guard/1,
+ pmatch/1,mixed/1,aliases/1,non_matching_aliases/1,
+ match_in_call/1,untuplify/1,shortcut_boolean/1,letify_guard/1,
selectify/1,underscore/1,match_map/1,map_vars_used/1,
coverage/1,grab_bag/1]).
@@ -36,7 +36,8 @@ all() ->
groups() ->
[{p,[parallel],
- [pmatch,mixed,aliases,match_in_call,untuplify,
+ [pmatch,mixed,aliases,non_matching_aliases,
+ match_in_call,untuplify,
shortcut_boolean,letify_guard,selectify,
underscore,match_map,map_vars_used,coverage,
grab_bag]}].
@@ -143,16 +144,6 @@ aliases(Config) when is_list(Config) ->
{a,b} = list_alias2([a,b]),
{a,b} = list_alias3([a,b]),
- %% Non-matching aliases.
- none = mixed_aliases(<<42>>),
- none = mixed_aliases([b]),
- none = mixed_aliases([d]),
- none = mixed_aliases({a,42}),
- none = mixed_aliases(42),
-
- %% Non-matching aliases.
- {'EXIT',{{badmatch,42},_}} = (catch nomatch_alias(42)),
-
ok.
str_alias(V) ->
@@ -256,6 +247,33 @@ list_alias2([X,Y]=[a,b]) ->
list_alias3([X,b]=[a,Y]) ->
{X,Y}.
+non_matching_aliases(_Config) ->
+ none = mixed_aliases(<<42>>),
+ none = mixed_aliases([b]),
+ none = mixed_aliases([d]),
+ none = mixed_aliases({a,42}),
+ none = mixed_aliases(42),
+
+ {'EXIT',{{badmatch,42},_}} = (catch nomatch_alias(42)),
+ {'EXIT',{{badmatch,job},_}} = (catch entirely()),
+ {'EXIT',{{badmatch,associates},_}} = (catch printer()),
+ {'EXIT',{{badmatch,borogoves},_}} = (catch tench()),
+
+ put(perch, 0),
+ {'EXIT',{{badmatch,{spine,42}},_}} = (catch perch(42)),
+ 1 = erase(perch),
+
+ put(salmon, 0),
+ {'EXIT',{{badmatch,mimsy},_}} = (catch salmon()),
+ 1 = erase(salmon),
+
+ put(shark, 0),
+ {'EXIT',{{badmatch,_},_}} = (catch shark()),
+ 1 = erase(shark),
+
+ {'EXIT',{{badmatch,_},_}} = (catch radio(research)),
+ ok.
+
mixed_aliases(<<X:8>> = x) -> {a,X};
mixed_aliases([b] = <<X:8>>) -> {b,X};
mixed_aliases(<<X:8>> = {a,X}) -> {c,X};
@@ -266,6 +284,42 @@ nomatch_alias(I) ->
{ok={A,B}} = id(I),
{A,B}.
+entirely() ->
+ 0(((Voice = true) = cool) = job),
+ [receive _ -> Voice end || banking <- printer].
+
+printer() ->
+ {[Indoor] = [] = associates},
+ [ireland || Indoor <- Indoor].
+
+tench() ->
+ E = begin
+ [A] = [] = borogoves,
+ A + 1
+ end,
+ E + 7 * A.
+
+perch(X) ->
+ begin
+ put(perch, get(perch)+1),
+ [A] = [] = {spine,X}
+ end.
+
+salmon() ->
+ {put(salmon, get(salmon)+1),#{key:=([A]=[])}=mimsy,exit(fail)},
+ A + 10.
+
+shark() ->
+ (hello = there) = (catch shark(put(shark, get(shark)+1), a = b)).
+
+shark(_, _) ->
+ ok.
+
+radio(research) ->
+ (connection = proof) =
+ (catch erlang:trace_pattern(catch mechanisms + assist,
+ summary = mechanisms)).
+
%% OTP-7018.
match_in_call(Config) when is_list(Config) ->