<div>Hi!</div><div><br></div>We found some code that successfully compiles to bytecode and behaves as expected using the beam interpreter but fails to compile using the hipe compiler. The code in questions is the 'cowboy_http' module in the cowboy web server. The code is available to browse online at <a href="https://github.com/extend/cowboy">https://github.com/extend/cowboy</a><div>
<br></div><div>The module contains many occurances of <<..., Var/bits>> patterns. Replacing all occurances of "bits" with "binary" solves the problem. I tried this because the code is only working on character strings, matching out bitstrings doesn't make much sense to begin with. I have reproduced the error on 64bit builds of the R14B04 and R15A releases under GNU/Linux (Debian wheezy). I did not try older releases to check if it is a new issue.</div>
<div><br></div><div>To reproduce the error. Execute the following steps on a system with either one of these releases installed. I'm using R15A here because the line numbers in the error messages are pretty useful to include in a bug report. (thanks for this addition of line numbers in R15).</div>
<div><br></div><div>1. Download, compile and run tests using bytecode interpreter</div><div>git clone git://<a href="http://github.com/extend/cowboy.git">github.com/extend/cowboy.git</a></div><div>cd cowboy</div><div>git checkout 168405830d564ff87fac61bd990c17ab6a35dfa8 # in case the code is updated</div>
<div><br></div><div>rebar get-deps</div><div>rebar compile</div><div>rebar eunit skip_deps=true</div><div><br></div><div>2. Add native to the erl_opts parameter list in rebar.config</div><div>vim rebar.config # add it under warn_export_all</div>
<div><br></div><div>3. Recompile using hipe</div><div>rebar clean</div><div>rebar compile</div><div><br></div><div><br></div><div>4. Expect an output containing these error messages</div><div> </div><div><div>==> cowboy (compile)</div>
<div>Compiled src/cowboy_http_handler.erl</div><div>Compiled src/cowboy_http_websocket_handler.erl</div><div>Compiled src/cowboy_protocol.erl</div><div>Compiled src/cowboy.erl</div><div>Compiled src/cowboy_app.erl</div><div>
Compiled src/cowboy_acceptors_sup.erl</div><div>Compiled src/cowboy_acceptor.erl</div><div>Compiled src/cowboy_bstr.erl</div><div>Compiled src/cowboy_dispatcher.erl</div><div><HiPE (v 3.8.1.pre)> EXITED with reason {function_clause,[{hipe_rtl_binary_match,gen_rtl,[{bs_match_string,<<34>>,1},[],[{rtl_var,21}],17,6],[{file,[104,105,112,101,95,114,116,108,95,98,105,110,97,114,121,95,109,97,116,99,104,46,101,114,108]},{line,45}]},{hipe_rtl_binary,gen_rtl,7,[{file,[104,105,112,101,95,114,116,108,95,98,105,110,97,114,121,46,101,114,108]},{line,33}]},{hipe_rtl_primops,gen_primop,3,[{file,[104,105,112,101,95,114,116,108,95,112,114,105,109,111,112,115,46,101,114,108]},{line,147}]},{hipe_icode2rtl,gen_call,3,[{file,[104,105,112,101,95,105,99,111,100,101,50,114,116,108,46,101,114,108]},{line,189}]},{hipe_icode2rtl,translate_instrs,5,[{file,[104,105,112,101,95,105,99,111,100,101,50,114,116,108,46,101,114,108]},{line,104}]},{hipe_icode2rtl,translate,2,[{file,[104,105,112,101,95,105,99,111,100,101,50,114,116,108,46,101,114,108]},{line,71}]},{hipe_main,translate_to_rtl,2,[{file,[104,105,112,101,95,109,97,105,110,46,101,114,108]},{line,396}]},{hipe_main,icode_to_rtl,4,[{file,[104,105,112,101,95,109,97,105,110,46,101,114,108]},{line,376}]}]} @hipe:867</div>
<div><br></div><div>=ERROR REPORT==== 9-Dec-2011::22:18:06 ===</div><div><HiPE (v 3.8.1.pre)> Error: [hipe:866]: ERROR: {function_clause,</div><div> [{hipe_rtl_binary_match,</div>
<div> gen_rtl,</div><div> [{bs_match_string,<<"\"">>,</div><div> 1},</div>
<div> [],</div><div> [{rtl_var,21}],</div><div> 17,6],</div><div> [{file,</div>
<div> "hipe_rtl_binary_match.erl"},</div><div> {line,45}]},</div><div> {hipe_rtl_binary,gen_rtl,7,</div>
<div> [{file,</div><div> "hipe_rtl_binary.erl"},</div><div> {line,33}]},</div>
<div> {hipe_rtl_primops,</div><div> gen_primop,3,</div><div> [{file,</div><div>
"hipe_rtl_primops.erl"},</div><div> {line,147}]},</div><div> {hipe_icode2rtl,gen_call,3,</div>
<div> [{file,"hipe_icode2rtl.erl"},</div><div> {line,189}]},</div><div> {hipe_icode2rtl,</div>
<div> translate_instrs,5,</div><div> [{file,"hipe_icode2rtl.erl"},</div><div> {line,104}]},</div>
<div> {hipe_icode2rtl,translate,2,</div><div> [{file,"hipe_icode2rtl.erl"},</div><div> {line,71}]},</div>
<div> {hipe_main,translate_to_rtl,</div><div> 2,</div><div> [{file,"hipe_main.erl"},</div>
<div> {line,396}]},</div><div> {hipe_main,icode_to_rtl,4,</div><div> [{file,"hipe_main.erl"},</div>
<div> {line,376}]}]}</div><div><br></div><div>=ERROR REPORT==== 9-Dec-2011::22:18:06 ===</div><div>Error in process <0.788.0> with exit value: {{hipe,867,{function_clause,[{hipe_rtl_binary_match,gen_rtl,[{bs_match_string,<<1 byte>>,1},[],[{rtl_var,21}],17,6],[{file,"hipe_rtl_binary_match.erl"},{line,45}]},{hipe_rtl_binary,gen_rtl,7,[{file,"hipe_rtl_binary.erl"},{line,33}]},{hipe_rtl_primops... </div>
<div><br></div><div>src/cowboy_http.erl:none: internal error in native_compile;</div><div>crash reason: {{hipe,867,</div><div> {function_clause,</div><div> [{hipe_rtl_binary_match,gen_rtl,</div>
<div> [{bs_match_string,<<"\"">>,1},</div><div> [],</div><div> [{rtl_var,21}],</div><div> 17,6],</div>
<div> [{file,"hipe_rtl_binary_match.erl"},{line,45}]},</div><div> {hipe_rtl_binary,gen_rtl,7,</div><div> [{file,"hipe_rtl_binary.erl"},{line,33}]},</div>
<div> {hipe_rtl_primops,gen_primop,3,</div><div> [{file,"hipe_rtl_primops.erl"},{line,147}]},</div><div> {hipe_icode2rtl,gen_call,3,</div>
<div> [{file,"hipe_icode2rtl.erl"},{line,189}]},</div><div> {hipe_icode2rtl,translate_instrs,5,</div><div> [{file,"hipe_icode2rtl.erl"},{line,104}]},</div>
<div> {hipe_icode2rtl,translate,2,</div><div> [{file,"hipe_icode2rtl.erl"},{line,71}]},</div><div> {hipe_main,translate_to_rtl,2,</div><div>
[{file,"hipe_main.erl"},{line,396}]},</div><div> {hipe_main,icode_to_rtl,4,</div><div> [{file,"hipe_main.erl"},{line,376}]}]}},</div>
<div> [{hipe,finalize_fun_sequential,3,</div><div> [{file,"hipe.erl"},{line,867}]},</div><div> {hipe,'-finalize_fun_concurrent/3-fun-3-',4,</div><div> [{file,"hipe.erl"},{line,833}]}]}</div>
</div><div><br></div><div><br></div><div>I hope this is enough information to reproduce the issue once it hits someones desk at the other side of the internet.</div><div><br></div><div>/ Magnus Klaar</div>