From ef26e8bb28b9cb564cff12a0bece3ad01170dcec Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Wed, 10 Jul 2019 04:08:24 -0700 Subject: [PATCH] [clang] NamespaceAliasDecl is just a no-op Summary: Fixes #1123. Reviewed By: mbouaziz, ngorogiannis Differential Revision: D16163589 fbshipit-source-id: 10d2d8010 --- infer/src/clang/cTrans.ml | 3 ++- .../codetoanalyze/cpp/pulse/frontend.cpp | 24 +++++++++++++++++++ .../tests/codetoanalyze/cpp/pulse/issues.exp | 1 + 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 infer/tests/codetoanalyze/cpp/pulse/frontend.cpp diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml index cb2ba4a49..0ce85078d 100644 --- a/infer/src/clang/cTrans.ml +++ b/infer/src/clang/cTrans.ml @@ -2404,7 +2404,8 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s match (decl_list : Clang_ast_t.decl list) with | VarDecl _ :: _ | CXXRecordDecl _ :: _ | RecordDecl _ :: _ -> collect_all_decl trans_state decl_list succ_nodes stmt_info - | (TypedefDecl _ | TypeAliasDecl _ | UsingDecl _ | UsingDirectiveDecl _) :: _ -> + | (NamespaceAliasDecl _ | TypedefDecl _ | TypeAliasDecl _ | UsingDecl _ | UsingDirectiveDecl _) + :: _ -> mk_trans_result (mk_fresh_void_exp_typ ()) empty_control | decl :: _ -> CFrontend_config.unimplemented __POS__ stmt_info.Clang_ast_t.si_source_range diff --git a/infer/tests/codetoanalyze/cpp/pulse/frontend.cpp b/infer/tests/codetoanalyze/cpp/pulse/frontend.cpp new file mode 100644 index 000000000..99bf91cc1 --- /dev/null +++ b/infer/tests/codetoanalyze/cpp/pulse/frontend.cpp @@ -0,0 +1,24 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +namespace some { +namespace thing { +using foo_int = int; +int* bad_ptr() { + int* p = new (int); + delete p; + return p; +} +} // namespace thing +} // namespace some + +// test that NamespaceAliasDecl is handled correctly +void deref_null_namespace_alias_ptr_bad() { + namespace st = some::thing; + st::foo_int x = 0; + int* p = st::bad_ptr(); + *p = x; +} diff --git a/infer/tests/codetoanalyze/cpp/pulse/issues.exp b/infer/tests/codetoanalyze/cpp/pulse/issues.exp index a148b68cc..acf642d05 100644 --- a/infer/tests/codetoanalyze/cpp/pulse/issues.exp +++ b/infer/tests/codetoanalyze/cpp/pulse/issues.exp @@ -10,6 +10,7 @@ codetoanalyze/cpp/pulse/deduplication.cpp, deduplication::SomeTemplatedClass, 3, USE_AFTER_DELETE, no_bucket, ERROR, [invalidation part of the trace starts here,when calling `deduplication::templated_delete_function` here,memory was invalidated by `delete` here,use-after-lifetime part of the trace starts here,assigned,when calling `deduplication::templated_access_function` here,invalid access occurs here here] codetoanalyze/cpp/pulse/deduplication.cpp, deduplication::templated_function_bad, 3, USE_AFTER_DELETE, no_bucket, ERROR, [invalidation part of the trace starts here,when calling `deduplication::templated_delete_function` here,memory was invalidated by `delete` here,use-after-lifetime part of the trace starts here,assigned,when calling `deduplication::templated_access_function` here,invalid access occurs here here] codetoanalyze/cpp/pulse/folly_DestructorGuard.cpp, UsingDelayedDestruction::double_delete_bad, 2, USE_AFTER_DELETE, no_bucket, ERROR, [invalidation part of the trace starts here,memory was invalidated by `delete` here,use-after-lifetime part of the trace starts here,invalid access occurs here here] +codetoanalyze/cpp/pulse/frontend.cpp, deref_null_namespace_alias_ptr_bad, 4, USE_AFTER_DELETE, no_bucket, ERROR, [invalidation part of the trace starts here,assigned,when calling `some::thing::bad_ptr()` here,memory was invalidated by `delete` here,use-after-lifetime part of the trace starts here,returned from call to `some::thing::bad_ptr()`,assigned,invalid access occurs here here] codetoanalyze/cpp/pulse/interprocedural.cpp, access_to_invalidated_alias, 3, USE_AFTER_DELETE, no_bucket, ERROR, [invalidation part of the trace starts here,when calling `invalidate_and_set_to_null()` here,memory was invalidated by `delete` here,use-after-lifetime part of the trace starts here,assigned,when calling `wraps_read()` here,when calling `wraps_read_inner()` here,invalid access occurs here here] codetoanalyze/cpp/pulse/interprocedural.cpp, delete_aliased_then_read_bad, 4, USE_AFTER_DELETE, no_bucket, ERROR, [invalidation part of the trace starts here,assigned,memory was invalidated by `delete` here,use-after-lifetime part of the trace starts here,assigned,when calling `wraps_read()` here,when calling `wraps_read_inner()` here,invalid access occurs here here] codetoanalyze/cpp/pulse/interprocedural.cpp, delete_inner_then_write_bad, 2, USE_AFTER_DELETE, no_bucket, ERROR, [invalidation part of the trace starts here,when calling `wraps_delete_inner()` here,memory was invalidated by `delete` here,use-after-lifetime part of the trace starts here,when calling `wraps_read()` here,when calling `wraps_read_inner()` here,invalid access occurs here here]