Skip to content

Commit

Permalink
fixup: compiler alias analysis: Avoid variable creation for plain values
Browse files Browse the repository at this point in the history
Extracting from a plain value is not possible, but the alias analysis
pass can sometimes encounter it when no type information is
available. Don't crash when trying to add an edge when trying to add
an edge recording the extraction when the source doesn't
exist. Instead conservatively set the result to aliased and leave the
source unchanged.
  • Loading branch information
frej committed Aug 2, 2024
1 parent 66280c7 commit 94cf118
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/compiler/src/beam_ssa_ss.erl
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ add_embedding(Dst, Src, Element, State0) ->
extract(Dst, Src, Element, State) ->
?DP("Extracting ~p[~p] into ~p~n", [Src,Element,Dst]),
?assert_state(State),
case beam_digraph:vertex(State, Src, unique) of
case beam_digraph:vertex(State, Src, plain) of
aliased ->
%% The pair/tuple is aliased, so what is extracted will be aliased.
?assert_state(set_status(Dst, aliased, State));
Expand All @@ -226,7 +226,13 @@ extract(Dst, Src, Element, State) ->
[Dst, Src, Element, OutEdges]),
extract_element(Dst, Src, Element, OutEdges, State);
no_info ->
?assert_state(set_status(Dst, no_info, State))
?assert_state(set_status(Dst, no_info, State));
plain ->
%% Extracting from a plain value is not possible, but the
%% alias analysis pass can sometimes encounter it when no
%% type information is available. Conservatively set the
%% result to aliased.
?assert_state(set_status(Dst, aliased, State))
end.

%% Note that extract_element/5 will never be given an out edge with a
Expand Down
5 changes: 5 additions & 0 deletions lib/compiler/test/beam_ssa_check_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
annotation_checks/1,
appendable_checks/1,
bs_size_unit_checks/1,
no_type_info_checks/1,
private_append_checks/1,
ret_annotation_checks/1,
sanity_checks/1,
Expand All @@ -47,6 +48,7 @@ groups() ->
[alias_checks,
annotation_checks,
appendable_checks,
no_type_info_checks,
private_append_checks,
ret_annotation_checks,
sanity_checks,
Expand Down Expand Up @@ -99,6 +101,9 @@ appendable_checks(Config) when is_list(Config) ->
bs_size_unit_checks(Config) when is_list(Config) ->
gen_and_run_post_ssa_opt(bs_size_unit_checks, Config).

no_type_info_checks(Config) when is_list(Config) ->
run_post_ssa_opt(no_type_info, Config).

private_append_checks(Config) when is_list(Config) ->
run_post_ssa_opt(private_append, Config).

Expand Down
48 changes: 48 additions & 0 deletions lib/compiler/test/beam_ssa_check_SUITE_data/no_type_info.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 2024. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%
%% %CopyrightEnd%
%%
%% This module tests functions which have previously crashed the
%% compiler when the `no_type_opt` option was used.
%%

-module(no_type_info).
-export([bug/0]).

-compile(no_type_opt).

bug() ->
begin
+ <<42 ||
$s <-
try
something
catch
error:false ->
[]
end
>>
end:(hd(not girl))(
try home of
_ when 34 ->
8
catch
_:_ ->
whatever
after
ok
end).

0 comments on commit 94cf118

Please sign in to comment.