From ad09c1cda6881f4a8d8da6252e1ba57605db05d1 Mon Sep 17 00:00:00 2001 From: Akos Hajdu Date: Fri, 30 Jul 2021 06:17:10 -0700 Subject: [PATCH] [erl-frontend] Support bitwise not operation Summary: Add support for bitwise not (unary). Reviewed By: mmarescotti Differential Revision: D29968081 fbshipit-source-id: fddf2e9dc --- infer/src/erlang/ErlangTranslator.ml | 7 ++--- .../codetoanalyze/erlang/features/issues.exp | 2 ++ .../erlang/features/src/bitwise.erl | 30 ++++++++++++++++++- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/infer/src/erlang/ErlangTranslator.ml b/infer/src/erlang/ErlangTranslator.ml index 4edefab7a..24b845f7d 100644 --- a/infer/src/erlang/ErlangTranslator.ml +++ b/infer/src/erlang/ErlangTranslator.ml @@ -576,15 +576,12 @@ and translate_expression env {Ast.line; simple_expression} = in let op_block = match op with + | UBNot -> + make_simple_op_block BNot | UMinus -> make_simple_op_block Neg | UNot -> make_simple_op_block LNot - | todo -> - L.debug Capture Verbose - "@[todo ErlangTranslator.translate_expression(UnaryOperator) %s@." - (Sexp.to_string (Ast.sexp_of_unary_operator todo)) ; - Block.make_success env in Block.all env [block; op_block] | Variable vname -> diff --git a/infer/tests/codetoanalyze/erlang/features/issues.exp b/infer/tests/codetoanalyze/erlang/features/issues.exp index 4caf0040b..55886c773 100644 --- a/infer/tests/codetoanalyze/erlang/features/issues.exp +++ b/infer/tests/codetoanalyze/erlang/features/issues.exp @@ -20,6 +20,8 @@ codetoanalyze/erlang/features/src/bitwise.erl, test_bsr1_Bad/0, -107, NO_MATCHIN codetoanalyze/erlang/features/src/bitwise.erl, test_bsr2_Bad/0, -121, NO_MATCHING_FUNCTION_CLAUSE, no_bucket, ERROR, [calling context starts here,in call to `warn/1`,no matching function clause here] codetoanalyze/erlang/features/src/bitwise.erl, test_bxor1_Bad/0, -65, NO_MATCHING_FUNCTION_CLAUSE, no_bucket, ERROR, [calling context starts here,in call to `warn/1`,no matching function clause here] codetoanalyze/erlang/features/src/bitwise.erl, test_bxor2_Bad/0, -79, NO_MATCHING_FUNCTION_CLAUSE, no_bucket, ERROR, [calling context starts here,in call to `warn/1`,no matching function clause here] +codetoanalyze/erlang/features/src/bitwise.erl, test_ubnot1_Bad/0, -134, NO_MATCHING_FUNCTION_CLAUSE, no_bucket, ERROR, [calling context starts here,in call to `warn/1`,no matching function clause here] +codetoanalyze/erlang/features/src/bitwise.erl, test_ubnot2_Bad/0, -146, NO_MATCHING_FUNCTION_CLAUSE, no_bucket, ERROR, [calling context starts here,in call to `warn/1`,no matching function clause here] codetoanalyze/erlang/features/src/bitwise.erl, warn/1, 0, NO_MATCHING_FUNCTION_CLAUSE, no_bucket, ERROR, [*** LATENT ***,no matching function clause here] codetoanalyze/erlang/features/src/block.erl, test_block_Bad/0, -15, NO_MATCHING_FUNCTION_CLAUSE, no_bucket, ERROR, [calling context starts here,in call to `warn/1`,no matching function clause here] codetoanalyze/erlang/features/src/block.erl, warn/1, 0, NO_MATCHING_FUNCTION_CLAUSE, no_bucket, ERROR, [*** LATENT ***,no matching function clause here] diff --git a/infer/tests/codetoanalyze/erlang/features/src/bitwise.erl b/infer/tests/codetoanalyze/erlang/features/src/bitwise.erl index ab3b95aa5..1bbb1723a 100644 --- a/infer/tests/codetoanalyze/erlang/features/src/bitwise.erl +++ b/infer/tests/codetoanalyze/erlang/features/src/bitwise.erl @@ -23,7 +23,11 @@ test_bsr1_Ok/0, test_bsr1_Bad/0, test_bsr2_Ok/0, - test_bsr2_Bad/0 + test_bsr2_Bad/0, + test_ubnot1_Ok/0, + test_ubnot1_Bad/0, + test_ubnot2_Ok/0, + test_ubnot2_Bad/0 ]). % Call this method with warn(1) to trigger a warning to expect @@ -154,3 +158,27 @@ test_bsr2_Bad() -> case X bsr Y of 0 -> warn(1) end. + +test_ubnot1_Ok() -> + X = 1, + case bnot X of + -2 -> ok + end. + +test_ubnot1_Bad() -> + X = 1, + case bnot X of + -2 -> warn(1) + end. + +test_ubnot2_Ok() -> + X = 11, + case bnot X of + -12 -> ok + end. + +test_ubnot2_Bad() -> + X = 11, + case bnot X of + -12 -> warn(1) + end.