File 1932-compiler-Don-t-continue-alias-analysis-into-the-EXCE.patch of Package erlang

From cad6ffa8fecdcf7c4c856f01e12ce09d3696138d Mon Sep 17 00:00:00 2001
From: Frej Drejhammar <frej.drejhammar@gmail.com>
Date: Thu, 6 Jul 2023 13:19:37 +0200
Subject: [PATCH 2/6] compiler: Don't continue alias analysis into the
 EXCEPTION_BLOCK

Nothing happening in the exception block can propagate to the other
blocks as it has no successors.
---
 lib/compiler/src/beam_ssa_alias.erl | 10 ++++++++++
 lib/compiler/test/compile_SUITE.erl |  2 +-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/lib/compiler/src/beam_ssa_alias.erl b/lib/compiler/src/beam_ssa_alias.erl
index 9bcc3839a2..87d3a82ae8 100644
--- a/lib/compiler/src/beam_ssa_alias.erl
+++ b/lib/compiler/src/beam_ssa_alias.erl
@@ -407,6 +407,10 @@ aa_fun(F, #opt_st{ssa=Linear0,args=Args},
     AAS#aas{alias_map=AliasMap,repeats=Repeats}.
 
 %% Main entry point for the alias analysis
+aa_blocks([{?EXCEPTION_BLOCK,_}|Bs], Lbl2SS, AAS) ->
+    %% Nothing happening in the exception block can propagate to the
+    %% other block.
+    aa_blocks(Bs, Lbl2SS, AAS);
 aa_blocks([{L,#b_blk{is=Is0,last=T0}}|Bs0], Lbl2SS0, AAS0) ->
     #{L:=SS0} = Lbl2SS0,
     {SS1,AAS1} = aa_is(Is0, L, SS0, AAS0),
@@ -575,6 +579,8 @@ aa_set_block_exit_ss(ThisBlockLbl, SS, Lbl2SS) ->
     Lbl2SS#{ThisBlockLbl=>SS}.
 
 %% Extend the SS valid on entry to the blocks in the list with NewSS.
+aa_add_block_entry_ss([?EXCEPTION_BLOCK|BlockLabels], NewSS, Lbl2SS) ->
+    aa_add_block_entry_ss(BlockLabels, NewSS, Lbl2SS);
 aa_add_block_entry_ss([L|BlockLabels], NewSS, Lbl2SS) ->
     aa_add_block_entry_ss(BlockLabels, NewSS, aa_merge_ss(L, NewSS, Lbl2SS));
 aa_add_block_entry_ss([], _, Lbl2SS) ->
@@ -928,6 +934,10 @@ aa_update_fun_annotation(#opt_st{ssa=SSA0}=OptSt0, Lbl2SS0, AAS) ->
     {SSA,Lbl2SS} = aa_update_annotation_blocks(reverse(SSA0), [], Lbl2SS0, AAS),
     {OptSt0#opt_st{ssa=SSA},Lbl2SS}.
 
+aa_update_annotation_blocks([{?EXCEPTION_BLOCK,_}=Block|Blocks],
+                            Acc, Lbl2SS, AAS) ->
+    %% There is no point in touching the exception block.
+    aa_update_annotation_blocks(Blocks, [Block|Acc], Lbl2SS, AAS);
 aa_update_annotation_blocks([{Lbl, Block0}|Blocks], Acc, Lbl2SS0, AAS) ->
     Successors = beam_ssa:successors(Block0),
     Lbl2SS = foldl(fun(?EXCEPTION_BLOCK, Lbl2SSAcc) ->
diff --git a/lib/compiler/test/compile_SUITE.erl b/lib/compiler/test/compile_SUITE.erl
index c8d037ce7c..2c6f260618 100644
--- a/lib/compiler/test/compile_SUITE.erl
+++ b/lib/compiler/test/compile_SUITE.erl
@@ -2101,7 +2101,7 @@ annotations_pp(Config) when is_list(Config) ->
     10 = length(Uniques),
 
     Aliased = get_annotations("  %% Aliased:", Lines),
-    17 = length(Aliased),
+    13 = length(Aliased),
 
     ok = file:del_dir_r(TargetDir),
     ok.
-- 
2.35.3

openSUSE Build Service is sponsored by