diff --git a/infer/man/man1/infer-analyze.txt b/infer/man/man1/infer-analyze.txt index 3c067c510..ea677cabb 100644 --- a/infer/man/man1/infer-analyze.txt +++ b/infer/man/man1/infer-analyze.txt @@ -72,6 +72,10 @@ OPTIONS Activates: Enable cost and disable all other checkers (Conversely: --no-cost-only) + --no-cost-suppress-func-ptr + Deactivates: Suppress printing function pointers in cost reports + (Conversely: --cost-suppress-func-ptr) + --custom-symbols json Specify named lists of symbols available to rules diff --git a/infer/man/man1/infer-full.txt b/infer/man/man1/infer-full.txt index bb37fc27e..0a08a3827 100644 --- a/infer/man/man1/infer-full.txt +++ b/infer/man/man1/infer-full.txt @@ -279,6 +279,10 @@ OPTIONS Activates: Enable cost and disable all other checkers (Conversely: --no-cost-only) See also infer-analyze(1). + --no-cost-suppress-func-ptr + Deactivates: Suppress printing function pointers in cost reports + (Conversely: --cost-suppress-func-ptr) See also infer-analyze(1). + --cost-tests-only-autoreleasepool Activates: [EXPERIMENTAL] Report only autoreleasepool size results in cost tests (Conversely: --no-cost-tests-only-autoreleasepool) diff --git a/infer/man/man1/infer.txt b/infer/man/man1/infer.txt index 7065d3daa..40c4da9ae 100644 --- a/infer/man/man1/infer.txt +++ b/infer/man/man1/infer.txt @@ -279,6 +279,10 @@ OPTIONS Activates: Enable cost and disable all other checkers (Conversely: --no-cost-only) See also infer-analyze(1). + --no-cost-suppress-func-ptr + Deactivates: Suppress printing function pointers in cost reports + (Conversely: --cost-suppress-func-ptr) See also infer-analyze(1). + --cost-tests-only-autoreleasepool Activates: [EXPERIMENTAL] Report only autoreleasepool size results in cost tests (Conversely: --no-cost-tests-only-autoreleasepool) diff --git a/infer/src/base/Config.ml b/infer/src/base/Config.ml index b2710e3a6..c6d4595ce 100644 --- a/infer/src/base/Config.ml +++ b/infer/src/base/Config.ml @@ -945,6 +945,12 @@ and costs_previous = "Costs report of the base revision to use for comparison" +and cost_suppress_func_ptr = + CLOpt.mk_bool ~default:true ~long:"cost-suppress-func-ptr" + ~in_help:InferCommand.[(Analyze, manual_generic)] + "Suppress printing function pointers in cost reports" + + and cost_tests_only_autoreleasepool = CLOpt.mk_bool ~long:"cost-tests-only-autoreleasepool" ~in_help:InferCommand.[(Report, manual_generic); (ReportDiff, manual_generic)] @@ -2753,6 +2759,8 @@ and cost_scuba_logging = !cost_scuba_logging and costs_previous = !costs_previous +and cost_suppress_func_ptr = !cost_suppress_func_ptr + and cost_tests_only_autoreleasepool = !cost_tests_only_autoreleasepool and cxx = !cxx diff --git a/infer/src/base/Config.mli b/infer/src/base/Config.mli index f7b8eb32a..ab4ad54f4 100644 --- a/infer/src/base/Config.mli +++ b/infer/src/base/Config.mli @@ -232,6 +232,8 @@ val cost_scuba_logging : bool val costs_previous : string option +val cost_suppress_func_ptr : bool + val cost_tests_only_autoreleasepool : bool val cxx : bool diff --git a/infer/src/bufferoverrun/polynomials.ml b/infer/src/bufferoverrun/polynomials.ml index 63e90ac30..36926589e 100644 --- a/infer/src/bufferoverrun/polynomials.ml +++ b/infer/src/bufferoverrun/polynomials.ml @@ -132,6 +132,8 @@ module NonNegativeNonTopPolynomial = struct let pp = pp_hum ~hum:true + + let is_func_ptr = function FuncPtr _ -> true | NonNegativeBoundWithDegreeKind _ -> false end module M = struct @@ -513,23 +515,20 @@ module NonNegativeNonTopPolynomial = struct Above s_trace + let rec is_zero_degree_poly {const; terms} = + NonNegativeInt.is_zero const && is_zero_degree_terms terms + + + and is_zero_degree_terms terms = + M.for_all (fun key v -> Key.is_func_ptr key || is_zero_degree_poly v) terms + + (** Emit a pair (d,t) where d is the degree of the polynomial and t is the first term with such degree. When calculating the degree, it ignores symbols of function pointer, so they are addressed as if zero cost. *) let degree_with_term {poly; autoreleasepool_trace} = - let rec is_func_ptr_poly {const; terms} = - NonNegativeInt.is_zero const - && M.for_all - (fun key v -> - match key with - | FuncPtr _ -> - true - | NonNegativeBoundWithDegreeKind _ -> - is_func_ptr_poly v ) - terms - in let rec degree_with_term_poly ({terms} as poly) = - if is_func_ptr_poly poly then (Degree.zero, true, poly) + if is_zero_degree_poly poly then (Degree.zero, true, poly) else M.fold (fun t p cur_max -> @@ -584,19 +583,28 @@ module NonNegativeNonTopPolynomial = struct in ( M.fold (fun s p print_plus -> - pp_sub ~hum ~print_plus (add_symb s symbs) fmt p ; - true ) + if Config.cost_suppress_func_ptr && (Key.is_func_ptr s || is_zero_degree_poly p) then + print_plus + else ( + pp_sub ~hum ~print_plus (add_symb s symbs) fmt p ; + true ) ) terms print_plus : bool ) |> ignore in fun ~hum fmt {const; terms} -> let const_not_zero = not (NonNegativeInt.is_zero const) in - if const_not_zero || M.is_empty terms then NonNegativeInt.pp fmt const ; + if + const_not_zero || M.is_empty terms + || (Config.cost_suppress_func_ptr && is_zero_degree_terms terms) + then NonNegativeInt.pp fmt const ; ( M.fold (fun s p print_plus -> - pp_sub ~hum ~print_plus ((s, PositiveInt.one), []) fmt p ; - true ) + if Config.cost_suppress_func_ptr && (Key.is_func_ptr s || is_zero_degree_poly p) then + print_plus + else ( + pp_sub ~hum ~print_plus ((s, PositiveInt.one), []) fmt p ; + true ) ) terms const_not_zero : bool ) |> ignore diff --git a/infer/tests/build_systems/differential_of_costs_report_java/Makefile b/infer/tests/build_systems/differential_of_costs_report_java/Makefile index 2d0316125..6cba13811 100644 --- a/infer/tests/build_systems/differential_of_costs_report_java/Makefile +++ b/infer/tests/build_systems/differential_of_costs_report_java/Makefile @@ -20,10 +20,12 @@ $(CURRENT_REPORT): $(QUIET)$(COPY) src/DiffExample.current.java src/DiffExample.java $(QUIET)$(COPY) src/DiffExampleUIThread.current.java src/DiffExampleUIThread.java $(QUIET)$(call silent_on_success,Testing Cost Differential: current,\ - $(INFER_BIN) --no-filtering --cost-only -o $(CURRENT_DIR) -- $(JAVAC) -cp $(CLASSPATH) $(COPIED)) + $(INFER_BIN) --no-filtering --cost-only --no-cost-suppress-func-ptr -o $(CURRENT_DIR) \ + -- $(JAVAC) -cp $(CLASSPATH) $(COPIED)) $(PREVIOUS_REPORT): $(QUIET)$(COPY) src/DiffExample.previous.java src/DiffExample.java $(QUIET)$(COPY) src/DiffExampleUIThread.previous.java src/DiffExampleUIThread.java $(QUIET)$(call silent_on_success,Testing Cost Differential: previous,\ - $(INFER_BIN) --debug --no-filtering --cost-only -o $(PREVIOUS_DIR) -- $(JAVAC) -cp $(CLASSPATH) $(COPIED)) + $(INFER_BIN) --debug --no-filtering --cost-only --no-cost-suppress-func-ptr -o $(PREVIOUS_DIR) \ + -- $(JAVAC) -cp $(CLASSPATH) $(COPIED)) diff --git a/infer/tests/build_systems/differential_of_costs_report_objc/Makefile b/infer/tests/build_systems/differential_of_costs_report_objc/Makefile index a254afbd8..2f885144f 100644 --- a/infer/tests/build_systems/differential_of_costs_report_objc/Makefile +++ b/infer/tests/build_systems/differential_of_costs_report_objc/Makefile @@ -20,9 +20,11 @@ $(CURRENT_REPORT) $(PREVIOUS_REPORT): $(OBJC_DEPS) $(CURRENT_REPORT): $(QUIET)$(COPY) src/DiffBlock.current.m src/DiffBlock.m $(QUIET)$(call silent_on_success,Testing Cost Differential: current,\ - $(INFER_BIN) --no-filtering --cost-only -o $(CURRENT_DIR) -- clang $(CLANG_OPTIONS) $(COPIED)) + $(INFER_BIN) --no-filtering --cost-only --no-cost-suppress-func-ptr -o $(CURRENT_DIR) \ + -- clang $(CLANG_OPTIONS) $(COPIED)) $(PREVIOUS_REPORT): $(QUIET)$(COPY) src/DiffBlock.previous.m src/DiffBlock.m $(QUIET)$(call silent_on_success,Testing Cost Differential: previous,\ - $(INFER_BIN) --debug --no-filtering --cost-only -o $(PREVIOUS_DIR) -- clang $(CLANG_OPTIONS) $(COPIED)) + $(INFER_BIN) --debug --no-filtering --cost-only --no-cost-suppress-func-ptr -o $(PREVIOUS_DIR) \ + -- clang $(CLANG_OPTIONS) $(COPIED)) diff --git a/infer/tests/codetoanalyze/c/performance/Makefile b/infer/tests/codetoanalyze/c/performance/Makefile index f527b6d2d..80b8bf73f 100644 --- a/infer/tests/codetoanalyze/c/performance/Makefile +++ b/infer/tests/codetoanalyze/c/performance/Makefile @@ -6,7 +6,8 @@ TESTS_DIR = ../../.. CLANG_OPTIONS = -c -INFER_OPTIONS = --cost-only --bufferoverrun --debug-exceptions --project-root $(TESTS_DIR) +INFER_OPTIONS = --cost-only --bufferoverrun --debug-exceptions --project-root $(TESTS_DIR) \ + --no-cost-suppress-func-ptr INFERPRINT_OPTIONS = --issues-tests INFERPRINT_COST_OPTIONS = --cost-issues-tests diff --git a/infer/tests/codetoanalyze/cpp/performance/Makefile b/infer/tests/codetoanalyze/cpp/performance/Makefile index 6209fa66e..eaf576948 100644 --- a/infer/tests/codetoanalyze/cpp/performance/Makefile +++ b/infer/tests/codetoanalyze/cpp/performance/Makefile @@ -8,7 +8,8 @@ TESTS_DIR = ../../.. # see explanations in cpp/biabduction/Makefile for the custom isystem CLANG_OPTIONS = -x c++ -std=c++11 -nostdinc++ -isystem$(CLANG_INCLUDES)/c++/v1/ -c INFER_OPTIONS = --cost-only --ml-buckets cpp --no-filtering --debug-exceptions \ - --project-root $(TESTS_DIR) --report-force-relative-path --debug + --project-root $(TESTS_DIR) --report-force-relative-path --debug \ + --no-cost-suppress-func-ptr INFERPRINT_OPTIONS = --issues-tests INFERPRINT_COST_OPTIONS = --cost-issues-tests diff --git a/infer/tests/codetoanalyze/java/performance-exclusive/Makefile b/infer/tests/codetoanalyze/java/performance-exclusive/Makefile index 1ecb233df..e332e932e 100644 --- a/infer/tests/codetoanalyze/java/performance-exclusive/Makefile +++ b/infer/tests/codetoanalyze/java/performance-exclusive/Makefile @@ -5,7 +5,8 @@ TESTS_DIR = ../../.. -INFER_OPTIONS = --cost-only --no-inclusive-cost --bufferoverrun --debug-exceptions +INFER_OPTIONS = --cost-only --no-inclusive-cost --bufferoverrun --debug-exceptions \ + --no-cost-suppress-func-ptr INFERPRINT_OPTIONS = --issues-tests INFERPRINT_COST_OPTIONS = --cost-issues-tests SOURCES = $(wildcard *.java) diff --git a/infer/tests/codetoanalyze/java/performance/Makefile b/infer/tests/codetoanalyze/java/performance/Makefile index 4d5f60f3f..e2c0b4ffe 100644 --- a/infer/tests/codetoanalyze/java/performance/Makefile +++ b/infer/tests/codetoanalyze/java/performance/Makefile @@ -5,7 +5,7 @@ TESTS_DIR = ../../.. -INFER_OPTIONS = --cost-only --bufferoverrun --debug-exceptions +INFER_OPTIONS = --cost-only --bufferoverrun --debug-exceptions --no-cost-suppress-func-ptr INFERPRINT_OPTIONS = --issues-tests INFERPRINT_COST_OPTIONS = --cost-issues-tests SOURCES = $(wildcard *.java) diff --git a/infer/tests/codetoanalyze/objc/autoreleasepool/Makefile b/infer/tests/codetoanalyze/objc/autoreleasepool/Makefile index d57b2a6c5..d10bf880d 100644 --- a/infer/tests/codetoanalyze/objc/autoreleasepool/Makefile +++ b/infer/tests/codetoanalyze/objc/autoreleasepool/Makefile @@ -7,7 +7,8 @@ TESTS_DIR = ../../.. CLANG_OPTIONS = -c $(OBJC_CLANG_OPTIONS) INFER_OPTIONS = --cost-only --debug-exceptions --project-root $(TESTS_DIR) \ - --report-force-relative-path --xcode-isysroot-suffix $(XCODE_ISYSROOT_SUFFIX) + --report-force-relative-path --xcode-isysroot-suffix $(XCODE_ISYSROOT_SUFFIX) \ + --no-cost-suppress-func-ptr INFERPRINT_OPTIONS = --issues-tests INFERPRINT_COST_OPTIONS = --cost-tests-only-autoreleasepool --cost-issues-tests diff --git a/infer/tests/codetoanalyze/objc/performance/Makefile b/infer/tests/codetoanalyze/objc/performance/Makefile index 68ef1eced..66e06859d 100644 --- a/infer/tests/codetoanalyze/objc/performance/Makefile +++ b/infer/tests/codetoanalyze/objc/performance/Makefile @@ -7,7 +7,8 @@ TESTS_DIR = ../../.. CLANG_OPTIONS = -c $(OBJC_CLANG_OPTIONS) INFER_OPTIONS = --cost-only --bufferoverrun --debug-exceptions --project-root $(TESTS_DIR) \ - --report-force-relative-path --xcode-isysroot-suffix $(XCODE_ISYSROOT_SUFFIX) + --report-force-relative-path --xcode-isysroot-suffix $(XCODE_ISYSROOT_SUFFIX) \ + --no-cost-suppress-func-ptr INFERPRINT_OPTIONS = --issues-tests INFERPRINT_COST_OPTIONS = --cost-issues-tests