Skip to content

Instantly share code, notes, and snippets.

@bjorng
Created August 20, 2018 14:13
Show Gist options
  • Save bjorng/3666b4133b0d242ddcf1aa0626a67178 to your computer and use it in GitHub Desktop.
Save bjorng/3666b4133b0d242ddcf1aa0626a67178 to your computer and use it in GitHub Desktop.
A bug in HiPE when using the new SSA-based compiler
Demonstrating the bug.
Erlang/OTP 21 [erts-10.0] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]
Eshell V10.0 (abort with ^G)
1> c(hipe_bug, [from_asm,native]).
{ok,hipe_bug}
2> hipe_bug:run().
size_object: matchstate term not allowedAborted (core dumped)
-module(hipe_bug).
-compile(native).
-export([run/0]).
run() ->
{[],<<1,2,3>>} =
dec_subidentifiers4(<<1:1,42:7,1:1,99:7,1,2,3>>, 0, [], 2),
ok.
dec_subidentifiers4(<<H,T/binary>>, Av, Al, Len) when Len =/= 0 ->
dec_subidentifiers4(T, 0, [((Av bsl 7) bor H)|Al], Len-1);
dec_subidentifiers4(Buffer, _Av, Al, 0) ->
{lists:reverse(Al),Buffer}.
{module, hipe_bug}. %% version = 0
{exports, [{module_info,0},{module_info,1},{run,0}]}.
{attributes, []}.
{labels, 12}.
{function, run, 0, 2}.
{label,1}.
{line,[{location,"hipe_bug.erl",6}]}.
{func_info,{atom,hipe_bug},{atom,run},0}.
{label,2}.
{allocate,0,0}.
{move,nil,{x,2}}.
{move,{integer,0},{x,1}}.
{move,{integer,2},{x,3}}.
{move,{literal,<<170,227,1,2,3>>},{x,0}}.
{line,[{location,"hipe_bug.erl",8}]}.
{call,4,{f,5}}.
{test,is_eq_exact,{f,3},[{x,0},{literal,{[],<<1,2,3>>}}]}.
{move,{atom,ok},{x,0}}.
{deallocate,0}.
return.
{label,3}.
{line,[{location,"hipe_bug.erl",7}]}.
{badmatch,{x,0}}.
{function, dec_subidentifiers4, 4, 5}.
{label,4}.
{line,[{location,"hipe_bug.erl",11}]}.
{func_info,{atom,hipe_bug},{atom,dec_subidentifiers4},4}.
{label,5}.
{test,bs_start_match2,{f,6},4,[{x,0},0],{x,0}}.
{test,bs_get_integer2,
{f,6},
4,
[{x,0},
{integer,8},
1,
{field_flags,[{anno,[11,{file,"hipe_bug.erl"}]},unsigned,big]}],
{x,4}}.
{test,bs_get_binary2,
{f,6},
5,
[{x,0},
{atom,all},
8,
{field_flags,[{anno,[11,{file,"hipe_bug.erl"}]},unsigned,big]}],
{x,5}}.
{'%',{no_bin_opt,{[{y,0}],
not_all_unused_after,
{bs_context_to_binary,{x,0}}},
[11,{file,"hipe_bug.erl"}]}}.
{test,is_ne_exact,{f,6},[{x,3},{integer,0}]}.
{line,[{location,"hipe_bug.erl",12}]}.
{gc_bif,'bsl',{f,0},6,[{x,1},{integer,7}],{x,0}}.
{line,[{location,"hipe_bug.erl",12}]}.
{gc_bif,'bor',{f,0},6,[{x,0},{x,4}],{x,0}}.
{line,[{location,"hipe_bug.erl",12}]}.
{gc_bif,'-',{f,0},6,[{x,3},{integer,1}],{x,1}}.
{test_heap,2,6}.
{put_list,{x,0},{x,2},{x,2}}.
{move,{x,1},{x,3}}.
{move,{integer,0},{x,1}}.
{move,{x,5},{x,0}}.
{call_only,4,{f,5}}.
{label,6}.
{test,is_eq_exact,{f,7},[{x,3},{integer,0}]}.
{allocate,1,3}.
{move,{x,0},{y,0}}.
{bs_context_to_binary,{x,0}}.
{move,{x,2},{x,0}}.
{line,[{location,"hipe_bug.erl",14}]}.
{call_ext,1,{extfunc,lists,reverse,1}}.
{test_heap,3,1}.
{put_tuple,2,{x,1}}.
{put,{x,0}}.
{put,{y,0}}.
{move,{x,1},{x,0}}.
{deallocate,1}.
return.
{label,7}.
{bs_context_to_binary,{x,0}}.
{jump,{f,4}}.
{function, module_info, 0, 9}.
{label,8}.
{line,[]}.
{func_info,{atom,hipe_bug},{atom,module_info},0}.
{label,9}.
{move,{atom,hipe_bug},{x,0}}.
{line,[]}.
{call_ext_only,1,{extfunc,erlang,get_module_info,1}}.
{function, module_info, 1, 11}.
{label,10}.
{line,[]}.
{func_info,{atom,hipe_bug},{atom,module_info},1}.
{label,11}.
{move,{x,0},{x,1}}.
{move,{atom,hipe_bug},{x,0}}.
{line,[]}.
{call_ext_only,2,{extfunc,erlang,get_module_info,2}}.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment