File 3292-Eliminate-crash-in-beam_ssa_codegen.patch of Package erlang

From 91e0c5d3020edb76cbf0b4ed50e611cbac205469 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org>
Date: Wed, 24 May 2023 12:18:49 +0200
Subject: [PATCH] Eliminate crash in beam_ssa_codegen

Closes #7283
---
 lib/compiler/src/beam_ssa_codegen.erl | 12 ++++++++++++
 lib/compiler/test/beam_ssa_SUITE.erl  | 14 ++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/lib/compiler/src/beam_ssa_codegen.erl b/lib/compiler/src/beam_ssa_codegen.erl
index 9f6169829b..81ab1e61c7 100644
--- a/lib/compiler/src/beam_ssa_codegen.erl
+++ b/lib/compiler/src/beam_ssa_codegen.erl
@@ -1814,6 +1814,18 @@ cg_instr(bs_get_position, [Ctx], Dst, Set) ->
 cg_instr(put_map, [{atom,assoc},SrcMap|Ss], Dst, Set) ->
     Live = get_live(Set),
     [{put_map_assoc,{f,0},SrcMap,Dst,Live,{list,Ss}}];
+cg_instr(put_map, [{atom,exact},SrcBadMap|_Ss], _Dst, #cg_set{anno=Anno}=Set) ->
+    %% GH-7283: An exact `put_map` without a failure label was not
+    %% handled. The absence of the failure label can only mean that
+    %% the source is known not to be a valid map. (None of the current
+    %% optimization passes can figure out that the key is always
+    %% present in the map and that the operation therefore can never
+    %% fail.)
+    Live = get_live(Set),
+    [{test_heap,3,Live},
+     {put_tuple2,{x,0},{list,[{atom,badmap},SrcBadMap]}},
+     line(Anno),
+     {call_ext_last,1,{extfunc,erlang,error,1},1}];
 cg_instr(is_nonempty_list, Ss, Dst, Set) ->
     #cg_set{anno=#{was_bif_is_list := true}} = Set, %Assertion.
 
diff --git a/lib/compiler/test/beam_ssa_SUITE.erl b/lib/compiler/test/beam_ssa_SUITE.erl
index 0bb485c7f1..80afa88f05 100644
--- a/lib/compiler/test/beam_ssa_SUITE.erl
+++ b/lib/compiler/test/beam_ssa_SUITE.erl
@@ -451,6 +451,10 @@ maps(_Config) ->
     {jkl,nil,nil} = maps_2(#{jkl => 0}),
     error = maps_2(#{}),
 
+    {'EXIT',{{badmap,true},_}} = catch maps_4(id(true), id(true)),
+    error = maps_4(id(#{}), id(true)),
+    error = maps_4(id(#{}), id(#{})),
+
     ok.
 
 maps_1(K) ->
@@ -523,6 +527,16 @@ maps_2b(#{}=Map) ->
             end
     end.
 
+maps_4(A, B = A) when B; A ->
+    A#{ok := ok},
+    try A of
+        B -> B
+    after
+        ok
+    end#{ok := ok};
+maps_4(_, _) ->
+    error.
+
 -record(wx_ref, {type=any_type,ref=any_ref}).
 
 cover_ssa_dead(_Config) ->
-- 
2.35.3

openSUSE Build Service is sponsored by