From 6a395859997086bd4b176c537f30575571a1ead2 Mon Sep 17 00:00:00 2001 From: Sam Blackshear Date: Thu, 23 Mar 2017 10:09:20 -0700 Subject: [PATCH] [thread-safety] treat non-interface methods with no summary as angelic Reviewed By: jeremydubreil Differential Revision: D4758609 fbshipit-source-id: fa56bd5 --- infer/src/checkers/ThreadSafety.ml | 9 +++++--- infer/src/opensource/FbThreadSafety.ml | 2 -- .../java/threadsafety/.inferconfig | 8 ++++++- .../java/threadsafety/Ownership.java | 5 +++++ .../java/threadsafety/SkippedClass.java | 22 +++++++++++++++++++ 5 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 infer/tests/codetoanalyze/java/threadsafety/SkippedClass.java diff --git a/infer/src/checkers/ThreadSafety.ml b/infer/src/checkers/ThreadSafety.ml index fdf5b60c1..370f3bdb6 100644 --- a/infer/src/checkers/ThreadSafety.ml +++ b/infer/src/checkers/ThreadSafety.ml @@ -392,7 +392,7 @@ module TransferFunctions (CFG : ProcCfg.S) = struct lhs_access_path target_exp target_typ ~f_resolve_id astate.attribute_map extras in { astate with attribute_map; } - | Sil.Call (ret_opt, Const (Cfun callee_pname), actuals, loc, _) -> + | Sil.Call (ret_opt, Const (Cfun callee_pname), actuals, loc, call_flags) -> let astate_callee = (* assuming that modeled procedures do not have useful summaries *) if is_thread_utils_method "assertMainThread" callee_pname then @@ -500,6 +500,10 @@ module TransferFunctions (CFG : ProcCfg.S) = struct extras in { astate with locks; threads; accesses; attribute_map; } | None -> + let should_assume_returns_ownership (call_flags : CallFlags.t) actuals = + (* assume non-interface methods with no summary and no parameters return + ownership *) + not (call_flags.cf_interface) && List.is_empty actuals in if is_box callee_pname then match ret_opt, actuals with @@ -520,9 +524,8 @@ module TransferFunctions (CFG : ProcCfg.S) = struct end | _ -> astate - else if FbThreadSafety.is_graphql_constructor callee_pname + else if should_assume_returns_ownership call_flags actuals then - (* assume generated GraphQL code returns ownership *) match ret_opt with | Some (ret_id, ret_typ) -> let attribute_map = diff --git a/infer/src/opensource/FbThreadSafety.ml b/infer/src/opensource/FbThreadSafety.ml index 0ab3001f1..d949237f0 100644 --- a/infer/src/opensource/FbThreadSafety.ml +++ b/infer/src/opensource/FbThreadSafety.ml @@ -12,5 +12,3 @@ open! IStd let is_custom_init _ _ = false let is_logging_method _ = false - -let is_graphql_constructor _ = false diff --git a/infer/tests/codetoanalyze/java/threadsafety/.inferconfig b/infer/tests/codetoanalyze/java/threadsafety/.inferconfig index be9c7530b..c60f430a4 100644 --- a/infer/tests/codetoanalyze/java/threadsafety/.inferconfig +++ b/infer/tests/codetoanalyze/java/threadsafety/.inferconfig @@ -1,3 +1,9 @@ { - "threadsafe-aliases": ["MyThreadSafeAlias1", "codetoanalyze.java.checkers.MyThreadSafeAlias2"] + "threadsafe-aliases": ["MyThreadSafeAlias1", "codetoanalyze.java.checkers.MyThreadSafeAlias2"], + "skip-translation": [ + { + "language": "Java", + "source_contains": "_SHOULD_BE_SKIPPED_" + } + ] } diff --git a/infer/tests/codetoanalyze/java/threadsafety/Ownership.java b/infer/tests/codetoanalyze/java/threadsafety/Ownership.java index 1ff2c4dc6..664b791de 100644 --- a/infer/tests/codetoanalyze/java/threadsafety/Ownership.java +++ b/infer/tests/codetoanalyze/java/threadsafety/Ownership.java @@ -371,6 +371,11 @@ public class Ownership { o.f = new Object(); } + void ownInSkippedCodeOk() { + SkippedClass c = SkippedClass.returnOwned(); + c.f = new Object(); + } + } diff --git a/infer/tests/codetoanalyze/java/threadsafety/SkippedClass.java b/infer/tests/codetoanalyze/java/threadsafety/SkippedClass.java new file mode 100644 index 000000000..efc144ad4 --- /dev/null +++ b/infer/tests/codetoanalyze/java/threadsafety/SkippedClass.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2015 - present Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +// _SHOULD_BE_SKIPPED_ + +package codetoanalyze.java.checkers; + +public class SkippedClass { + + Object f; + + public static SkippedClass returnOwned() { + return new SkippedClass(); + } + +}