aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler/src/beam_validator.erl
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2011-12-05 09:22:12 +0100
committerBjörn Gustavsson <[email protected]>2011-12-06 13:22:18 +0100
commit1687a490039698fab6ccabdbbd61faa5d9d5eb41 (patch)
tree3f84ca91da1791e39fa42d944bd627f866c34ba9 /lib/compiler/src/beam_validator.erl
parent43a493df03174bc04d9a62edb4cff96943eebe35 (diff)
downloadotp-1687a490039698fab6ccabdbbd61faa5d9d5eb41.tar.gz
otp-1687a490039698fab6ccabdbbd61faa5d9d5eb41.tar.bz2
otp-1687a490039698fab6ccabdbbd61faa5d9d5eb41.zip
beam_validator: Fix type for failure label for bs_start_match2/5
A bs_start_match2/5 instruction will never fail (take the branch) if given a match state or a binary. Therefore, the type at the failure label should be 'term', not match state or binary. Without this correction, the beam_validator will reject safe programs.
Diffstat (limited to 'lib/compiler/src/beam_validator.erl')
-rw-r--r--lib/compiler/src/beam_validator.erl14
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/compiler/src/beam_validator.erl b/lib/compiler/src/beam_validator.erl
index fe3b1680d9..95f12df40d 100644
--- a/lib/compiler/src/beam_validator.erl
+++ b/lib/compiler/src/beam_validator.erl
@@ -670,10 +670,20 @@ valfun_4({get_tuple_element,Src,I,Dst}, Vst) ->
valfun_4({test,bs_start_match2,{f,Fail},Live,[Ctx,NeedSlots],Ctx}, Vst0) ->
%% If source and destination registers are the same, match state
%% is OK as input.
- _ = get_move_term_type(Ctx, Vst0),
+ CtxType = get_move_term_type(Ctx, Vst0),
verify_live(Live, Vst0),
Vst1 = prune_x_regs(Live, Vst0),
- Vst = branch_state(Fail, Vst1),
+ BranchVst = case CtxType of
+ {match_context,_,_} ->
+ %% The failure branch will never be taken when Ctx
+ %% is a match context. Therefore, the type for Ctx
+ %% at the failure label must not be match_context
+ %% (or we could reject legal code).
+ set_type_reg(term, Ctx, Vst1);
+ _ ->
+ Vst1
+ end,
+ Vst = branch_state(Fail, BranchVst),
set_type_reg(bsm_match_state(NeedSlots), Ctx, Vst);
valfun_4({test,bs_start_match2,{f,Fail},Live,[Src,Slots],Dst}, Vst0) ->
assert_term(Src, Vst0),