From 2c8d7a20462da76b9b1eaf1567508e078170257a Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Wed, 4 Jul 2018 08:52:53 -0700 Subject: [PATCH] [clang] support `SubstNonTypeTemplateParmExpr` Summary: These just point to expressions that we know how to translate. Fixes #950 Reviewed By: mbouaziz Differential Revision: D8713784 fbshipit-source-id: 9eafa39 --- infer/src/clang/cTrans.ml | 5 +++-- .../codetoanalyze/cpp/liveness/issues.exp | 2 ++ .../cpp/liveness/non_type_template_param.cpp | 22 +++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 infer/tests/codetoanalyze/cpp/liveness/non_type_template_param.cpp diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml index 64c41c893..4b2e6d22d 100644 --- a/infer/src/clang/cTrans.ml +++ b/infer/src/clang/cTrans.ml @@ -3417,10 +3417,11 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s sub-expressions *) | ObjCAvailabilityCheckExpr (_, _, expr_info, _) -> undefined_expr trans_state expr_info + | SubstNonTypeTemplateParmExpr (_, stmts, _) | SubstNonTypeTemplateParmPackExpr (_, stmts, _) -> + let[@warning "-8"] [expr] = stmts in + instruction trans_state expr (* Infer somehow ended up in templated non instantiated code - right now it's not supported and failure in those cases is expected. *) - | SubstNonTypeTemplateParmExpr ({Clang_ast_t.si_source_range}, _, _) - | SubstNonTypeTemplateParmPackExpr ({Clang_ast_t.si_source_range}, _, _) | CXXDependentScopeMemberExpr ({Clang_ast_t.si_source_range}, _, _) -> CFrontend_config.unimplemented __POS__ si_source_range ~ast_node:(Clang_ast_proj.get_stmt_kind_string instr) diff --git a/infer/tests/codetoanalyze/cpp/liveness/issues.exp b/infer/tests/codetoanalyze/cpp/liveness/issues.exp index 067a2fd94..302a6cc61 100644 --- a/infer/tests/codetoanalyze/cpp/liveness/issues.exp +++ b/infer/tests/codetoanalyze/cpp/liveness/issues.exp @@ -17,3 +17,5 @@ codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::plus_plus2_bad, 2, DEAD codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::plus_plus3_bad, 2, DEAD_STORE, no_bucket, ERROR, [Write of unused value] codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::reassign_param_bad, 0, DEAD_STORE, no_bucket, ERROR, [Write of unused value] codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::use_then_dead_bad, 3, DEAD_STORE, no_bucket, ERROR, [Write of unused value] +codetoanalyze/cpp/liveness/non_type_template_param.cpp, X<3>_isZeroBad, 1, DEAD_STORE, no_bucket, ERROR, [Write of unused value] +codetoanalyze/cpp/liveness/non_type_template_param.cpp, instanciateTemplateBad, 3, DEAD_STORE, no_bucket, ERROR, [Write of unused value] diff --git a/infer/tests/codetoanalyze/cpp/liveness/non_type_template_param.cpp b/infer/tests/codetoanalyze/cpp/liveness/non_type_template_param.cpp new file mode 100644 index 000000000..6f0d4da3a --- /dev/null +++ b/infer/tests/codetoanalyze/cpp/liveness/non_type_template_param.cpp @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2018-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +// see also https://github.com/facebook/infer/issues/950 + +template +struct X { + bool isZeroBad() { + int unused = 1; + return T == 0; + } +}; + +int instanciateTemplateBad() { + X<3> x; + x.isZeroBad(); + int unused = 1; + return 0; +}