Skip to content

Commit a7901f8

Browse files
committed
Merge branch 'isabell/compiler/fix/GH-11494/OTP-20312' into maint
* isabell/compiler/fix/GH-11494/OTP-20312: compiler: Fix bug in `beam_types:subtract/2` for bitstrings
2 parents 1be3263 + add6b21 commit a7901f8

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

lib/compiler/src/beam_types.erl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -541,11 +541,10 @@ subtract(#t_atom{elements=[_|_]=Set0}, #t_atom{elements=[_|_]=Set1}) ->
541541
end;
542542
subtract(#t_bitstring{size_unit=UnitA}=T, #t_bs_matchable{tail_unit=UnitB}) ->
543543
subtract_matchable(T, UnitA, UnitB);
544-
subtract(#t_bitstring{appendable=App,size_unit=UnitA}=T,
545-
#t_bitstring{appendable=App,size_unit=UnitB}) ->
546-
subtract_matchable(T, UnitA, UnitB);
547-
subtract(#t_bitstring{}=T, #t_bitstring{}) ->
544+
subtract(#t_bitstring{appendable=false}=T, #t_bitstring{appendable=true}) ->
548545
T;
546+
subtract(#t_bitstring{size_unit=UnitA}=T, #t_bitstring{size_unit=UnitB}) ->
547+
subtract_matchable(T, UnitA, UnitB);
549548
subtract(#t_bs_context{tail_unit=UnitA}=T, #t_bs_matchable{tail_unit=UnitB}) ->
550549
subtract_matchable(T, UnitA, UnitB);
551550
subtract(#t_bs_context{tail_unit=UnitA}=T, #t_bs_context{tail_unit=UnitB}) ->

lib/compiler/test/beam_ssa_SUITE.erl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
mapfoldl/0,mapfoldl/1,
3232
grab_bag/1,redundant_br/1,
3333
coverage/1,normalize/1,
34-
trycatch/1,gh_6599/1]).
34+
trycatch/1,gh_6599/1,gh_11494/1]).
3535

3636
suite() -> [{ct_hooks,[ts_install_cth]}].
3737

@@ -55,7 +55,8 @@ groups() ->
5555
coverage,
5656
normalize,
5757
trycatch,
58-
gh_6599
58+
gh_6599,
59+
gh_11494
5960
]}].
6061

6162
init_per_suite(Config) ->
@@ -1560,6 +1561,17 @@ gh_6599_7(X, Y) ->
15601561
ok
15611562
end.
15621563

1564+
gh_11494(_Config) ->
1565+
100 = inspect([100]),
1566+
<<>> = inspect(<<>>),
1567+
ok.
1568+
1569+
inspect(Value) ->
1570+
case Value of
1571+
Res when is_integer(Res);
1572+
is_bitstring(Res) -> Res;
1573+
[Num] -> inspect(Num)
1574+
end.
15631575

15641576
%% The identity function.
15651577
id(I) -> I.

0 commit comments

Comments
 (0)