aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2018-04-25 07:41:49 +0200
committerBjörn Gustavsson <[email protected]>2018-04-25 10:38:59 +0200
commit6703828ea9085a4125812cfa47631d061032c514 (patch)
treedad6d32955220f75fd9af17ea51c7727d4a7f4e0 /lib/compiler
parent381ab6129998cbd43216eaafabf7cef78c879c5d (diff)
downloadotp-6703828ea9085a4125812cfa47631d061032c514.tar.gz
otp-6703828ea9085a4125812cfa47631d061032c514.tar.bz2
otp-6703828ea9085a4125812cfa47631d061032c514.zip
sys_core_fold: Eliminate crash for map update in guard
sys_core_fold would crash when attempting to optimize this code: t() when (#{})#{}-> c.
Diffstat (limited to 'lib/compiler')
-rw-r--r--lib/compiler/src/sys_core_fold.erl2
-rw-r--r--lib/compiler/test/core_fold_SUITE.erl18
2 files changed, 18 insertions, 2 deletions
diff --git a/lib/compiler/src/sys_core_fold.erl b/lib/compiler/src/sys_core_fold.erl
index bb3a9c7628..167383a202 100644
--- a/lib/compiler/src/sys_core_fold.erl
+++ b/lib/compiler/src/sys_core_fold.erl
@@ -214,6 +214,8 @@ opt_guard_try(#c_case{clauses=Cs}=Term) ->
Term#c_case{clauses=opt_guard_try_list(Cs)};
opt_guard_try(#c_clause{body=B0}=Term) ->
Term#c_clause{body=opt_guard_try(B0)};
+opt_guard_try(#c_let{vars=[],arg=#c_values{es=[]},body=B}) ->
+ B;
opt_guard_try(#c_let{arg=Arg,body=B0}=Term) ->
case opt_guard_try(B0) of
#c_literal{}=B ->
diff --git a/lib/compiler/test/core_fold_SUITE.erl b/lib/compiler/test/core_fold_SUITE.erl
index 4fd1f84569..ab7f36abf7 100644
--- a/lib/compiler/test/core_fold_SUITE.erl
+++ b/lib/compiler/test/core_fold_SUITE.erl
@@ -27,7 +27,8 @@
multiple_aliases/1,redundant_boolean_clauses/1,
mixed_matching_clauses/1,unnecessary_building/1,
no_no_file/1,configuration/1,supplies/1,
- redundant_stack_frame/1,export_from_case/1]).
+ redundant_stack_frame/1,export_from_case/1,
+ empty_values/1]).
-export([foo/0,foo/1,foo/2,foo/3]).
@@ -47,7 +48,8 @@ groups() ->
multiple_aliases,redundant_boolean_clauses,
mixed_matching_clauses,unnecessary_building,
no_no_file,configuration,supplies,
- redundant_stack_frame,export_from_case]}].
+ redundant_stack_frame,export_from_case,
+ empty_values]}].
init_per_suite(Config) ->
@@ -584,5 +586,17 @@ export_from_case_2(Bool, Rec) ->
end,
{ok,Result}.
+empty_values(_Config) ->
+ case ?MODULE of
+ core_fold_inline_SUITE ->
+ {'EXIT',_} = (catch do_empty_values());
+ _ ->
+ {'EXIT',{function_clause,_}} = (catch do_empty_values())
+ end,
+ ok.
+
+do_empty_values() when (#{})#{} ->
+ c.
+
id(I) -> I.