From 68651be298a997a22224f53445688a74dc2fab7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Thu, 29 Dec 2011 15:28:32 +0100 Subject: 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. --- lib/compiler/test/core_fold_SUITE.erl | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'lib/compiler/test') 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})), -- cgit v1.2.3