diff options
author | Björn Gustavsson <[email protected]> | 2014-03-06 10:56:59 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2014-03-06 10:56:59 +0100 |
commit | cb5942909249958cd70f6247c4493db5aa6b8a5a (patch) | |
tree | 8418d6d8d92bc1321d6634e54f0d724cf132c18a | |
parent | 4273b07493a8d36c2cfc5f9c918cb7bd683732d0 (diff) | |
parent | b38151704e9c9bf74b38ffbd4a4d8f3b2840aacf (diff) | |
download | otp-cb5942909249958cd70f6247c4493db5aa6b8a5a.tar.gz otp-cb5942909249958cd70f6247c4493db5aa6b8a5a.tar.bz2 otp-cb5942909249958cd70f6247c4493db5aa6b8a5a.zip |
Merge branch 'nox/compiler/core_lint-call-guard'
* nox/compiler/core_lint-call-guard:
Properly lint calls in Core Erlang guards
-rw-r--r-- | lib/compiler/src/core_lint.erl | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/lib/compiler/src/core_lint.erl b/lib/compiler/src/core_lint.erl index 36165245a6..25df33a287 100644 --- a/lib/compiler/src/core_lint.erl +++ b/lib/compiler/src/core_lint.erl @@ -267,10 +267,21 @@ gexpr(#c_let{vars=Vs,arg=Arg,body=B}, Def, Rt, St0) -> St1 = gbody(Arg, Def, let_varcount(Vs), St0), %This is a guard body {Lvs,St2} = variable_list(Vs, St1), gbody(B, union(Lvs, Def), Rt, St2); -gexpr(#c_call{module=#c_literal{val=erlang}, - name=#c_literal{}, - args=As}, Def, 1, St) -> - gexpr_list(As, Def, St); +gexpr(#c_call{module=#c_literal{val=erlang},name=#c_literal{val=is_record}, + args=[Arg,#c_literal{val=Tag},#c_literal{val=Size}]}, + Def, 1, St) when is_atom(Tag), is_integer(Size) -> + gexpr(Arg, Def, 1, St); +gexpr(#c_call{module=#c_literal{val=erlang},name=#c_literal{val=is_record}}, + _Def, 1, St) -> + add_error({illegal_guard,St#lint.func}, St); +gexpr(#c_call{module=#c_literal{val=erlang},name=#c_literal{val=Name},args=As}, + Def, 1, St) when is_atom(Name) -> + case is_guard_bif(Name, length(As)) of + true -> + gexpr_list(As, Def, St); + false -> + add_error({illegal_guard,St#lint.func}, St) + end; gexpr(#c_primop{name=#c_literal{val=A},args=As}, Def, _Rt, St0) when is_atom(A) -> gexpr_list(As, Def, St0); gexpr(#c_try{arg=E,vars=[#c_var{name=X}],body=#c_var{name=X}, @@ -298,6 +309,14 @@ gbitstr_list(Es, Def, St0) -> gbitstr(#c_bitstr{val=V,size=S}, Def, St) -> gexpr_list([V,S], Def, St). +%% is_guard_bif(Name, Arity) -> Boolean. + +is_guard_bif(Name, Arity) -> + erl_internal:guard_bif(Name, Arity) + orelse erl_internal:arith_op(Name, Arity) + orelse erl_internal:bool_op(Name, Arity) + orelse erl_internal:comp_op(Name, Arity). + %% expr(Expr, Defined, RetCount, State) -> State. expr(#c_var{name={_,_}=FA}, Def, _Rt, St) -> |