File 0421-Fix-code-generation-for-bin-comprehension-without-ge.patch of Package erlang
From 8e50d96652b0af10fbddd26cadd3e16fa340ade2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org>
Date: Fri, 21 Feb 2020 12:46:15 +0100
Subject: [PATCH 01/30] Fix code generation for bin comprehension without
generator
In code such as the following, no test_heap instruction
was emitted for the list construction (causing beam_validator
to reject the code):
[<<(id(<<"abc">>)) || true >>].
(The test_heap got swallowed by the bs_private_append instruction.)
---
lib/compiler/src/beam_ssa_codegen.erl | 7 ++++---
lib/compiler/test/bs_bincomp_SUITE.erl | 11 +++++++++--
2 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/lib/compiler/src/beam_ssa_codegen.erl b/lib/compiler/src/beam_ssa_codegen.erl
index d028f4d6ef..fd91f2585a 100644
--- a/lib/compiler/src/beam_ssa_codegen.erl
+++ b/lib/compiler/src/beam_ssa_codegen.erl
@@ -1129,20 +1129,21 @@ cg_block([#cg_set{op=bs_init,dst=Dst0,args=Args0,anno=Anno}=I,
Line = line(Anno),
Alloc = map_get(alloc, Anno),
[#b_literal{val=Kind}|Args1] = Args0,
+ Live = get_live(I),
case Kind of
new ->
[Dst,Size,{integer,Unit}] = beam_args([Dst0|Args1], St),
- Live = get_live(I),
{[Line|cg_bs_init(Dst, Size, Alloc, Unit, Live, Fail)],St};
private_append ->
[Dst,Src,Bits,{integer,Unit}] = beam_args([Dst0|Args1], St),
Flags = {field_flags,[]},
- Is = [Line,{bs_private_append,Fail,Bits,Unit,Src,Flags,Dst}],
+ TestHeap = {test_heap,Alloc,Live},
+ BsPrivateAppend = {bs_private_append,Fail,Bits,Unit,Src,Flags,Dst},
+ Is = [TestHeap,Line,BsPrivateAppend],
{Is,St};
append ->
[Dst,Src,Bits,{integer,Unit}] = beam_args([Dst0|Args1], St),
Flags = {field_flags,[]},
- Live = get_live(I),
Is = [Line,{bs_append,Fail,Bits,Alloc,Live,Unit,Src,Flags,Dst}],
{Is,St}
end;
diff --git a/lib/compiler/test/bs_bincomp_SUITE.erl b/lib/compiler/test/bs_bincomp_SUITE.erl
index eade3ff93f..a4125f00f1 100644
--- a/lib/compiler/test/bs_bincomp_SUITE.erl
+++ b/lib/compiler/test/bs_bincomp_SUITE.erl
@@ -26,7 +26,8 @@
init_per_group/2,end_per_group/2,
byte_aligned/1,bit_aligned/1,extended_byte_aligned/1,
extended_bit_aligned/1,mixed/1,filters/1,trim_coverage/1,
- nomatch/1,sizes/1,general_expressions/1,matched_out_size/1]).
+ nomatch/1,sizes/1,general_expressions/1,matched_out_size/1,
+ no_generator/1]).
-include_lib("common_test/include/ct.hrl").
@@ -35,7 +36,8 @@ suite() -> [{ct_hooks,[ts_install_cth]}].
all() ->
[byte_aligned, bit_aligned, extended_byte_aligned,
extended_bit_aligned, mixed, filters, trim_coverage,
- nomatch, sizes, general_expressions, matched_out_size].
+ nomatch, sizes, general_expressions, matched_out_size,
+ no_generator].
groups() ->
[].
@@ -351,6 +353,11 @@ matched_out_size(Config) when is_list(Config) ->
matched_out_size_1(Binary) ->
<< <<X>> || <<S, X:S>> <= Binary>>.
+no_generator(Config) ->
+ [<<"abc">>] = [<<(id(<<"abc">>)) || true >>],
+ {<<>>} = {<<(id(<<"abc">>)) || false >>},
+ ok.
+
cs_init() ->
erts_debug:set_internal_state(available_internal_state, true),
ok.
--
2.16.4