summaryrefslogtreecommitdiff
path: root/lib/compiler/src/beam_ssa_lint.erl
diff options
context:
space:
mode:
authorJohn Högberg <john@erlang.org>2019-08-07 14:00:09 +0200
committerJohn Högberg <john@erlang.org>2019-08-07 16:47:25 +0200
commit6ae9975689858d0e0c9af0a36869c012bb3762c0 (patch)
tree973ca6e2ad428001d6e3a0ce30fa18ef574b4933 /lib/compiler/src/beam_ssa_lint.erl
parentdb8a1822079b309075dd5be9fa1cb2019da2c61d (diff)
downloaderlang-6ae9975689858d0e0c9af0a36869c012bb3762c0.tar.gz
compiler: Fix awkward match context substitution
This worked out by accident since codegen never actually looks at the arguments for 'succeeded'; it just assumes that they reference the preceding instruction.
Diffstat (limited to 'lib/compiler/src/beam_ssa_lint.erl')
-rw-r--r--lib/compiler/src/beam_ssa_lint.erl20
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/compiler/src/beam_ssa_lint.erl b/lib/compiler/src/beam_ssa_lint.erl
index b2a8c1a0d1..224095d4c4 100644
--- a/lib/compiler/src/beam_ssa_lint.erl
+++ b/lib/compiler/src/beam_ssa_lint.erl
@@ -65,7 +65,13 @@ format_error({{_M,F,A},{phi_inside_block, Name, Id}}) ->
[F, A, format_var(Name), Id]);
format_error({{_M,F,A},{undefined_label_in_phi, Label, I}}) ->
io_lib:format("~p/~p: Unknown block label ~p in phi node ~ts",
- [F, A, Label, format_instr(I)]).
+ [F, A, Label, format_instr(I)]);
+format_error({{_M,F,A},{succeeded_not_preceded, I}}) ->
+ io_lib:format("~p/~p: ~ts does not reference the preceding instruction",
+ [F, A, format_instr(I)]);
+format_error({{_M,F,A},{succeeded_not_last, I}}) ->
+ io_lib:format("~p/~p: ~ts is not the last instruction in its block",
+ [F, A, format_instr(I)]).
format_instr(I) ->
[$',beam_ssa_pp:format_instr(I),$'].
@@ -229,6 +235,18 @@ vvars_block(Id, State0) ->
State :: #vvars{}.
vvars_block_1([], State) ->
State;
+vvars_block_1([#b_set{dst=OpVar,args=OpArgs}=I,
+ #b_set{op=succeeded,args=[OpVar],dst=SuccVar}], State) ->
+ ok = vvars_assert_args(OpArgs, I, State),
+ vvars_save_var(SuccVar, vvars_save_var(OpVar, State));
+vvars_block_1([#b_set{op=succeeded,args=Args}=I | [_|_]], State) ->
+ ok = vvars_assert_args(Args, I, State),
+ %% 'succeeded' must be the last instruction in its block.
+ throw({succeeded_not_last, I});
+vvars_block_1([#b_set{op=succeeded,args=Args}=I], State)->
+ ok = vvars_assert_args(Args, I, State),
+ %% 'succeeded' must be be directly preceded by the operation it checks.
+ throw({succeeded_not_preceded, I});
vvars_block_1([#b_set{ dst = Dst, op = phi } | Is], State) ->
%% We don't check phi node arguments at this point since we may not have
%% visited their definition yet. They'll be handled later on in