From e59d9632b13d99fe9741219507e389996f18201e Mon Sep 17 00:00:00 2001 From: Daiva Naudziuniene Date: Wed, 28 Nov 2018 07:01:47 -0800 Subject: [PATCH] [Pulse] Improve example to illustrate FP caused by an allocation in a branch Summary: Recent improvements in join fixed `FP_allocate_in_branch_ok` because the variable was not read after the join. Reviewed By: mbouaziz Differential Revision: D13233441 fbshipit-source-id: 89b701e12 --- infer/tests/codetoanalyze/cpp/pulse/issues.exp | 1 + infer/tests/codetoanalyze/cpp/pulse/use_after_destructor.cpp | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/infer/tests/codetoanalyze/cpp/pulse/issues.exp b/infer/tests/codetoanalyze/cpp/pulse/issues.exp index 65d65c005..a10fe79fc 100644 --- a/infer/tests/codetoanalyze/cpp/pulse/issues.exp +++ b/infer/tests/codetoanalyze/cpp/pulse/issues.exp @@ -10,6 +10,7 @@ codetoanalyze/cpp/pulse/use_after_delete.cpp, reassign_field_of_deleted_bad, 3, codetoanalyze/cpp/pulse/use_after_delete.cpp, return_deleted_bad, 3, USE_AFTER_DELETE, no_bucket, ERROR, [invalidated by call to `delete s` at line 24, column 3 here,accessed `s` here] codetoanalyze/cpp/pulse/use_after_delete.cpp, use_in_branch_bad, 4, USE_AFTER_DELETE, no_bucket, ERROR, [invalidated by call to `delete s` at line 73, column 3 here,accessed `s` here] codetoanalyze/cpp/pulse/use_after_delete.cpp, use_in_loop_bad, 4, USE_AFTER_DELETE, no_bucket, ERROR, [invalidated by call to `delete s` at line 102, column 3 here,accessed `s->f` here] +codetoanalyze/cpp/pulse/use_after_destructor.cpp, use_after_destructor::FP_allocate_in_branch_ok, 10, USE_AFTER_DESTRUCTOR, no_bucket, ERROR, [invalidated by destructor call `std::unique_ptr>_~unique_ptr(a2)` at line 245, column 10 here,accessed `a1` here] codetoanalyze/cpp/pulse/use_after_destructor.cpp, use_after_destructor::double_destructor_bad, 5, USE_AFTER_DESTRUCTOR, no_bucket, ERROR, [invalidated by destructor call `use_after_destructor::S_~S(s)` at line 64, column 3 here,accessed `s` here] codetoanalyze/cpp/pulse/use_after_destructor.cpp, use_after_destructor::placement_new_aliasing1_bad, 5, USE_AFTER_DELETE, no_bucket, ERROR, [invalidated by call to `delete alias` at line 142, column 3 here,accessed `s` here] codetoanalyze/cpp/pulse/use_after_destructor.cpp, use_after_destructor::placement_new_aliasing2_bad, 5, USE_AFTER_DELETE, no_bucket, ERROR, [invalidated by call to `delete s` at line 150, column 3 here,accessed `alias` here] diff --git a/infer/tests/codetoanalyze/cpp/pulse/use_after_destructor.cpp b/infer/tests/codetoanalyze/cpp/pulse/use_after_destructor.cpp index a0c88c2cd..4f13ee2a4 100644 --- a/infer/tests/codetoanalyze/cpp/pulse/use_after_destructor.cpp +++ b/infer/tests/codetoanalyze/cpp/pulse/use_after_destructor.cpp @@ -232,7 +232,7 @@ void FP_destructor_order_empty_destructor_ok() { a.f = &b; } -void allocate_in_branch_ok(bool b) { +std::unique_ptr* FP_allocate_in_branch_ok(bool b) { std::unique_ptr a1; std::unique_ptr a2; std::unique_ptr* a3 = &a1; @@ -241,6 +241,8 @@ void allocate_in_branch_ok(bool b) { a2 = std::make_unique(*a1); a3 = &a2; } // current join makes a1 and a2 equal + + return a3; } // we get `use after destructor` for a1, after destructor call for a2 } // namespace use_after_destructor