From 6adc50b534d0db2be2e0bf5c4029cf22e45a84a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20H=C3=B6gberg?= Date: Thu, 24 Jan 2019 13:21:41 +0100 Subject: beam_trim: Ignore type annotations The type annotations inserted by beam_ssa_type and beam_ssa_bsm would inadvertently disable stack trimming, as unknown instructions are considered unsafe. --- lib/compiler/src/beam_trim.erl | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib') diff --git a/lib/compiler/src/beam_trim.erl b/lib/compiler/src/beam_trim.erl index 51ff580a7a..acf3838da4 100644 --- a/lib/compiler/src/beam_trim.erl +++ b/lib/compiler/src/beam_trim.erl @@ -200,6 +200,8 @@ create_map(Trim, Moves) -> (Any) -> Any end. +remap([{'%',_}=I|Is], Map, Acc) -> + remap(Is, Map, [I|Acc]); remap([{block,Bl0}|Is], Map, Acc) -> Bl = remap_block(Bl0, Map, []), remap(Is, Map, [{block,Bl}|Acc]); @@ -279,6 +281,8 @@ safe_labels([_|Is], Acc) -> safe_labels(Is, Acc); safe_labels([], Acc) -> cerl_sets:from_list(Acc). +is_safe_label([{'%',_}|Is]) -> + is_safe_label(Is); is_safe_label([{line,_}|Is]) -> is_safe_label(Is); is_safe_label([{badmatch,{Tag,_}}|_]) -> @@ -337,6 +341,8 @@ frame_layout_2(Is) -> reverse(Is). %% to safe labels (i.e., the code at those labels don't depend %% on the contents of any Y register). +frame_size([{'%',_}|Is], Safe) -> + frame_size(Is, Safe); frame_size([{block,_}|Is], Safe) -> frame_size(Is, Safe); frame_size([{call_fun,_}|Is], Safe) -> @@ -393,6 +399,8 @@ frame_size_branch(L, Is, Safe) -> %% This function handles the same instructions as frame_size/2. It %% assumes that any labels in the instructions are safe labels. +is_not_used(Y, [{'%',_}|Is]) -> + is_not_used(Y, Is); is_not_used(Y, [{apply,_}|Is]) -> is_not_used(Y, Is); is_not_used(Y, [{bif,_,{f,_},Ss,Dst}|Is]) -> -- cgit v1.2.3