From 499295576712b14314ebc8f9753af7f0e1198080 Mon Sep 17 00:00:00 2001 From: Mikael Pettersson Date: Fri, 27 Aug 2010 22:00:53 +0200 Subject: fix crash in hipe_icode_exceptions This fixes a problem in the HiPE compiler's BEAM-to-Icode pass where it can crash due to the BEAM compiler's merging of identical basic blocks with different exception handling contexts. This bug has been latent, but is now exposed by what appears to be more aggressive optimizations in BEAM. The added comment explains things in more detail. --- lib/hipe/icode/hipe_icode_exceptions.erl | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib') diff --git a/lib/hipe/icode/hipe_icode_exceptions.erl b/lib/hipe/icode/hipe_icode_exceptions.erl index 787fb05415..3c8f7b5712 100644 --- a/lib/hipe/icode/hipe_icode_exceptions.erl +++ b/lib/hipe/icode/hipe_icode_exceptions.erl @@ -344,6 +344,16 @@ pop_catch(Cs) -> pop_catch_1([[_|C] | Cs]) -> [C | pop_catch_1(Cs)]; +pop_catch_1([[] | Cs]) -> + %% The elements in the list represent different possible incoming + %% stacks of catch handlers to this BB. Before the fixpoint has + %% been found these elements are underapproximations of the true + %% stacks, therefore it's possible for these elements to be too + %% short for the number of pops implied by the code in the BB. + %% We must not fail in that case, so we set pop([]) = []. + %% This fixes find_catches_crash.erl and compiler_tests in the + %% HiPE test suite. + [[] | pop_catch_1(Cs)]; pop_catch_1([]) -> []. -- cgit v1.2.3