aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler/test
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2011-12-29 15:28:32 +0100
committerBjörn Gustavsson <[email protected]>2012-01-11 08:39:56 +0100
commit68651be298a997a22224f53445688a74dc2fab7d (patch)
treec62acf8de66888109bcc09151ddefaa56fe7ec90 /lib/compiler/test
parent85f789f22ce07112be08354417b4179ee23427c7 (diff)
downloadotp-68651be298a997a22224f53445688a74dc2fab7d.tar.gz
otp-68651be298a997a22224f53445688a74dc2fab7d.tar.bz2
otp-68651be298a997a22224f53445688a74dc2fab7d.zip
sys_core_fold: Fix opt_guard_try/1
opt_guard_try/1 assumed that it was only operating on guards, and implicitly assumed that any function call was to BIFs without any side effects.
Diffstat (limited to 'lib/compiler/test')
-rw-r--r--lib/compiler/test/core_fold_SUITE.erl21
1 files changed, 19 insertions, 2 deletions
diff --git a/lib/compiler/test/core_fold_SUITE.erl b/lib/compiler/test/core_fold_SUITE.erl
index fb5ec88c9f..54bd52947e 100644
--- a/lib/compiler/test/core_fold_SUITE.erl
+++ b/lib/compiler/test/core_fold_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,
t_element/1,setelement/1,t_length/1,append/1,t_apply/1,bifs/1,
- eq/1,nested_call_in_case/1,coverage/1]).
+ eq/1,nested_call_in_case/1,guard_try_catch/1,coverage/1]).
-export([foo/0,foo/1,foo/2,foo/3]).
@@ -32,7 +32,7 @@ suite() -> [{ct_hooks,[ts_install_cth]}].
all() ->
test_lib:recompile(?MODULE),
[t_element, setelement, t_length, append, t_apply, bifs,
- eq, nested_call_in_case, coverage].
+ eq, nested_call_in_case, guard_try_catch, coverage].
groups() ->
[].
@@ -207,6 +207,23 @@ nested_call_in_case(Config) when is_list(Config) ->
?line {'EXIT',_} = (catch Mod:a(not_a_list, 42)),
ok.
+guard_try_catch(_Config) ->
+ false = do_guard_try_catch(key, value),
+ value = get(key),
+ ok.
+
+do_guard_try_catch(K, V) ->
+ %% This try...catch block looks like a guard.
+ %% Make sure that it is not optimized like a guard
+ %% (the put/2 call must not be optimized away).
+ try
+ put(K, V),
+ false
+ catch
+ _:_ ->
+ false
+ end.
+
coverage(Config) when is_list(Config) ->
?line {'EXIT',{{case_clause,{a,b,c}},_}} =
(catch cover_will_match_list_type({a,b,c})),