aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2015-03-17 10:20:52 +0100
committerBjörn Gustavsson <[email protected]>2015-03-17 10:22:19 +0100
commit9e07ede3f954bdfc6af9f82c1b8261e38b8d857c (patch)
tree739c6703df0dec0781cfddd8c4e140c0e5b85647 /lib
parent408c7dc8922a123aad815a24a27d7ff24971a253 (diff)
downloadotp-9e07ede3f954bdfc6af9f82c1b8261e38b8d857c.tar.gz
otp-9e07ede3f954bdfc6af9f82c1b8261e38b8d857c.tar.bz2
otp-9e07ede3f954bdfc6af9f82c1b8261e38b8d857c.zip
PER, UPER: Eliminate compiler warning for SeqPrim.asn1
The BEAM compiler now warns more aggressively for expressions whose values are not used. For example, the generated Erlang code for the following ASN.1 code will now cause a warning: Seq ::= SEQUENCE { ..., os OCTET STRING (SIZE (17000..30000)) } The generated Erlang code looks similar to the following: Enc9@bin = iolist_to_binary(Enc9@output), Enc9@len = byte_size(Enc9@bin), [align|encode_fragmented(Enc9@bin, 8)] The variable Enc9@len is not used and the BEAM compiler will complain that the value returned from the byte_size/1 call is not used. Improve the optimization of the intermediate code to eliminate the assignment to the unused variable.
Diffstat (limited to 'lib')
-rw-r--r--lib/asn1/src/asn1ct_imm.erl33
1 files changed, 23 insertions, 10 deletions
diff --git a/lib/asn1/src/asn1ct_imm.erl b/lib/asn1/src/asn1ct_imm.erl
index 91820e08de..5bf69e9294 100644
--- a/lib/asn1/src/asn1ct_imm.erl
+++ b/lib/asn1/src/asn1ct_imm.erl
@@ -1922,16 +1922,7 @@ enc_opt(nil, St) ->
enc_opt({seq,H0,T0}, St0) ->
{H,St1} = enc_opt(H0, St0),
{T,St} = enc_opt(T0, St1),
- case {H,T} of
- {none,_} ->
- {T,St};
- {{list,Imm,Data},
- {seq,{call,per,complete,[Data],_},_}} ->
- %% Get rid of any explicit 'align' added by per_enc_open_type/2.
- {{seq,{list,remove_trailing_align(Imm),Data},T},St};
- {_,_} ->
- {{seq,H,T},St}
- end;
+ {enc_opt_seq(H, T),St};
enc_opt({set,_,_}=Imm, St) ->
{Imm,St#ost{t=undefined}};
enc_opt({sub,Src0,Int,Dst}, St0) ->
@@ -1965,6 +1956,28 @@ remove_trailing_align({seq,H,T}) ->
{seq,H,remove_trailing_align(T)};
remove_trailing_align(Imm) -> Imm.
+enc_opt_seq(none, T) ->
+ T;
+enc_opt_seq({list,Imm,Data}, {seq,{call,per,complete,[Data],_},_}=T) ->
+ %% Get rid of any explicit 'align' added by per_enc_open_type/2.
+ {seq,{list,remove_trailing_align(Imm),Data},T};
+enc_opt_seq({call,_,_,_,{var,_}=Dst}=H, T) ->
+ case is_var_unused(Dst, T) of
+ false -> {seq,H,T};
+ true -> T
+ end;
+enc_opt_seq(H, T) ->
+ {seq,H,T}.
+
+is_var_unused(_, align) ->
+ true;
+is_var_unused(V, {call,_,_,Args}) ->
+ not lists:member(V, Args);
+is_var_unused(V, {cons,H,T}) ->
+ is_var_unused(V, H) andalso is_var_unused(V, T);
+is_var_unused(_, _) ->
+ false.
+
bit_size_propagate(Bin, Type, St) ->
case t_range(Type) of
any ->