File 0560-Eliminate-crash-in-sub-pass-ssa_opt_bc_size.patch of Package erlang

From fac1f717f534f6fc15f97cb03611eb032dd48b28 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org>
Date: Tue, 15 Nov 2022 07:26:26 +0100
Subject: [PATCH] Eliminate crash in sub pass ssa_opt_bc_size

Closes #6468
---
 lib/compiler/src/beam_ssa_bc_size.erl  |  2 ++
 lib/compiler/test/bs_bincomp_SUITE.erl | 35 ++++++++++++++++++++++++++
 2 files changed, 37 insertions(+)

diff --git a/lib/compiler/src/beam_ssa_bc_size.erl b/lib/compiler/src/beam_ssa_bc_size.erl
index a93fe8f2f3..5e9b1486a2 100644
--- a/lib/compiler/src/beam_ssa_bc_size.erl
+++ b/lib/compiler/src/beam_ssa_bc_size.erl
@@ -239,6 +239,8 @@ update_successors(#b_br{bool=Bool,succ=Succ,fail=Fail}, Bs0, Map0) ->
     case get_value(Bool, Bs0) of
         #b_literal{val=true} ->
             update_successor(Succ, Bs0, Map0);
+        #b_literal{val=false} ->
+            update_successor(Fail, Bs0, Map0);
         {succeeded,Var} ->
             Map = update_successor(Succ, Bs0, Map0),
             update_successor(Fail, maps:remove(Var, Bs0), Map);
diff --git a/lib/compiler/test/bs_bincomp_SUITE.erl b/lib/compiler/test/bs_bincomp_SUITE.erl
index 488cebf661..9ddb387836 100644
--- a/lib/compiler/test/bs_bincomp_SUITE.erl
+++ b/lib/compiler/test/bs_bincomp_SUITE.erl
@@ -173,6 +173,13 @@ mixed(Config) when is_list(Config) ->
     <<255>> = over_complex_generator(),
     {'EXIT',_} = catch float_segment_size(),
 
+    <<>> = inconsistent_types_1([]),
+    {'EXIT',{{bad_generator,42},_}} = catch inconsistent_types_1(42),
+    Self = self(),
+    {'EXIT',{{bad_generator,Self},_}} = catch inconsistent_types_1(Self),
+
+    {'EXIT',{{bad_filter,<<>>},_}} = catch inconsistent_types_2(),
+
     cs_end().
 
 mixed_nested(L) ->
@@ -244,6 +251,34 @@ float_segment_size() ->
             error
     end.
 
+%% GH-6468. Would crash in beam_ssa_bc_size:update_successors/3.
+inconsistent_types_1(X) ->
+    <<
+      X || _ <- X,
+           case is_pid(X) of
+               Y ->
+                   (#{
+                        ((not Y) andalso
+                         <<Y:(Y andalso X)>>) := Y
+                     } = X);
+               _ ->
+                   false
+           end
+    >>.
+
+%% GH-6468. Same type of crash.
+inconsistent_types_2() ->
+    <<
+      0 || case id([]) of
+               Y ->
+                   <<
+                     Y ||
+                       _ <- Y,
+                       (not ((false = Y) = (Y /= []))), (_ = Y)
+                   >>
+           end
+    >>.
+
 filters(Config) when is_list(Config) ->
     cs_init(),
     <<"BDF">> =
-- 
2.35.3

openSUSE Build Service is sponsored by