[erlang-bugs] Use a set to store ref registers in beam_receive

Anthony Ramine <>
Wed Apr 10 00:19:31 CEST 2013


In some circumstances, as when inlining code, when some optimization passes are disabled or with hand-written but semantically correct Core Erlang or BEAM assembly, a fresh reference may be live in more than one register:

        {call_ext,0,{extfunc,erlang,make_ref,0}}. % Ref in [x0]
        {move,{x,0},{y,0}}. % Ref in [x0,y0]
        {move,{y,1},{x,0}}. % Ref in [y0]
        {move,{y,0},{x,0}}. % Ref in [x0,y0]
        {move,{x,0},{y,1}}. % Ref in [x0,y0,y1]
        {loop_rec,{f,6},{x,0}}. % Ref in [y0,y1]

Pass beam_receive expects a single live register for the ref when it encounters the loop_rec instruction and crashes with the following reason:

    $ erlc t.S
    crash reason: {{case_clause,

This patch teaches beam_receive how to use a set of registers instead of a single one when tracking fresh references, thus avoiding the crash.

	git fetch https://github.com/nox/otp.git fix-multiple-ref-regs


This is yet again something that I encountered while working on the file optimization branch file-receive-optim:



Anthony Ramine

More information about the erlang-bugs mailing list