aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler
diff options
context:
space:
mode:
authorJohn Högberg <[email protected]>2019-06-11 08:14:59 +0200
committerJohn Högberg <[email protected]>2019-06-11 08:14:59 +0200
commit05d316d93ddb4796b03a4a04175fd8c09b0092be (patch)
tree658beea07a290fd9463b4280a6f58e80060efed6 /lib/compiler
parenta8ba18249d6fd3a913f320bdeeb8b9ea5eef2888 (diff)
parenta726c015867beffe15cc20ee22e32778678e8fdf (diff)
downloadotp-05d316d93ddb4796b03a4a04175fd8c09b0092be.tar.gz
otp-05d316d93ddb4796b03a4a04175fd8c09b0092be.tar.bz2
otp-05d316d93ddb4796b03a4a04175fd8c09b0092be.zip
Merge branch 'john/compiler/fix-bad-bitstring-type-opt/OTP-15872' into maint
* john/compiler/fix-bad-bitstring-type-opt/OTP-15872: beam_ssa_type: Fix incorrect bitstring unit determination
Diffstat (limited to 'lib/compiler')
-rw-r--r--lib/compiler/src/beam_ssa_type.erl11
-rw-r--r--lib/compiler/test/beam_type_SUITE.erl14
2 files changed, 14 insertions, 11 deletions
diff --git a/lib/compiler/src/beam_ssa_type.erl b/lib/compiler/src/beam_ssa_type.erl
index 57fd7fec60..68920e7dd3 100644
--- a/lib/compiler/src/beam_ssa_type.erl
+++ b/lib/compiler/src/beam_ssa_type.erl
@@ -840,15 +840,8 @@ type({bif,Bif}, Args, Ts, _Ds) ->
Type ->
Type
end;
-type(bs_init, [#b_literal{val=Type}|Args], _Ts, _Ds) ->
- case {Type,Args} of
- {new,[_,#b_literal{val=Unit}]} ->
- {binary,Unit};
- {append,[_,_,#b_literal{val=Unit}]} ->
- {binary,Unit};
- {private_append,[_,_,#b_literal{val=Unit}]} ->
- {binary,Unit}
- end;
+type(bs_init, _Args, _Ts, _Ds) ->
+ {binary, 1};
type(bs_extract, [Ctx], Ts, _Ds) ->
#t_bs_match{type=Type} = get_type(Ctx, Ts),
Type;
diff --git a/lib/compiler/test/beam_type_SUITE.erl b/lib/compiler/test/beam_type_SUITE.erl
index 2297c2e0f5..076a604aa4 100644
--- a/lib/compiler/test/beam_type_SUITE.erl
+++ b/lib/compiler/test/beam_type_SUITE.erl
@@ -24,7 +24,7 @@
integers/1,numbers/1,coverage/1,booleans/1,setelement/1,
cons/1,tuple/1,record_float/1,binary_float/1,float_compare/1,
arity_checks/1,elixir_binaries/1,find_best/1,
- test_size/1,cover_lists_functions/1,list_append/1]).
+ test_size/1,cover_lists_functions/1,list_append/1,bad_binary_unit/1]).
suite() -> [{ct_hooks,[ts_install_cth]}].
@@ -48,7 +48,8 @@ groups() ->
find_best,
test_size,
cover_lists_functions,
- list_append
+ list_append,
+ bad_binary_unit
]}].
init_per_suite(Config) ->
@@ -508,5 +509,14 @@ list_append(_Config) ->
hello = id([]) ++ id(hello),
ok.
+%% OTP-15872: The compiler would treat the "Unit" of bs_init instructions as
+%% the unit of the result instead of the required unit of the input, causing
+%% is_binary checks to be wrongly optimized away.
+bad_binary_unit(_Config) ->
+ Bin = id(<<1,2,3>>),
+ Bitstring = <<Bin/binary,1:1>>,
+ false = is_binary(Bitstring),
+ ok.
+
id(I) ->
I.