aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler/src/cerl_inline.erl
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2018-03-22 12:38:39 +0100
committerBjörn Gustavsson <[email protected]>2018-03-23 14:57:30 +0100
commit43a91c5e461e3fbec924e332f42fd69b81be34b2 (patch)
tree15735351ba2f604f2a8590def44321d3f640442a /lib/compiler/src/cerl_inline.erl
parente48f59aff695e55c0150664a6cc4f441c1636a16 (diff)
downloadotp-43a91c5e461e3fbec924e332f42fd69b81be34b2.tar.gz
otp-43a91c5e461e3fbec924e332f42fd69b81be34b2.tar.bz2
otp-43a91c5e461e3fbec924e332f42fd69b81be34b2.zip
cerl_inline: Fix a name capture bug
The way variables created by make_template() are used, it is necessary that the names are unique in the entire function. This has not happened to cause any problems in the past because all other compiler passes created atom variable names, not integer variable names. If other passes start to create integer variable names, this bug is exposed.
Diffstat (limited to 'lib/compiler/src/cerl_inline.erl')
-rw-r--r--lib/compiler/src/cerl_inline.erl17
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/compiler/src/cerl_inline.erl b/lib/compiler/src/cerl_inline.erl
index f5afa75b16..caff47dbcb 100644
--- a/lib/compiler/src/cerl_inline.erl
+++ b/lib/compiler/src/cerl_inline.erl
@@ -1822,6 +1822,14 @@ new_var(Env) ->
Name = env__new_vname(Env),
c_var(Name).
+%% The way a template variable is used makes it necessary
+%% to make sure that it is unique in the entire function.
+%% Therefore, template variables are atoms with the prefix "@i".
+
+new_template_var(Env) ->
+ Name = env__new_tname(Env),
+ c_var(Name).
+
residualize_var(R, S) ->
S1 = count_size(weight(var), S),
{ref_to_var(R), st__set_var_referenced(R#ref.loc, S1)}.
@@ -2183,7 +2191,7 @@ make_template(E, Vs0, Env0) ->
T = make_data_skel(data_type(E), Ts),
E1 = update_data(E, data_type(E),
[hd(get_ann(T)) || T <- Ts]),
- V = new_var(Env1),
+ V = new_template_var(Env1),
Env2 = env__bind(var_name(V), E1, Env1),
{set_ann(T, [V]), [V | Vs1], Env2};
false ->
@@ -2198,7 +2206,7 @@ make_template(E, Vs0, Env0) ->
Env2 = env__bind(V, E1, Env1),
{T, Vs1, Env2};
_ ->
- V = new_var(Env0),
+ V = new_template_var(Env0),
Env1 = env__bind(var_name(V), E, Env0),
{set_ann(V, [V]), [V | Vs0], Env1}
end
@@ -2564,6 +2572,11 @@ env__is_defined(Key, Env) ->
env__new_vname(Env) ->
rec_env:new_key(Env).
+env__new_tname(Env) ->
+ rec_env:new_key(fun(I) ->
+ list_to_atom("@i"++integer_to_list(I))
+ end, Env).
+
env__new_fname(A, N, Env) ->
rec_env:new_key(fun (X) ->
S = integer_to_list(X),