From cabdef3b97c077119fe6f43538dbdd5cffe9dd91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Mon, 20 May 2019 11:54:22 +0200 Subject: Fix non-terminating compilation The compiler would not terminate while compiling the following code: foo(<>, Tuple, NewValue) -> _ = element(N, Tuple), setelement(N, Tuple, NewValue). The type analysis pass would attempt to construct a huge list when attempting analyse the type of `Tuple` after the call to `setelement/3`. https://bugs.erlang.org/browse/ERL-948 --- lib/compiler/test/beam_type_SUITE.erl | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'lib/compiler/test') diff --git a/lib/compiler/test/beam_type_SUITE.erl b/lib/compiler/test/beam_type_SUITE.erl index 882e281a44..0d1680fb15 100644 --- a/lib/compiler/test/beam_type_SUITE.erl +++ b/lib/compiler/test/beam_type_SUITE.erl @@ -271,8 +271,22 @@ setelement(_Config) -> T0 = id({a,42}), {a,_} = T0, {b,_} = setelement(1, T0, b), + {z,b} = do_setelement_1(<<(id(1)):32>>, {a,b}, z), + {new,two} = do_setelement_2(<<(id(1)):1>>, {one,two}, new), ok. +do_setelement_1(<>, Tuple, NewValue) -> + _ = element(N, Tuple), + %% While updating the type for Tuple, beam_ssa_type would do: + %% maps:without(lists:seq(0, 4294967295), Elements) + setelement(N, Tuple, NewValue). + +do_setelement_2(<>, Tuple, NewValue) -> + %% Cover the second clause in remove_element_info/2. The + %% type for the second element will be kept. + two = element(2, Tuple), + setelement(N, Tuple, NewValue). + cons(_Config) -> [did] = cons(assigned, did), -- cgit v1.2.3