Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Björn Gustavsson bjorng authored

Showing 1 changed file with 10 additions and 1 deletion. Show diff stats Hide diff stats

  1. +10 1 lib/compiler/src/v3_codegen.erl
11 lib/compiler/src/v3_codegen.erl
@@ -1190,7 +1190,12 @@ trap_bif(_, _, _) -> false.
1190 1190
1191 1191 bif_cg(bs_context_to_binary=Instr, [Src0], [], Le, Vdb, Bef, St0) ->
1192 1192 [Src] = cg_reg_args([Src0], Bef),
1193   - {[{Instr,Src}],clear_dead(Bef, Le#l.i, Vdb), St0};
  1193 + case is_register(Src) of
  1194 + false ->
  1195 + {[],clear_dead(Bef, Le#l.i, Vdb), St0};
  1196 + true ->
  1197 + {[{Instr,Src}],clear_dead(Bef, Le#l.i, Vdb), St0}
  1198 + end;
1194 1199 bif_cg(dsetelement, [Index0,Tuple0,New0], _Rs, Le, Vdb, Bef, St0) ->
1195 1200 [New,Tuple,{integer,Index1}] = cg_reg_args([New0,Tuple0,Index0], Bef),
1196 1201 Index = Index1-1,
@@ -2019,6 +2024,10 @@ fetch_stack(V, [_|Stk], I) -> fetch_stack(V, Stk, I+1).
2019 2024
2020 2025 on_stack(V, Stk) -> keymember(V, 1, Stk).
2021 2026
  2027 +is_register({x,_}) -> true;
  2028 +is_register({yy,_}) -> true;
  2029 +is_register(_) -> false.
  2030 +
2022 2031 %% put_catch(CatchTag, Stack) -> Stack'
2023 2032 %% drop_catch(CatchTag, Stack) -> Stack'
2024 2033 %% Special interface for putting and removing catch tags, to ensure that

0 comments on commit 57cb16f

Please sign in to comment.
Something went wrong with that request. Please try again.