summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjörn Gustavsson <bjorn@erlang.org>2020-02-26 04:25:40 +0100
committerBjörn Gustavsson <bjorn@erlang.org>2020-02-26 04:28:26 +0100
commit00c15c32d915d9b7e7708de7965da3bf85feb204 (patch)
tree2d8197a6983027b097416446111f527c246c0bc7
parent55bc9c8f75d6bfff922d98768e689e721b229e6d (diff)
downloaderlang-00c15c32d915d9b7e7708de7965da3bf85feb204.tar.gz
Make sure that 'fail' in a guard makes the guard fail
https://bugs.erlang.org/browse/ERL-1183
-rw-r--r--lib/compiler/src/beam_ssa_bool.erl2
-rw-r--r--lib/compiler/test/guard_SUITE.erl17
2 files changed, 18 insertions, 1 deletions
diff --git a/lib/compiler/src/beam_ssa_bool.erl b/lib/compiler/src/beam_ssa_bool.erl
index 0b05d97064..0860029c59 100644
--- a/lib/compiler/src/beam_ssa_bool.erl
+++ b/lib/compiler/src/beam_ssa_bool.erl
@@ -237,7 +237,7 @@ get_phi_info_instr(#b_set{op=phi,dst=Dst,args=Args}, From, Sub0) ->
#{Dst:='=:='} ->
get_phi_info_single_use(Dst, Sub0);
#{Dst:={true_or_any,_}} ->
- {true,Sub0};
+ get_phi_info_single_use(Dst, Sub0);
#{} ->
{false,Sub0}
end,
diff --git a/lib/compiler/test/guard_SUITE.erl b/lib/compiler/test/guard_SUITE.erl
index 9f5f89288a..c039da93f0 100644
--- a/lib/compiler/test/guard_SUITE.erl
+++ b/lib/compiler/test/guard_SUITE.erl
@@ -2270,6 +2270,7 @@ beam_bool_SUITE(_Config) ->
wrong_order(),
megaco(),
looks_like_a_guard(),
+ fail_in_guard(),
ok.
before_and_inside_if() ->
@@ -2496,6 +2497,22 @@ looks_like_a_guard(N) ->
_ -> looks_like_a_guard(N)
end.
+fail_in_guard() ->
+ false = struct_or_map(a, "foo"),
+ false = struct_or_map(a, foo),
+ false = struct_or_map(#{}, "foo"),
+ true = struct_or_map(#{}, foo),
+ ok.
+
+%% ERL-1183. If Name is not an atom, the `fail` atom must cause the
+%% entire guard to fail.
+struct_or_map(Arg, Name) when
+ (is_map(Arg) andalso (is_atom(Name) orelse fail) andalso
+ is_map_key(struct, Arg)) orelse is_map(Arg) -> true;
+struct_or_map(_Arg, _Name) ->
+ false.
+
+
%%%
%%% End of beam_bool_SUITE tests.
%%%