From be53bc80e2c622c9dc3fdd7330f4b965926563e3 Mon Sep 17 00:00:00 2001 From: Dulma Churchill Date: Wed, 7 Mar 2018 06:20:30 -0800 Subject: [PATCH] [lieveness] Fix false positive to do with a _Generic expression not being translated properly Reviewed By: sblackshear Differential Revision: D7169156 fbshipit-source-id: ab79bf9 --- facebook-clang-plugins | 2 +- infer/src/clang/cFrontend_config.ml | 2 ++ infer/src/clang/cFrontend_config.mli | 2 ++ infer/src/clang/cTrans.ml | 13 +++++++++++-- .../c/frontend/unusual_exps/generic_exp.c.dot | 4 ++-- .../objc/liveness/GenericExprExample.m | 14 ++++++++++++++ 6 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 infer/tests/codetoanalyze/objc/liveness/GenericExprExample.m diff --git a/facebook-clang-plugins b/facebook-clang-plugins index 5f64a6842..9d03cb460 160000 --- a/facebook-clang-plugins +++ b/facebook-clang-plugins @@ -1 +1 @@ -Subproject commit 5f64a6842e9a85fc222f9a436c3d993cacb891b3 +Subproject commit 9d03cb460a30ad02d7b5edfa38f3a1143e642cfe diff --git a/infer/src/clang/cFrontend_config.ml b/infer/src/clang/cFrontend_config.ml index 8c4bfb7f4..a5306cf6e 100644 --- a/infer/src/clang/cFrontend_config.ml +++ b/infer/src/clang/cFrontend_config.ml @@ -93,6 +93,8 @@ let infer_skip_fun = "__infer_skip_function" let infer_skip_gcc_asm_stmt = "__infer_skip_gcc_asm_stmt" +let infer_generic_selection_expr = "__infer_generic_selection_expr" + let init = "init" let is_kind_of_class = "isKindOfClass:" diff --git a/infer/src/clang/cFrontend_config.mli b/infer/src/clang/cFrontend_config.mli index 84a9ed21c..9e88c9419 100644 --- a/infer/src/clang/cFrontend_config.mli +++ b/infer/src/clang/cFrontend_config.mli @@ -88,6 +88,8 @@ val infer_skip_fun : string val infer_skip_gcc_asm_stmt : string +val infer_generic_selection_expr : string + val init : string val is_kind_of_class : string diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml index c9fe6c786..85fddc9ad 100644 --- a/infer/src/clang/cTrans.ml +++ b/infer/src/clang/cTrans.ml @@ -2943,6 +2943,11 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s call_function_with_args "GCCAsmStmt" pname trans_state + and genericSelectionExprUnknown_trans trans_state = + let pname = Typ.Procname.from_string_c_fun CFrontend_config.infer_generic_selection_expr in + call_function_with_args "GenericSelectionExpr" pname trans_state + + and objc_cxx_throw_trans trans_state = call_function_with_args "ObjCCPPThrow" BuiltinDecl.objc_cpp_throw trans_state @@ -3272,8 +3277,12 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s cxxDefaultExpr_trans trans_state default_expr_info | ImplicitValueInitExpr (stmt_info, _, _) -> implicitValueInitExpr_trans trans_state stmt_info - | GenericSelectionExpr _ - (* to be fixed when we dump the right info in the ast *) + | GenericSelectionExpr (stmt_info, stmts, _, gse_info) -> ( + match gse_info.gse_value with + | Some value -> + instruction trans_state value + | None -> + genericSelectionExprUnknown_trans trans_state stmt_info stmts ) | SizeOfPackExpr _ -> {empty_res_trans with exps= [(Exp.get_undefined false, Typ.mk Tvoid)]} | GCCAsmStmt (stmt_info, stmts) -> diff --git a/infer/tests/codetoanalyze/c/frontend/unusual_exps/generic_exp.c.dot b/infer/tests/codetoanalyze/c/frontend/unusual_exps/generic_exp.c.dot index a0b2fb524..e963c5788 100644 --- a/infer/tests/codetoanalyze/c/frontend/unusual_exps/generic_exp.c.dot +++ b/infer/tests/codetoanalyze/c/frontend/unusual_exps/generic_exp.c.dot @@ -7,11 +7,11 @@ digraph cfg { "test_typename.b2359812ef4a83b4e2638a11e6c522b3_2" [label="2: Exit test_typename \n " color=yellow style=filled] -"test_typename.b2359812ef4a83b4e2638a11e6c522b3_3" [label="3: DeclStmt \n *&z:void=_t$0 [line 16, column 3]\n " shape="box"] +"test_typename.b2359812ef4a83b4e2638a11e6c522b3_3" [label="3: DeclStmt \n *&z:int=3 [line 16, column 3]\n " shape="box"] "test_typename.b2359812ef4a83b4e2638a11e6c522b3_3" -> "test_typename.b2359812ef4a83b4e2638a11e6c522b3_2" ; -"test_typename.b2359812ef4a83b4e2638a11e6c522b3_4" [label="4: DeclStmt \n *&x:void=_t$1 [line 15, column 3]\n " shape="box"] +"test_typename.b2359812ef4a83b4e2638a11e6c522b3_4" [label="4: DeclStmt \n *&x:int=2 [line 15, column 3]\n " shape="box"] "test_typename.b2359812ef4a83b4e2638a11e6c522b3_4" -> "test_typename.b2359812ef4a83b4e2638a11e6c522b3_3" ; diff --git a/infer/tests/codetoanalyze/objc/liveness/GenericExprExample.m b/infer/tests/codetoanalyze/objc/liveness/GenericExprExample.m new file mode 100644 index 000000000..4e832df50 --- /dev/null +++ b/infer/tests/codetoanalyze/objc/liveness/GenericExprExample.m @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2018 - present Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +#import + +static float generic_expr_ok() { + NSString* currentValue = [NSString new]; + return _Generic(0.2f, float : [currentValue floatValue]); +};