From 31a6aba3c2ba43a1bd0ce291d157b0ff2e2dd671 Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Tue, 25 Apr 2017 00:28:45 -0700 Subject: [PATCH] [siof] enable SIOF checker only when new --siof option is passed Summary: As an interprocedural checker, SIOF should not run unless explicitly required. Make it a new type of analyzer like other similar checkers. Reviewed By: mbouaziz Differential Revision: D4937820 fbshipit-source-id: a9e2d38 --- Makefile | 2 +- infer/src/backend/InferPrint.re | 1 + infer/src/backend/infer.ml | 3 ++- infer/src/base/Config.ml | 23 +++++++++++++------ infer/src/base/Config.mli | 6 +++-- infer/src/checkers/registerCheckers.ml | 2 +- infer/src/integration/Buck.ml | 2 +- infer/tests/build_systems/j1/Makefile | 2 +- .../codetoanalyze/cpp/checkers/issues.exp | 10 -------- .../cpp/{checkers => siof}/Makefile | 2 +- infer/tests/codetoanalyze/cpp/siof/issues.exp | 10 ++++++++ .../cpp/{checkers => siof}/siof/const.cpp | 0 .../cpp/{checkers => siof}/siof/const_use.cpp | 0 .../siof/pod_across_translation_units-1.cpp | 0 .../siof/pod_across_translation_units-2.cpp | 0 .../siof/pod_same_translation_unit.cpp | 0 .../cpp/{checkers => siof}/siof/siof.cpp | 0 .../siof/siof_different_tu.cpp | 0 .../siof/siof_templated.cpp | 0 .../cpp/{checkers => siof}/siof/siof_types.h | 0 .../siof/std_ios_base_init.cpp | 0 21 files changed, 38 insertions(+), 25 deletions(-) delete mode 100644 infer/tests/codetoanalyze/cpp/checkers/issues.exp rename infer/tests/codetoanalyze/cpp/{checkers => siof}/Makefile (98%) create mode 100644 infer/tests/codetoanalyze/cpp/siof/issues.exp rename infer/tests/codetoanalyze/cpp/{checkers => siof}/siof/const.cpp (100%) rename infer/tests/codetoanalyze/cpp/{checkers => siof}/siof/const_use.cpp (100%) rename infer/tests/codetoanalyze/cpp/{checkers => siof}/siof/pod_across_translation_units-1.cpp (100%) rename infer/tests/codetoanalyze/cpp/{checkers => siof}/siof/pod_across_translation_units-2.cpp (100%) rename infer/tests/codetoanalyze/cpp/{checkers => siof}/siof/pod_same_translation_unit.cpp (100%) rename infer/tests/codetoanalyze/cpp/{checkers => siof}/siof/siof.cpp (100%) rename infer/tests/codetoanalyze/cpp/{checkers => siof}/siof/siof_different_tu.cpp (100%) rename infer/tests/codetoanalyze/cpp/{checkers => siof}/siof/siof_templated.cpp (100%) rename infer/tests/codetoanalyze/cpp/{checkers => siof}/siof/siof_types.h (100%) rename infer/tests/codetoanalyze/cpp/{checkers => siof}/siof/std_ios_base_init.cpp (100%) diff --git a/Makefile b/Makefile index 040d73f6b..da2ccccea 100644 --- a/Makefile +++ b/Makefile @@ -32,7 +32,7 @@ BUILD_SYSTEMS_TESTS += \ DIRECT_TESTS += \ c_bufferoverrun c_errors c_frontend \ - cpp_bufferoverrun cpp_checkers cpp_errors cpp_frontend cpp_quandary \ + cpp_bufferoverrun cpp_errors cpp_frontend cpp_quandary cpp_siof \ ifneq ($(BUCK),no) BUILD_SYSTEMS_TESTS += buck-clang-db diff --git a/infer/src/backend/InferPrint.re b/infer/src/backend/InferPrint.re index 30c9d7f39..aeec64b4a 100644 --- a/infer/src/backend/InferPrint.re +++ b/infer/src/backend/InferPrint.re @@ -271,6 +271,7 @@ let should_report (issue_kind: Exceptions.err_kind) issue_type error_desc eclass switch Config.analyzer { | Checkers | Eradicate + | Siof | Tracing => true | Bufferoverrun | Capture diff --git a/infer/src/backend/infer.ml b/infer/src/backend/infer.ml index bd29567e6..e3c014baa 100644 --- a/infer/src/backend/infer.ml +++ b/infer/src/backend/infer.ml @@ -375,7 +375,8 @@ let analyze driver_mode = false, false | _, (Capture | Compile) -> false, false - | _, (Infer | Eradicate | Checkers | Tracing | Crashcontext | Quandary | Threadsafety | Bufferoverrun) -> + | _, (Infer | Eradicate | Checkers | Tracing | Crashcontext | Quandary | Siof | Threadsafety + | Bufferoverrun) -> true, true | _, Linters -> false, true in diff --git a/infer/src/base/Config.ml b/infer/src/base/Config.ml index e5482f74a..e88531a67 100644 --- a/infer/src/base/Config.ml +++ b/infer/src/base/Config.ml @@ -36,8 +36,9 @@ let exe_name = let frontend_parse_modes = CLOpt.(Infer [Clang]) type analyzer = - Capture | Compile | Infer | Eradicate | Checkers | Tracing | Crashcontext | Linters | Quandary - | Threadsafety | Bufferoverrun [@@deriving compare] + | Capture | Compile | Infer | Eradicate | Checkers | Tracing | Crashcontext | Linters | Quandary + | Siof | Threadsafety | Bufferoverrun +[@@deriving compare] let equal_analyzer = [%compare.equal : analyzer] @@ -45,7 +46,7 @@ let string_to_analyzer = [("capture", Capture); ("compile", Compile); ("infer", Infer); ("eradicate", Eradicate); ("checkers", Checkers); ("tracing", Tracing); ("crashcontext", Crashcontext); ("linters", Linters); - ("quandary", Quandary); ("threadsafety", Threadsafety); + ("quandary", Quandary); ("siof", Siof); ("threadsafety", Threadsafety); ("bufferoverrun", Bufferoverrun)] let string_of_analyzer a = @@ -479,7 +480,7 @@ and analyzer = (* NOTE: if compilation fails here, it means you have added a new analyzer without updating the documentation of this option *) | Capture | Compile | Infer | Eradicate | Checkers | Tracing | Crashcontext | Linters - | Quandary | Threadsafety | Bufferoverrun -> () in + | Quandary | Siof | Threadsafety | Bufferoverrun -> () in CLOpt.mk_symbol_opt ~deprecated:["analyzer"] ~long:"analyzer" ~short:'a' ~parse_mode:CLOpt.(Infer [Driver]) "Specify which analyzer to run (only one at a time is supported):\n\ @@ -487,7 +488,8 @@ and analyzer = - capture: run capture phase only (no analysis)\n\ - compile: run compilation command without interfering (not supported by all frontends)\n\ - crashcontext, tracing: experimental (see --crashcontext and --tracing)\n\ - - linters: run linters based on the ast only (Objective-C and Objective-C++ only)" + - linters: run linters based on the ast only (Objective-C and Objective-C++ only)\n\ + - siof: check for Static Initialization Order Fiasco (C++ only)" ~symbols:string_to_analyzer and android_harness = @@ -585,7 +587,7 @@ and changed_files_index = start. Source files should be specified relative to project root or be absolute" and bufferoverrun, checkers, checkers_repeated_calls, - crashcontext, eradicate, quandary, threadsafety = + crashcontext, eradicate, quandary, siof, threadsafety = let checkers = CLOpt.mk_bool ~deprecated:["checkers"] ~long:"checkers" "Activate the checkers instead of the full analysis" @@ -615,13 +617,18 @@ and bufferoverrun, checkers, checkers_repeated_calls, "Activate the quandary taint analysis" [checkers] [] in + let siof = + CLOpt.mk_bool_group ~long:"siof" + "Activate the Static Initialization Order Fiasco analysis" + [checkers] [] + in let threadsafety = CLOpt.mk_bool_group ~deprecated:["threadsafety"] ~long:"threadsafety" "Activate the thread safety analysis" [checkers] [] in (bufferoverrun, checkers, checkers_repeated_calls, - crashcontext, eradicate, quandary, threadsafety) + crashcontext, eradicate, quandary, siof, threadsafety) and clang_biniou_file = CLOpt.mk_path_opt ~long:"clang-biniou-file" ~parse_mode:CLOpt.(Infer [Clang]) ~meta:"file" @@ -1537,6 +1544,7 @@ let post_parsing_initialization () = | Some Quandary -> checkers := true; quandary := true | Some Threadsafety -> checkers := true; threadsafety := true | Some Bufferoverrun -> checkers := true; bufferoverrun := true + | Some Siof -> checkers := true; siof := true | Some Tracing -> tracing := true | Some (Capture | Compile | Infer | Linters) | None -> () @@ -1727,6 +1735,7 @@ and save_analysis_results = !save_results and seconds_per_iteration = !seconds_per_iteration and show_buckets = !print_buckets and show_progress_bar = !progress_bar +and siof = !siof and siof_safe_methods = !siof_safe_methods and skip_analysis_in_path = !skip_analysis_in_path and skip_duplicated_types = !skip_duplicated_types diff --git a/infer/src/base/Config.mli b/infer/src/base/Config.mli index e3314b922..78023237a 100644 --- a/infer/src/base/Config.mli +++ b/infer/src/base/Config.mli @@ -19,8 +19,9 @@ val exe_name : exe -> string (** Various kind of analyzers *) type analyzer = - Capture | Compile | Infer | Eradicate | Checkers | Tracing | Crashcontext | Linters | Quandary - | Threadsafety | Bufferoverrun [@@deriving compare] + | Capture | Compile | Infer | Eradicate | Checkers | Tracing | Crashcontext | Linters | Quandary + | Siof | Threadsafety | Bufferoverrun +[@@deriving compare] val equal_analyzer : analyzer -> analyzer -> bool @@ -315,6 +316,7 @@ val save_analysis_results : string option val seconds_per_iteration : float option val show_buckets : bool val show_progress_bar : bool +val siof : bool val siof_safe_methods : string list val skip_analysis_in_path : string list val skip_duplicated_types : bool diff --git a/infer/src/checkers/registerCheckers.ml b/infer/src/checkers/registerCheckers.ml index 2b3d6c1f7..146ab8cd9 100644 --- a/infer/src/checkers/registerCheckers.ml +++ b/infer/src/checkers/registerCheckers.ml @@ -51,7 +51,7 @@ let active_procedure_checkers () = CheckDeadCode.callback_check_dead_code, false; Checkers.callback_print_access_to_globals, false; ClangTaintAnalysis.checker, Config.quandary; - Siof.checker, Config.checkers_enabled; + Siof.checker, Config.siof; BufferOverrunChecker.checker, Config.bufferoverrun; ] in List.map ~f:(fun (x, y) -> (x, y, Some Config.Clang)) l in diff --git a/infer/src/integration/Buck.ml b/infer/src/integration/Buck.ml index d08f403dc..656e4f44a 100644 --- a/infer/src/integration/Buck.ml +++ b/infer/src/integration/Buck.ml @@ -53,7 +53,7 @@ let add_flavor_to_target target = add "infer-capture-all" | None, (Checkers | Infer) -> add "infer" - | None, (Eradicate | Tracing | Crashcontext | Quandary | Threadsafety | Bufferoverrun) -> + | None, (Eradicate | Tracing | Crashcontext | Quandary | Siof | Threadsafety | Bufferoverrun) -> failwithf "Unsupported infer analyzer with Buck flavors: %s" (Config.string_of_analyzer Config.analyzer) diff --git a/infer/tests/build_systems/j1/Makefile b/infer/tests/build_systems/j1/Makefile index 6cbac2f01..28951a26d 100644 --- a/infer/tests/build_systems/j1/Makefile +++ b/infer/tests/build_systems/j1/Makefile @@ -12,4 +12,4 @@ default: compile .PHONY: print replace test clean print replace test clean: - $(QUIET)INFER_ARGS=-j^1 $(MAKE) -C ../../codetoanalyze/cpp/checkers TEST_SUFFIX=-j1 $@ + $(QUIET)INFER_ARGS=-j^1 $(MAKE) -C ../../codetoanalyze/cpp/siof TEST_SUFFIX=-j1 $@ diff --git a/infer/tests/codetoanalyze/cpp/checkers/issues.exp b/infer/tests/codetoanalyze/cpp/checkers/issues.exp deleted file mode 100644 index b93d9b66d..000000000 --- a/infer/tests/codetoanalyze/cpp/checkers/issues.exp +++ /dev/null @@ -1,10 +0,0 @@ -codetoanalyze/cpp/checkers/siof/siof.cpp, __infer_globals_initializer_X::static_pod_accesses_non_pod, 0, STATIC_INITIALIZATION_ORDER_FIASCO, [initialization of X::static_pod_accesses_non_pod,call to access_to_non_pod,access to global_object2,access to some_other_global_object2] -codetoanalyze/cpp/checkers/siof/siof.cpp, __infer_globals_initializer_another_global_object, 0, STATIC_INITIALIZATION_ORDER_FIASCO, [initialization of another_global_object,call to SomeOtherNonPODObject_SomeOtherNonPODObject,access to extern_global_object] -codetoanalyze/cpp/checkers/siof/siof.cpp, __infer_globals_initializer_another_global_object2, 0, STATIC_INITIALIZATION_ORDER_FIASCO, [initialization of another_global_object2,call to access_to_non_pod,access to global_object2,access to some_other_global_object2] -codetoanalyze/cpp/checkers/siof/siof.cpp, __infer_globals_initializer_another_global_object3, 0, STATIC_INITIALIZATION_ORDER_FIASCO, [initialization of another_global_object3,call to access_to_templated_non_pod,access to global_object3] -codetoanalyze/cpp/checkers/siof/siof.cpp, __infer_globals_initializer_initWithGlobal, 0, STATIC_INITIALIZATION_ORDER_FIASCO, [initialization of initWithGlobal,call to getGlobalNonPOD,access to some_other_global_object2,access to global_object2] -codetoanalyze/cpp/checkers/siof/siof.cpp, __infer_globals_initializer_pod_accesses_non_pod, 0, STATIC_INITIALIZATION_ORDER_FIASCO, [initialization of pod_accesses_non_pod,call to access_to_non_pod,access to global_object2,access to some_other_global_object2] -codetoanalyze/cpp/checkers/siof/siof_templated.cpp, __infer_globals_initializer_another_templated_global_object, 0, STATIC_INITIALIZATION_ORDER_FIASCO, [initialization of another_templated_global_object,call to SomeOtherTemplatedNonPODObject<_Bool>_SomeOtherTemplatedNonPODObject,access to extern_global_object] -codetoanalyze/cpp/checkers/siof/siof_templated.cpp, __infer_globals_initializer_another_templated_global_object2, 0, STATIC_INITIALIZATION_ORDER_FIASCO, [initialization of another_templated_global_object2,call to access_to_non_pod,access to global_object2,access to some_other_global_object2] -codetoanalyze/cpp/checkers/siof/siof_templated.cpp, __infer_globals_initializer_another_templated_global_object3, 0, STATIC_INITIALIZATION_ORDER_FIASCO, [initialization of another_templated_global_object3,call to access_to_templated_non_pod,access to global_object3] -codetoanalyze/cpp/checkers/siof/std_ios_base_init.cpp, __infer_globals_initializer_global_bad_std_cerr_access, 0, STATIC_INITIALIZATION_ORDER_FIASCO, [initialization of global_bad_std_cerr_access,call to return_4_SIOF,call to printing_SIOF,access to std::cerr] diff --git a/infer/tests/codetoanalyze/cpp/checkers/Makefile b/infer/tests/codetoanalyze/cpp/siof/Makefile similarity index 98% rename from infer/tests/codetoanalyze/cpp/checkers/Makefile rename to infer/tests/codetoanalyze/cpp/siof/Makefile index aa6b8906a..d5532d2c7 100644 --- a/infer/tests/codetoanalyze/cpp/checkers/Makefile +++ b/infer/tests/codetoanalyze/cpp/siof/Makefile @@ -7,7 +7,7 @@ TESTS_DIR = ../../.. -ANALYZER = checkers +ANALYZER = siof # see explanations in cpp/errors/Makefile for the custom isystem CLANG_OPTIONS = -x c++ -std=c++11 -nostdinc++ -isystem$(MODELS_DIR)/cpp/include -isystem$(CLANG_INCLUDES)/c++/v1/ -c INFER_OPTIONS = --ml-buckets cpp --no-filtering --debug-exceptions --project-root $(TESTS_DIR) --no-failures-allowed diff --git a/infer/tests/codetoanalyze/cpp/siof/issues.exp b/infer/tests/codetoanalyze/cpp/siof/issues.exp new file mode 100644 index 000000000..2a65071ab --- /dev/null +++ b/infer/tests/codetoanalyze/cpp/siof/issues.exp @@ -0,0 +1,10 @@ +codetoanalyze/cpp/siof/siof/siof.cpp, __infer_globals_initializer_X::static_pod_accesses_non_pod, 0, STATIC_INITIALIZATION_ORDER_FIASCO, [initialization of X::static_pod_accesses_non_pod,call to access_to_non_pod,access to global_object2,access to some_other_global_object2] +codetoanalyze/cpp/siof/siof/siof.cpp, __infer_globals_initializer_another_global_object, 0, STATIC_INITIALIZATION_ORDER_FIASCO, [initialization of another_global_object,call to SomeOtherNonPODObject_SomeOtherNonPODObject,access to extern_global_object] +codetoanalyze/cpp/siof/siof/siof.cpp, __infer_globals_initializer_another_global_object2, 0, STATIC_INITIALIZATION_ORDER_FIASCO, [initialization of another_global_object2,call to access_to_non_pod,access to global_object2,access to some_other_global_object2] +codetoanalyze/cpp/siof/siof/siof.cpp, __infer_globals_initializer_another_global_object3, 0, STATIC_INITIALIZATION_ORDER_FIASCO, [initialization of another_global_object3,call to access_to_templated_non_pod,access to global_object3] +codetoanalyze/cpp/siof/siof/siof.cpp, __infer_globals_initializer_initWithGlobal, 0, STATIC_INITIALIZATION_ORDER_FIASCO, [initialization of initWithGlobal,call to getGlobalNonPOD,access to some_other_global_object2,access to global_object2] +codetoanalyze/cpp/siof/siof/siof.cpp, __infer_globals_initializer_pod_accesses_non_pod, 0, STATIC_INITIALIZATION_ORDER_FIASCO, [initialization of pod_accesses_non_pod,call to access_to_non_pod,access to global_object2,access to some_other_global_object2] +codetoanalyze/cpp/siof/siof/siof_templated.cpp, __infer_globals_initializer_another_templated_global_object, 0, STATIC_INITIALIZATION_ORDER_FIASCO, [initialization of another_templated_global_object,call to SomeOtherTemplatedNonPODObject<_Bool>_SomeOtherTemplatedNonPODObject,access to extern_global_object] +codetoanalyze/cpp/siof/siof/siof_templated.cpp, __infer_globals_initializer_another_templated_global_object2, 0, STATIC_INITIALIZATION_ORDER_FIASCO, [initialization of another_templated_global_object2,call to access_to_non_pod,access to global_object2,access to some_other_global_object2] +codetoanalyze/cpp/siof/siof/siof_templated.cpp, __infer_globals_initializer_another_templated_global_object3, 0, STATIC_INITIALIZATION_ORDER_FIASCO, [initialization of another_templated_global_object3,call to access_to_templated_non_pod,access to global_object3] +codetoanalyze/cpp/siof/siof/std_ios_base_init.cpp, __infer_globals_initializer_global_bad_std_cerr_access, 0, STATIC_INITIALIZATION_ORDER_FIASCO, [initialization of global_bad_std_cerr_access,call to return_4_SIOF,call to printing_SIOF,access to std::cerr] diff --git a/infer/tests/codetoanalyze/cpp/checkers/siof/const.cpp b/infer/tests/codetoanalyze/cpp/siof/siof/const.cpp similarity index 100% rename from infer/tests/codetoanalyze/cpp/checkers/siof/const.cpp rename to infer/tests/codetoanalyze/cpp/siof/siof/const.cpp diff --git a/infer/tests/codetoanalyze/cpp/checkers/siof/const_use.cpp b/infer/tests/codetoanalyze/cpp/siof/siof/const_use.cpp similarity index 100% rename from infer/tests/codetoanalyze/cpp/checkers/siof/const_use.cpp rename to infer/tests/codetoanalyze/cpp/siof/siof/const_use.cpp diff --git a/infer/tests/codetoanalyze/cpp/checkers/siof/pod_across_translation_units-1.cpp b/infer/tests/codetoanalyze/cpp/siof/siof/pod_across_translation_units-1.cpp similarity index 100% rename from infer/tests/codetoanalyze/cpp/checkers/siof/pod_across_translation_units-1.cpp rename to infer/tests/codetoanalyze/cpp/siof/siof/pod_across_translation_units-1.cpp diff --git a/infer/tests/codetoanalyze/cpp/checkers/siof/pod_across_translation_units-2.cpp b/infer/tests/codetoanalyze/cpp/siof/siof/pod_across_translation_units-2.cpp similarity index 100% rename from infer/tests/codetoanalyze/cpp/checkers/siof/pod_across_translation_units-2.cpp rename to infer/tests/codetoanalyze/cpp/siof/siof/pod_across_translation_units-2.cpp diff --git a/infer/tests/codetoanalyze/cpp/checkers/siof/pod_same_translation_unit.cpp b/infer/tests/codetoanalyze/cpp/siof/siof/pod_same_translation_unit.cpp similarity index 100% rename from infer/tests/codetoanalyze/cpp/checkers/siof/pod_same_translation_unit.cpp rename to infer/tests/codetoanalyze/cpp/siof/siof/pod_same_translation_unit.cpp diff --git a/infer/tests/codetoanalyze/cpp/checkers/siof/siof.cpp b/infer/tests/codetoanalyze/cpp/siof/siof/siof.cpp similarity index 100% rename from infer/tests/codetoanalyze/cpp/checkers/siof/siof.cpp rename to infer/tests/codetoanalyze/cpp/siof/siof/siof.cpp diff --git a/infer/tests/codetoanalyze/cpp/checkers/siof/siof_different_tu.cpp b/infer/tests/codetoanalyze/cpp/siof/siof/siof_different_tu.cpp similarity index 100% rename from infer/tests/codetoanalyze/cpp/checkers/siof/siof_different_tu.cpp rename to infer/tests/codetoanalyze/cpp/siof/siof/siof_different_tu.cpp diff --git a/infer/tests/codetoanalyze/cpp/checkers/siof/siof_templated.cpp b/infer/tests/codetoanalyze/cpp/siof/siof/siof_templated.cpp similarity index 100% rename from infer/tests/codetoanalyze/cpp/checkers/siof/siof_templated.cpp rename to infer/tests/codetoanalyze/cpp/siof/siof/siof_templated.cpp diff --git a/infer/tests/codetoanalyze/cpp/checkers/siof/siof_types.h b/infer/tests/codetoanalyze/cpp/siof/siof/siof_types.h similarity index 100% rename from infer/tests/codetoanalyze/cpp/checkers/siof/siof_types.h rename to infer/tests/codetoanalyze/cpp/siof/siof/siof_types.h diff --git a/infer/tests/codetoanalyze/cpp/checkers/siof/std_ios_base_init.cpp b/infer/tests/codetoanalyze/cpp/siof/siof/std_ios_base_init.cpp similarity index 100% rename from infer/tests/codetoanalyze/cpp/checkers/siof/std_ios_base_init.cpp rename to infer/tests/codetoanalyze/cpp/siof/siof/std_ios_base_init.cpp