diff options
| author | Björn Gustavsson <bjorn@erlang.org> | 2023-03-08 06:51:27 +0100 |
|---|---|---|
| committer | Björn Gustavsson <bjorn@erlang.org> | 2023-03-08 07:19:58 +0100 |
| commit | bb3cfdb32447f41ac2a27b7bd413434524b17b85 (patch) | |
| tree | a772ccf2ac5bcd7f0772ab364324e9a052919616 /lib/compiler | |
| parent | b07e0d167027432a83dc61c85305de5fcdada997 (diff) | |
| download | erlang-bb3cfdb32447f41ac2a27b7bd413434524b17b85.tar.gz | |
Eliminate assertion failure in beam_ssa_codegen
If the code in `?EXCEPTION_BLOCK` is modified in any way, the
`beam_ssa_codegen:assert_exception_block/1` function will cause an
internal compiler error. Ensure that the literal unfolding
optimization in `beam_ssa_opt` will not modify the code in
`?EXCEPTION_BLOCK`.
Diffstat (limited to 'lib/compiler')
| -rw-r--r-- | lib/compiler/src/beam_ssa_opt.erl | 2 | ||||
| -rw-r--r-- | lib/compiler/test/beam_except_SUITE.erl | 18 |
2 files changed, 18 insertions, 2 deletions
diff --git a/lib/compiler/src/beam_ssa_opt.erl b/lib/compiler/src/beam_ssa_opt.erl index 01e1fe2c6a..851573a82b 100644 --- a/lib/compiler/src/beam_ssa_opt.erl +++ b/lib/compiler/src/beam_ssa_opt.erl @@ -3022,6 +3022,8 @@ collect_arg_literals([V|Vs], Info, X, Acc0) -> collect_arg_literals([], _Info, _X, Acc) -> Acc. +unfold_literals([?EXCEPTION_BLOCK|Ls], LitMap, SafeMap, Blocks) -> + unfold_literals(Ls, LitMap, SafeMap,Blocks); unfold_literals([L|Ls], LitMap, SafeMap0, Blocks0) -> {Blocks,Safe} = case map_get(L, SafeMap0) of diff --git a/lib/compiler/test/beam_except_SUITE.erl b/lib/compiler/test/beam_except_SUITE.erl index 9a90c1b676..c52217ad79 100644 --- a/lib/compiler/test/beam_except_SUITE.erl +++ b/lib/compiler/test/beam_except_SUITE.erl @@ -22,7 +22,7 @@ -export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, init_per_group/2,end_per_group/2, multiple_allocs/1,bs_get_tail/1,coverage/1, - binary_construction_allocation/1]). + binary_construction_allocation/1,unfold_literals/1]). suite() -> [{ct_hooks,[ts_install_cth]}]. @@ -34,7 +34,8 @@ groups() -> [multiple_allocs, bs_get_tail, coverage, - binary_construction_allocation]}]. + binary_construction_allocation, + unfold_literals]}]. init_per_suite(Config) -> test_lib:recompile(?MODULE), @@ -177,6 +178,19 @@ do_binary_construction_allocation(Req) -> _ -> ok end. +unfold_literals(_Config) -> + a = do_unfold_literals(badarg, id({a,b})), + {'EXIT',{badarg,_}} = catch do_unfold_literals(badarg, id(a)), + + ok. + +do_unfold_literals(_BadArg, T) -> + %% The call `erlang:error(badarg)` in ?EXCEPTION_BLOCK would be + %% rewritten to `erlang:error(_BadArg)` by + %% beam_ssa_opt:unfold_literals/1, which would cause + %% beam_ssa_codegen:assert_exception_block/1 to fail. + element(1, T). + id(I) -> I. -file("fake.erl", 1). |
