File 2004-beam_jump-Don-t-share-catch-and-try-catch-blocks.patch of Package erlang

From df1f6ff388ad8264e281e158f6e144266b79b87a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org>
Date: Wed, 20 Nov 2019 15:27:45 +0100
Subject: [PATCH 1/2] beam_jump: Don't share catch and try/catch blocks

Sharing blocks that are inside a try/catch or catch does not
substantially reduce the code size, but can make the code more
difficult to understand for both HiPE and beam_validator.
---
 lib/compiler/src/beam_jump.erl | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/lib/compiler/src/beam_jump.erl b/lib/compiler/src/beam_jump.erl
index 0f9a2de190..e6e245419e 100644
--- a/lib/compiler/src/beam_jump.erl
+++ b/lib/compiler/src/beam_jump.erl
@@ -328,7 +328,12 @@ share(Is0) ->
 share_1([{label,L}=Lbl|Is], Dict0, Lbls0, [_|_]=Seq, Acc) ->
     case maps:find(Seq, Dict0) of
         error ->
-            Dict = maps:put(Seq, L, Dict0),
+            Dict = case is_shareable(Seq) of
+                       true ->
+                           maps:put(Seq, L, Dict0);
+                       false ->
+                           Dict0
+                   end,
             share_1(Is, Dict, Lbls0, [], [[Lbl|Seq]|Acc]);
         {ok,Label} ->
             Lbls = maps:put(L, Label, Lbls0),
@@ -363,6 +368,13 @@ share_1([I|Is], Dict, Lbls, Seq, Acc) ->
 	    share_1(Is, Dict, Lbls, [I], Acc)
     end.
 
+is_shareable([{'catch',_,_}|_]) -> false;
+is_shareable([{catch_end,_}|_]) -> false;
+is_shareable([{'try',_,_}|_]) -> false;
+is_shareable([{try_case,_}|_]) -> false;
+is_shareable([{try_end,_}|_]) -> false;
+is_shareable(_) -> true.
+
 clean_non_sharable(Dict0, Lbls0) ->
     %% We are passing in or out of a 'catch' or 'try' block. Remove
     %% sequences that should not be shared over the boundaries of the
-- 
2.16.4

openSUSE Build Service is sponsored by