Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash in beam_ssa_private_append #7011

Closed
bjorng opened this issue Mar 13, 2023 · 1 comment · Fixed by #7014
Closed

Crash in beam_ssa_private_append #7011

bjorng opened this issue Mar 13, 2023 · 1 comment · Fixed by #7014
Assignees
Labels
bug Issue is reported as a bug team:VM Assigned to OTP team VM

Comments

@bjorng
Copy link
Contributor

bjorng commented Mar 13, 2023

Describe the bug:

During compilation of the following module:

-module(bug).
-export([bug/2,id/1]).

bug(V, _) when V ->
    << ok || catch <<(bug(id(ok), ok))/binary>> >>;
bug(_, V) ->
    id(ok) bor V.

id(I) ->
    I.

the compiler crashes:

$ erlc bug.erl
Sub pass ssa_opt_private_append
bug.erl: internal error in pass beam_ssa_opt:
exception error: no case clause matching {{bif,'bor'},[{b_var,7},{b_var,1}],self}
  in function  beam_ssa_private_append:track_value_in_fun/6 (beam_ssa_private_append.erl, line 212)
  in call from beam_ssa_private_append:private_append/3 (beam_ssa_private_append.erl, line 71)
  in call from compile:run_sub_passes_1/3 (compile.erl, line 424)
  in call from beam_ssa_opt:run_phases/3 (beam_ssa_opt.erl, line 75)
  in call from beam_ssa_opt:module/2 (beam_ssa_opt.erl, line 71)
  in call from compile:'-select_passes/2-anonymous-0-'/3 (compile.erl, line 683)
  in call from compile:fold_comp/4 (compile.erl, line 410)
  in call from compile:internal_comp/5 (compile.erl, line 394)
bug.erl:5:5: Warning: binary construction will fail because of a type mismatch
%    5|     << ok || catch <<(bug(id(ok), ok))/binary>> >>;
%     |     ^

To Reproduce

See the example above.

Expected behavior
Compilation should succeed without a crash.

Affected versions
The master branch, with or without #7005.

@bjorng bjorng added team:VM Assigned to OTP team VM bug Issue is reported as a bug labels Mar 13, 2023
@bjorng bjorng self-assigned this Mar 13, 2023
@frej
Copy link
Contributor

frej commented Mar 13, 2023

Looks like my fault, will take a look.

frej added a commit to frej/otp that referenced this issue Mar 13, 2023
In the private append pass we track values which could be bitstrings
or a term containing a bitstring to find the operation where the
bitstring is constructed. For the purpose of this description, we call
such a value a potential bitstring.

As tracking potential bitstrings is done without correlating type
checks and flow-control, we can sometimes encounter values which are
not potential bitstrings. In 0bac830
the tracking logic was refined to abort as soon as we detected that a
returned literal could not be on an execution path returning a
potential bitstring. This commit extends the tracking logic to abort
tracking when a potential bitstring is constructed by an operation
which cannot produce a bitstring or a term containing a bitstring.

Closes erlang#7011
bjorng added a commit that referenced this issue Mar 14, 2023
Fix compiler crash in beam_ssa_private_append (#7011)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue is reported as a bug team:VM Assigned to OTP team VM
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants