File 0989-Support-loading-of-complicated-nested-binary-compreh.patch of Package erlang

From d133125c50a4c70a278148c6b3212d3f7a8b6ebe Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org>
Date: Fri, 25 Sep 2020 07:00:27 +0200
Subject: [PATCH] Support loading of complicated nested binary comprehensions

---
 erts/emulator/beam/ops.tab              |  3 +++
 erts/emulator/test/bs_bincomp_SUITE.erl | 14 +++++++++++++-
 lib/compiler/test/bs_bincomp_SUITE.erl  |  6 ++++++
 3 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/erts/emulator/beam/ops.tab b/erts/emulator/beam/ops.tab
index ed0b240d8a..14afdd8553 100644
--- a/erts/emulator/beam/ops.tab
+++ b/erts/emulator/beam/ops.tab
@@ -1300,6 +1300,9 @@ bs_append Fail Size Extra Live Unit Bin Flags Dst => \
 bs_private_append Fail Size Unit Bin Flags Dst => \
   i_bs_private_append Fail Unit Size Bin Dst
 
+i_bs_private_append Fail Unit Size Bin Dst=y => \
+  i_bs_private_append Fail Unit Size Bin x | move x Dst
+
 bs_init_writable
 
 i_bs_append j I I I s d
diff --git a/erts/emulator/test/bs_bincomp_SUITE.erl b/erts/emulator/test/bs_bincomp_SUITE.erl
index c481e93e41..2dcebc2ef9 100644
--- a/erts/emulator/test/bs_bincomp_SUITE.erl
+++ b/erts/emulator/test/bs_bincomp_SUITE.erl
@@ -112,7 +112,14 @@ mixed(Config) when is_list(Config) ->
     [(X+Y) || <<X:3>> <= <<1:3,2:3,3:3,4:3>>, <<Y:3>> <= <<1:3,2:3>>],
   [2,3,3,4,4,5,5,6] =  
     [(X+Y) || <<X:3>> <= <<1:3,2:3,3:3,4:3>>, Y <- [1,2]],
-  ok.
+
+    %% OTP-16899: Nested binary comprehensions would fail to load.
+    <<0,1,0,2,0,3,99>> = mixed_nested([1,2,3]),
+
+    ok.
+
+mixed_nested(L) ->
+    << << << << E:16 >> || E <- L >> || true >>/binary, 99:(id(8))>>.
 
 %% OTP-8179: Call tracing on binary comprehensions would cause a crash.
 tracing(Config) when is_list(Config) ->
@@ -148,3 +155,8 @@ tracer(Parent, N) ->
 		    tracer(Parent, N+1)
 	    end
     end.
+
+%%% Common utilities.
+
+id(I) ->
+    I.
diff --git a/lib/compiler/test/bs_bincomp_SUITE.erl b/lib/compiler/test/bs_bincomp_SUITE.erl
index 9ac261c805..48c91f856c 100644
--- a/lib/compiler/test/bs_bincomp_SUITE.erl
+++ b/lib/compiler/test/bs_bincomp_SUITE.erl
@@ -128,8 +128,14 @@ mixed(Config) when is_list(Config) ->
 	[(X+Y) || <<X:3>> <= <<1:3,2:3,3:3,4:3>>, <<Y:3>> <= <<1:3,2:3>>],
     [2,3,3,4,4,5,5,6] =
 	[(X+Y) || <<X:3>> <= <<1:3,2:3,3:3,4:3>>, {_,Y} <- [{a,1},{b,2}]],
+
+    %% OTP-16899: Nested binary comprehensions would fail to load.
+    <<0,1,0,2,0,3,99>> = mixed_nested([1,2,3]),
     cs_end().
 
+mixed_nested(L) ->
+    << << << << E:16 >> || E <- L >> || true >>/binary, 99:(id(8))>>.
+
 filters(Config) when is_list(Config) ->
     cs_init(),
     <<"BDF">> =
-- 
2.26.2

openSUSE Build Service is sponsored by