Skip to content

erts: Disable unsafe optimization in bs_append #9372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions erts/emulator/beam/erl_bits.c
Original file line number Diff line number Diff line change
Expand Up @@ -1479,14 +1479,6 @@ erts_bs_append_checked(Process* c_p, Eterm* reg, Uint live,
}
}

if (build_size_in_bits == 0) {
if (HeapWordsLeft(c_p) < extra_words) {
(void) erts_garbage_collect(c_p, extra_words, reg, live+1);
bin = reg[live];
}
return bin;
}

if((ERTS_UINT_MAX - build_size_in_bits) < erts_bin_offset) {
c_p->fvalue = am_size;
c_p->freason = SYSTEM_LIMIT;
Expand Down Expand Up @@ -1573,10 +1565,6 @@ erts_bs_append_checked(Process* c_p, Eterm* reg, Uint live,
}
}

if (build_size_in_bits == 0) {
return bin;
}

if((ERTS_UINT_MAX - build_size_in_bits) < erts_bin_offset) {
c_p->fvalue = am_size;
c_p->freason = SYSTEM_LIMIT;
Expand Down
8 changes: 6 additions & 2 deletions erts/emulator/test/bs_construct_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -553,9 +553,13 @@ do_something() ->

append_empty_is_same(Config) when is_list(Config) ->
NonWritableBin = <<"123">>,
true = erts_debug:same(NonWritableBin, append(NonWritableBin, <<>>)),

%% Should use erts_debug:same/2, but this was disabled in PR-9372
%% (ERIERL-1177) because the optimization was unsafe.
true = NonWritableBin =:= append(NonWritableBin, <<>>),
WritableBin = <<(id(<<>>))/binary,0,1,2,3,4,5,6,7>>,
true = erts_debug:same(WritableBin, append(WritableBin, <<>>)),
true = WritableBin =:= append(WritableBin, <<>>),

ok.

append(A, B) ->
Expand Down
Loading