From c9f5fdb5c92c418f28d67bb62ea8baac296da5ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Sat, 12 Jan 2019 06:43:15 +0100 Subject: beam_type: Eliminate compiler crash when arithmetic expression fails The compiler would crash when compiling code such as: (A / B) band 16#ff The type for the expression would be 'none', but beam_type:verified_type/1 did not handle 'none'. https://bugs.erlang.org/browse/ERL-829 --- lib/compiler/src/beam_type.erl | 3 ++- lib/compiler/test/beam_type_SUITE.erl | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/compiler/src/beam_type.erl b/lib/compiler/src/beam_type.erl index b5c979e529..a1e9eff8f3 100644 --- a/lib/compiler/src/beam_type.erl +++ b/lib/compiler/src/beam_type.erl @@ -1114,4 +1114,5 @@ verified_type(nonempty_list=T) -> T; verified_type({tuple,_,Sz,[]}=T) when is_integer(Sz) -> T; verified_type({tuple,_,Sz,[_]}=T) when is_integer(Sz) -> T; verified_type({tuple_element,_,_}=T) -> T; -verified_type(float=T) -> T. +verified_type(float=T) -> T; +verified_type(none=T) -> T. diff --git a/lib/compiler/test/beam_type_SUITE.erl b/lib/compiler/test/beam_type_SUITE.erl index 061076b3ff..9f691716e3 100644 --- a/lib/compiler/test/beam_type_SUITE.erl +++ b/lib/compiler/test/beam_type_SUITE.erl @@ -157,6 +157,10 @@ coverage(Config) -> [_|_] -> ok end, + + %% Cover beam_type:verified_type(none). + {'EXIT',{badarith,_}} = (catch (id(2) / id(1)) band 16#ff), + ok. booleans(_Config) -> -- cgit v1.2.3