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

Compiler crash in pass beam_ssa_opt, sub pass ssa_opt_private_append #6847

Closed
bjorng opened this issue Feb 11, 2023 · 3 comments · Fixed by #6862
Closed

Compiler crash in pass beam_ssa_opt, sub pass ssa_opt_private_append #6847

bjorng opened this issue Feb 11, 2023 · 3 comments · Fixed by #6862
Assignees
Labels
bug Issue is reported as a bug team:VM Assigned to OTP team VM

Comments

@bjorng
Copy link
Contributor

bjorng commented Feb 11, 2023

Describe the bug
The compiler crashes like this when compiling the module shown below:

Sub pass ssa_opt_private_append
beam_ssa_private_append_crash.erl: internal error in pass beam_ssa_opt:
exception error: no function clause matching beam_ssa_private_append:patch_literal_term([],[self],5) 
  in function  beam_ssa_private_append:patch_appends_ret/3 (beam_ssa_private_append.erl, line 462)
  in call from beam_ssa_private_append:patch_appends_f/5 (beam_ssa_private_append.erl, line 416)
  in call from beam_ssa_private_append:'-patch_appends/3-anonymous-2-'/3 (beam_ssa_private_append.erl, line 390)
  in call from maps:fold_1/4 (maps.erl, line 416)
  in call from beam_ssa_private_append:private_append/3 (beam_ssa_private_append.erl, line 72)
  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)

To Reproduce
Compile the following module:

-module(beam_ssa_private_append_crash).
-compile([export_all]).

foo() ->
    <<(bar(ok))/binary>>.

bar(#{}) ->
    [];
bar(_) ->
    <<>>.

Expected behavior
The compilation should succeed.

Affected versions
The current master branch.

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

bjorng commented Feb 11, 2023

@frej,

As a bonus, here is how the currently not covered line 548 in beam_ssa_private_append can be covered:

cover_beam_ssa_private_append_line_548() ->
    <<(try
           <<>> = ok
       catch
           throw:#{} ->
               <<>>;
           _  ->
               ok
       end)/binary>>.

@frej
Copy link
Contributor

frej commented Feb 11, 2023

@bjorng, is it ok if I look at this and #6848 on Monday?

@bjorng
Copy link
Contributor Author

bjorng commented Feb 11, 2023

@frej Yes, of course. It's not urgent. Sorry for not making that clear. Bug fixes for minor bugs will be included in the second release candidate, not the the first.

frej added a commit to frej/otp that referenced this issue Feb 15, 2023
Avoid a crash in the private-append optimization due to attempting to
rewrite a literal which isn't a bitstring.

As value tracking is done without type information, it can happen that
when following def chains, we encounter literals which are not
bitstrings. We should never schedule a literal which isn't a bitstring
for rewriting when the complete literal is what we are tracking,
i.e. when the element is `self`.

Closes erlang#6847
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