Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

compiler: Suppress bs_context_to_binary/1 for a literal operand

The inliner can cause illegal uses of the bs_context_to_binary/1
instruction, such as:

  bs_context_to_binary {literal,"string"}

or

  bs_context_to_binary {integer,1}

Remove the bs_context_to_binary/1 instruction if the operand
is not a register (it is clearly not needed).
  • Loading branch information...
commit 57cb16f84fd21443d3ad9951473f1e0960c6a26e 1 parent e2074da
@bjorng bjorng authored
Showing with 10 additions and 1 deletion.
  1. +10 −1 lib/compiler/src/v3_codegen.erl
View
11 lib/compiler/src/v3_codegen.erl
@@ -1190,7 +1190,12 @@ trap_bif(_, _, _) -> false.
bif_cg(bs_context_to_binary=Instr, [Src0], [], Le, Vdb, Bef, St0) ->
[Src] = cg_reg_args([Src0], Bef),
- {[{Instr,Src}],clear_dead(Bef, Le#l.i, Vdb), St0};
+ case is_register(Src) of
+ false ->
+ {[],clear_dead(Bef, Le#l.i, Vdb), St0};
+ true ->
+ {[{Instr,Src}],clear_dead(Bef, Le#l.i, Vdb), St0}
+ end;
bif_cg(dsetelement, [Index0,Tuple0,New0], _Rs, Le, Vdb, Bef, St0) ->
[New,Tuple,{integer,Index1}] = cg_reg_args([New0,Tuple0,Index0], Bef),
Index = Index1-1,
@@ -2019,6 +2024,10 @@ fetch_stack(V, [_|Stk], I) -> fetch_stack(V, Stk, I+1).
on_stack(V, Stk) -> keymember(V, 1, Stk).
+is_register({x,_}) -> true;
+is_register({yy,_}) -> true;
+is_register(_) -> false.
+
%% put_catch(CatchTag, Stack) -> Stack'
%% drop_catch(CatchTag, Stack) -> Stack'
%% Special interface for putting and removing catch tags, to ensure that
Please sign in to comment.
Something went wrong with that request. Please try again.