From d586630edfd9a1ba70e0642f6eaedb38c4a35e2e Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Fri, 17 May 2019 07:38:50 -0700 Subject: [PATCH] [pules] do not print templated part of function names Summary: This messes with the deduplication heuristic when templated function names show up in the error messages, since the heuristic demands that the error messages are the same. Reviewed By: mbouaziz Differential Revision: D15374333 fbshipit-source-id: 70232d254 --- infer/src/IR/Typ.ml | 9 +++++- .../codetoanalyze/cpp/pulse/deduplication.cpp | 31 ++++++++++++++++++- .../tests/codetoanalyze/cpp/pulse/issues.exp | 2 ++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/infer/src/IR/Typ.ml b/infer/src/IR/Typ.ml index 808d5831a..a6f6dca91 100644 --- a/infer/src/IR/Typ.ml +++ b/infer/src/IR/Typ.ml @@ -1277,7 +1277,14 @@ module Procname = struct (** Pretty print a proc name *) let pp f pn = F.pp_print_string f (to_string pn) - let describe f pn = F.pp_print_string f (hashable_name pn) + let describe f pn = + let name = hashable_name pn in + match String.lsplit2 ~on:'<' name with + | Some (name_without_template, _template_part) -> + F.pp_print_string f name_without_template + | None -> + F.pp_print_string f name + module Hashable = struct type nonrec t = t diff --git a/infer/tests/codetoanalyze/cpp/pulse/deduplication.cpp b/infer/tests/codetoanalyze/cpp/pulse/deduplication.cpp index 965307e08..1384704c2 100644 --- a/infer/tests/codetoanalyze/cpp/pulse/deduplication.cpp +++ b/infer/tests/codetoanalyze/cpp/pulse/deduplication.cpp @@ -33,7 +33,7 @@ void SomeTemplatedClass::lifetime_error_bad(A* a) { SomeTemplatedClass::templated_wrapper_access_ok(a); } -void materialize_template_instances() { +void materialize_class_template_instances() { A* a1 = new A(); SomeTemplatedClass x1; x1.lifetime_error_bad(a1); @@ -43,4 +43,33 @@ void materialize_template_instances() { x2.lifetime_error_bad(a2); } +template +void templated_delete_function(T t, A* a) { + delete a; +} + +template +void templated_access_function(T t, A* a) { + int x = a->f; +} + +template +void templated_function_bad(T t) { + A* a = new A(); + templated_delete_function(t, a); + templated_access_function(t, a); +} + +template void templated_delete_function(int, A*); +template void templated_delete_function(bool, A*); +template void templated_access_function(int, A*); +template void templated_access_function(bool, A*); +template void templated_function_bad(int); +template void templated_function_bad(bool); + +void materialize_function_template_instances() { + templated_function_bad(42); + templated_function_bad(true); +} + } // namespace deduplication diff --git a/infer/tests/codetoanalyze/cpp/pulse/issues.exp b/infer/tests/codetoanalyze/cpp/pulse/issues.exp index 1da54140e..350a66208 100644 --- a/infer/tests/codetoanalyze/cpp/pulse/issues.exp +++ b/infer/tests/codetoanalyze/cpp/pulse/issues.exp @@ -4,6 +4,8 @@ codetoanalyze/cpp/pulse/closures.cpp, implicit_ref_capture_destroy_invoke_bad, 6 codetoanalyze/cpp/pulse/closures.cpp, ref_capture_destroy_invoke_bad, 6, USE_AFTER_LIFETIME, no_bucket, ERROR, [invalidation part of the trace starts here,memory is the address of a stack variable `s` whose lifetime has ended here,use-after-lifetime part of the trace starts here,`&s` captured as `s`,invalid access to `&f` here] codetoanalyze/cpp/pulse/deduplication.cpp, deduplication::SomeTemplatedClass::lifetime_error_bad, 2, USE_AFTER_DELETE, no_bucket, ERROR, [invalidation part of the trace starts here,when calling `templated_wrapper_delete_ok` here,memory was invalidated by `delete` on `a` here,use-after-lifetime part of the trace starts here,when calling `templated_wrapper_access_ok` here,invalid access to `a->f` here] codetoanalyze/cpp/pulse/deduplication.cpp, deduplication::SomeTemplatedClass::lifetime_error_bad, 2, USE_AFTER_DELETE, no_bucket, ERROR, [invalidation part of the trace starts here,when calling `templated_wrapper_delete_ok` here,memory was invalidated by `delete` on `a` here,use-after-lifetime part of the trace starts here,when calling `templated_wrapper_access_ok` here,invalid access to `a->f` here] +codetoanalyze/cpp/pulse/deduplication.cpp, deduplication::templated_function_bad<_Bool>, 3, USE_AFTER_DELETE, no_bucket, ERROR, [invalidation part of the trace starts here,when calling `deduplication::templated_delete_function` here,memory was invalidated by `delete` on `a` here,use-after-lifetime part of the trace starts here,assigned to `a`,when calling `deduplication::templated_access_function` here,invalid access to `a->f` here] +codetoanalyze/cpp/pulse/deduplication.cpp, deduplication::templated_function_bad, 3, USE_AFTER_DELETE, no_bucket, ERROR, [invalidation part of the trace starts here,when calling `deduplication::templated_delete_function` here,memory was invalidated by `delete` on `a` here,use-after-lifetime part of the trace starts here,assigned to `a`,when calling `deduplication::templated_access_function` here,invalid access to `a->f` here] codetoanalyze/cpp/pulse/interprocedural.cpp, delete_aliased_then_read_bad, 4, USE_AFTER_DELETE, no_bucket, ERROR, [invalidation part of the trace starts here,assigned to `y`,memory was invalidated by `delete` on `y` here,use-after-lifetime part of the trace starts here,assigned to `z`,when calling `wraps_read()` here,when calling `wraps_read_inner()` here,invalid access to `x->f` here] codetoanalyze/cpp/pulse/interprocedural.cpp, delete_inner_then_write_bad, 2, USE_AFTER_DELETE, no_bucket, ERROR, [invalidation part of the trace starts here,when calling `wraps_delete_inner()` here,memory was invalidated by `delete` on `x` here,use-after-lifetime part of the trace starts here,when calling `wraps_read()` here,when calling `wraps_read_inner()` here,invalid access to `x->f` here] codetoanalyze/cpp/pulse/interprocedural.cpp, delete_then_read_bad, 2, USE_AFTER_DELETE, no_bucket, ERROR, [invalidation part of the trace starts here,memory was invalidated by `delete` on `x` here,use-after-lifetime part of the trace starts here,when calling `wraps_read()` here,when calling `wraps_read_inner()` here,invalid access to `x->f` here]