From f4b9bb3e3b483ff2a270399ac6735e9aa562dae9 Mon Sep 17 00:00:00 2001 From: Daiva Naudziuniene Date: Fri, 2 Jun 2017 06:26:13 -0700 Subject: [PATCH] [ThreadSafety] Do not report unprotected writes for c++. Reviewed By: jberdine Differential Revision: D5172030 fbshipit-source-id: 945acba --- infer/src/checkers/ThreadSafety.ml | 33 +++++++++++-------- .../codetoanalyze/cpp/threadsafety/issues.exp | 2 -- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/infer/src/checkers/ThreadSafety.ml b/infer/src/checkers/ThreadSafety.ml index 2567ce475..bd202f34e 100644 --- a/infer/src/checkers/ThreadSafety.ml +++ b/infer/src/checkers/ThreadSafety.ml @@ -1128,19 +1128,26 @@ let report_unsafe_accesses ~is_file_threadsafe aggregated_access_map = else match snd (TraceElem.kind access), pre with | Access.Write, AccessPrecondition.Unprotected _ -> - if threaded - then - reported_acc - else - begin - (* unprotected write. warn. *) - report_thread_safety_violation - tenv - pdesc - ~make_description:make_unprotected_write_description - access; - update_reported access pname reported_acc - end + begin + match Procdesc.get_proc_name pdesc with + | Java _ -> + if threaded + then + reported_acc + else + begin + (* unprotected write. warn. *) + report_thread_safety_violation + tenv + pdesc + ~make_description:make_unprotected_write_description + access; + update_reported access pname reported_acc + end + | _ -> + (* Do not report unprotected writes for ObjC_Cpp *) + reported_acc + end | Access.Write, AccessPrecondition.Protected _ -> (* protected write, do nothing *) reported_acc diff --git a/infer/tests/codetoanalyze/cpp/threadsafety/issues.exp b/infer/tests/codetoanalyze/cpp/threadsafety/issues.exp index 13fa8f951..82060295f 100644 --- a/infer/tests/codetoanalyze/cpp/threadsafety/issues.exp +++ b/infer/tests/codetoanalyze/cpp/threadsafety/issues.exp @@ -1,5 +1,3 @@ codetoanalyze/cpp/threadsafety/basics.cpp, basics::Basic_get2, 3, THREAD_SAFETY_VIOLATION, [access to `suspiciously_written`] codetoanalyze/cpp/threadsafety/basics.cpp, basics::Basic_get3, 0, THREAD_SAFETY_VIOLATION, [,access to `not_guarded`,,access to `not_guarded`] codetoanalyze/cpp/threadsafety/basics.cpp, basics::Basic_get4, 0, THREAD_SAFETY_VIOLATION, [,access to `suspiciously_read`,,access to `suspiciously_read`] -codetoanalyze/cpp/threadsafety/basics.cpp, basics::Basic_set, 1, THREAD_SAFETY_VIOLATION, [access to `not_guarded`] -codetoanalyze/cpp/threadsafety/basics.cpp, basics::Basic_set, 6, THREAD_SAFETY_VIOLATION, [access to `suspiciously_written`]