diff --git a/facebook-clang-plugins b/facebook-clang-plugins index 1f77ff5f3..36266f6c8 160000 --- a/facebook-clang-plugins +++ b/facebook-clang-plugins @@ -1 +1 @@ -Subproject commit 1f77ff5f316a72aacdf9816ce36190a5d869a952 +Subproject commit 36266f6c86041896bed32ffec0637fefbc4463e0 diff --git a/infer/src/clang/ctl_parser_types.ml b/infer/src/clang/ctl_parser_types.ml index 6be18caa9..982f044e1 100644 --- a/infer/src/clang/ctl_parser_types.ml +++ b/infer/src/clang/ctl_parser_types.ml @@ -85,20 +85,23 @@ let rec ast_node_cxx_fully_qualified_name an = let open Clang_ast_t in match an with | Decl dec -> ( - match Clang_ast_proj.get_named_decl_tuple dec with - | Some (_, n) -> - fully_qualified_name n.Clang_ast_t.ni_qual_name + match Clang_ast_proj.get_var_decl_tuple dec with + | Some (_, ndi, _, {vdi_is_global= false}) -> + ndi.ni_name + | Some (_, ndi, _, _) -> + fully_qualified_name ndi.ni_qual_name + | None -> ( + match Clang_ast_proj.get_named_decl_tuple dec with + | Some (_, ndi) -> + fully_qualified_name ndi.ni_qual_name + | None -> + "" ) ) + | Stmt (DeclRefExpr (_, _, _, {drti_decl_ref= Some dr})) -> ( + match CAst_utils.get_decl dr.dr_decl_pointer with + | Some decl -> + ast_node_cxx_fully_qualified_name (Decl decl) | None -> "" ) - | Stmt (DeclRefExpr (_, _, _, {drti_decl_ref= Some dr})) -> - let ndi, _, _ = CAst_utils.get_info_from_decl_ref dr in - fully_qualified_name ndi.ni_qual_name - | Stmt (OpaqueValueExpr (_, _, _, {ovei_source_expr= Some stmt})) - | Stmt (ImplicitCastExpr (_, [stmt], _, _)) - | Stmt (PseudoObjectExpr (_, stmt :: _, _)) - | Stmt (ParenExpr (_, [stmt], _)) - | Stmt (CallExpr (_, stmt :: _, _)) -> - ast_node_cxx_fully_qualified_name (Stmt stmt) | _ -> "" diff --git a/infer/tests/codetoanalyze/cpp/linters-for-test-only/issues.exp b/infer/tests/codetoanalyze/cpp/linters-for-test-only/issues.exp index d99c6be16..9d7059508 100644 --- a/infer/tests/codetoanalyze/cpp/linters-for-test-only/issues.exp +++ b/infer/tests/codetoanalyze/cpp/linters-for-test-only/issues.exp @@ -1,5 +1,12 @@ codetoanalyze/cpp/linters-for-test-only/test_constructor.cpp, f, 12, FIND_STATIC_LOCAL_VAR, no_bucket, WARNING, [] codetoanalyze/cpp/linters-for-test-only/test_constructor.cpp, g, 17, FIND_CXX_COPY_CONSTRUCTOR, no_bucket, WARNING, [] +codetoanalyze/cpp/linters-for-test-only/test_fully_qualified_names.cpp, Foo::Bar_f, 26, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, [] +codetoanalyze/cpp/linters-for-test-only/test_fully_qualified_names.cpp, Foo::Bar_f, 28, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, [] +codetoanalyze/cpp/linters-for-test-only/test_fully_qualified_names.cpp, Foo::Bar_f, 29, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, [] +codetoanalyze/cpp/linters-for-test-only/test_fully_qualified_names.cpp, Linters_dummy_method, 22, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, [] +codetoanalyze/cpp/linters-for-test-only/test_fully_qualified_names.cpp, Linters_dummy_method, 24, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, [] +codetoanalyze/cpp/linters-for-test-only/test_fully_qualified_names.cpp, Linters_dummy_method, 25, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, [] +codetoanalyze/cpp/linters-for-test-only/test_fully_qualified_names.cpp, Linters_dummy_method, 33, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, [] codetoanalyze/cpp/linters-for-test-only/test_included.h, Bazoo_fibble, 11, FIND_CXX_METHODS_FROM_HEADER_FILE, no_bucket, WARNING, [] codetoanalyze/cpp/linters-for-test-only/test_overrides.cpp, B_bar, 16, FIND_CXX_METHOD_OVERRIDES, no_bucket, WARNING, [] codetoanalyze/cpp/linters-for-test-only/test_overrides.cpp, B_foo, 14, FIND_CXX_METHOD_OVERRIDES, no_bucket, WARNING, [] diff --git a/infer/tests/codetoanalyze/cpp/linters-for-test-only/test_fully_qualified_names.cpp b/infer/tests/codetoanalyze/cpp/linters-for-test-only/test_fully_qualified_names.cpp new file mode 100644 index 000000000..c62d55adc --- /dev/null +++ b/infer/tests/codetoanalyze/cpp/linters-for-test-only/test_fully_qualified_names.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2019-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. + */ + +int globalVarInTopNs; + +namespace { + +int globalVarInAnonNs; + +struct Baz { + int fld_; +}; + +} // namespace + +namespace Foo { + +int globalVarInFoo; + +class Bar : public Baz { + static int classVar; + int f(const Baz& baz) { + label: + return baz.fld_ + fld_ + barFld_ + classVar + globalVarInTopNs + + globalVarInAnonNs + globalVarInFoo; + } + + private: + int barFld_; +}; + +} // namespace Foo