Why does the following code cause the Erlang HiPE compiler crash?

397 views Asked by At

The code is following:

-module(hipe_crash). 
-export([f/6]). 

f(A, B, C, D, E, L) -> 
    lists:foldl(fun (X, P) -> 
        AVar = case A of 
            0 -> 1 / D; 
            N -> N / (C - B) 
        end, 
        BVar = case E of 
            atom1 -> 1.0; 
            atom2 -> 0.8; 
            _ -> E 
        end, 
        CVar = case X of 
            atom1 -> 0.1 * AVar; 
            _ -> 1.0 
        end, 
        P * BVar * CVar 
    end, 1, L). 

Compiling this code with erlc no error occur,compiling is ok. But when I compile it with erlc +native ,the compiler crashed,with information:

<HiPE (v 3.9.2)> EXITED with reason {function_clause,[{hipe_icode_fp,assert_assigned,[[{30,{icode_variable,40,fvar,[]}}]],[{file,[104,105,112,101,95,105,99,111,100,101,95,102,112,46,101,114,108]},{line,772}]},{hipe_icode_fp,bindings_are_assigned,1,[{file,[104,105,112,101,95,105,99,111,100,101,95,102,112,46,101,114,108]},{line,766}]},{hipe_icode_fp,filter_map,3,[{file,[104,105,112,101,95,105,99,111,100,101,95,102,112,46,101,114,108]},{line,753}]},{hipe_icode_fp,transform_block,2,[{file,[104,105,112,101,95,105,99,111,100,101,95,102,112,46,101,114,108]},{line,162}]},{hipe_icode_fp,cfg,1,[{file,[104,105,112,101,95,105,99,111,100,101,95,102,112,46,101,114,108]},{line,48}]},{hipe_main,icode_ssa_type,4,[{file,[104,105,112,101,95,109,97,105,110,46,101,114,108]},{line,273}]},{hipe_main,icode_ssa,4,[{file,[104,105,112,101,95,109,97,105,110,46,101,114,108]},{line,255}]},{hipe_main,compile_icode,5,[{file,[104,105,112,101,95,109,97,105,110,46,101,114,108]},{line,109}]}]} @hipe:829
hipe_crash.erl:none: internal error in native_compile;
crash reason: {{hipe,829,
                   {function_clause,
                       [{hipe_icode_fp,assert_assigned,
                            [[{30,{icode_variable,40,fvar,[]}}]],
                            [{file,"hipe_icode_fp.erl"},{line,772}]},
                        {hipe_icode_fp,bindings_are_assigned,1,
                            [{file,"hipe_icode_fp.erl"},{line,766}]},
                        {hipe_icode_fp,filter_map,3,
                            [{file,"hipe_icode_fp.erl"},{line,753}]},
                        {hipe_icode_fp,transform_block,2,
                            [{file,"hipe_icode_fp.erl"},{line,162}]},
                        {hipe_icode_fp,cfg,1,
                            [{file,"hipe_icode_fp.erl"},{line,48}]},
                        {hipe_main,icode_ssa_type,4,
                            [{file,"hipe_main.erl"},{line,273}]},
                        {hipe_main,icode_ssa,4,
                            [{file,"hipe_main.erl"},{line,255}]},
                        {hipe_main,compile_icode,5,
                            [{file,"hipe_main.erl"},{line,109}]}]}},
               [{hipe,finalize_fun_sequential,3,
                    [{file,"hipe.erl"},{line,829}]},
                {hipe,'-finalize_fun_concurrent/3-fun-3-',4,
                    [{file,"hipe.erl"},{line,795}]}]}

I found this code in :http://erlang.2086793.n4.nabble.com/internal-error-in-native-compile-td2298937.html.But I can't get more information about why this code crashes the compiler.

1

There are 1 answers

0
拿小xi的铅笔 On

One of the BEAM float-point operations' optimisations is to group float-point operations into blocks,if some intermediate operation failed,the BEAM will signal badarith. It relies on headware.
I think it's a bug of the exception handler. You can use the no_inline_fp HiPE compiler option at the expense of disabling all float-point optimisations.