Skip to content

Commit

Permalink
Merge pull request #7129 from bjorng/bjorn/compiler/beam_ssa_pre_code…
Browse files Browse the repository at this point in the history
…gen/GH-7128

Fix failure to load module with disabled optimizations
  • Loading branch information
bjorng authored Apr 19, 2023
2 parents e07aed3 + dedc07d commit 0f6032a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/compiler/src/beam_ssa_pre_codegen.erl
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ sanitize([L|Ls], InBlocks, Count0, Values0, Blocks0) ->
no_change ->
Blk = sanitize_last(Blk0, Values0),
Blocks1 = Blocks0#{L := Blk},
Blocks = sanitize_reachable(Blk0, Blocks1),
Blocks = sanitize_reachable(Blk, Blocks1),
sanitize(Ls, InBlocks, Count0, Values0, Blocks);
{Is,Last,Count,Values} ->
Blk1 = Blk0#b_blk{is=Is,last=Last},
Expand Down
15 changes: 15 additions & 0 deletions lib/compiler/test/beam_ssa_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
%% %CopyrightEnd%
%%
-module(beam_ssa_SUITE).
-feature(maybe_expr, enable).

-export([all/0,suite/0,groups/0,init_per_suite/1,end_per_suite/1,
init_per_group/2,end_per_group/2,
Expand Down Expand Up @@ -904,6 +905,8 @@ grab_bag(_Config) ->
6 = grab_bag_21(id(64)),
{'EXIT',{badarith,_}} = catch grab_bag_21(id(a)),

false = grab_bag_22(),

ok.

grab_bag_1() ->
Expand Down Expand Up @@ -1180,6 +1183,18 @@ grab_bag_21(A) ->
grab_bag_21(_, D, _, _) ->
D.

%% GH-7128: With optimizations disabled, the code would fail to
%% load with the following message:
%%
%% beam/beam_load.c(367): Error loading function
%% beam_ssa_no_opt_SUITE:grab_bag_22/0: op get_list: Sdd:
%% bad tag 2 for destination
grab_bag_22() ->
maybe
[_ | _] ?= ((true xor true) andalso foo),
bar ?= id(42)
end.

redundant_br(_Config) ->
{false,{x,y,z}} = redundant_br_1(id({x,y,z})),
{true,[[a,b,c]]} = redundant_br_1(id([[[a,b,c]]])),
Expand Down

0 comments on commit 0f6032a

Please sign in to comment.