From dedc07d6e600cb9b0c6cc89a862114a1ff071d85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Tue, 18 Apr 2023 07:20:50 +0200 Subject: [PATCH] Fix failure to load module with disabled optimizations Closes #7128 --- lib/compiler/src/beam_ssa_pre_codegen.erl | 2 +- lib/compiler/test/beam_ssa_SUITE.erl | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/compiler/src/beam_ssa_pre_codegen.erl b/lib/compiler/src/beam_ssa_pre_codegen.erl index e3406f12de78..dc76755aad99 100644 --- a/lib/compiler/src/beam_ssa_pre_codegen.erl +++ b/lib/compiler/src/beam_ssa_pre_codegen.erl @@ -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}, diff --git a/lib/compiler/test/beam_ssa_SUITE.erl b/lib/compiler/test/beam_ssa_SUITE.erl index f6b0eb29299e..6a91bdd7b82c 100644 --- a/lib/compiler/test/beam_ssa_SUITE.erl +++ b/lib/compiler/test/beam_ssa_SUITE.erl @@ -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, @@ -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() -> @@ -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]]])),