PR analyzer/94378 reports a false -Wanalyzer-malloc-leak when returning a struct containing a malloc-ed pointer. The issue is that the assignment code was not handling compound copies, only copying top-level values from region to region, and not copying child values. This patch introduces a region_model::copy_region function, using it for assignments and when analyzing function return values. It recursively copies nested values within structs, unions, and arrays, fixing the bug. gcc/analyzer/ChangeLog: PR analyzer/94378 * checker-path.cc: Include "bitmap.h". * constraint-manager.cc: Likewise. * diagnostic-manager.cc: Likewise. * engine.cc: Likewise. (exploded_node::detect_leaks): Pass null region_id to pop_frame. * program-point.cc: Include "bitmap.h". * program-state.cc: Likewise. * region-model.cc (id_set<region_id>::id_set): Convert to... (region_id_set::region_id_set): ...this. (svalue_id_set::svalue_id_set): New ctor. (region_model::copy_region): New function. (region_model::copy_struct_region): New function. (region_model::copy_union_region): New function. (region_model::copy_array_region): New function. (stack_region::pop_frame): Drop return value. Add "result_dst_rid" param; if it is non-null, use copy_region to copy the result to it. Rather than capture and pass a single "known used" return value to be used by purge_unused_values, instead gather and pass a set of known used return values. (root_region::pop_frame): Drop return value. Add "result_dst_rid" param. (region_model::on_assignment): Use copy_region. (region_model::on_return): Likewise for the result. (region_model::on_longjmp): Pass null for pop_frame's result_dst_rid. (region_model::update_for_return_superedge): Pass the region for the return value of the call, if any, to pop_frame, rather than setting the lvalue for the lhs of the result. (region_model::pop_frame): Drop return value. Add "result_dst_rid" param. (region_model::purge_unused_svalues): Convert third param from an svalue_id * to an svalue_id_set *, updating the initial populating of the "used" bitmap accordingly. Don't remap it when done. (struct selftest::coord_test): New selftest fixture, extracted from... (selftest::test_dump_2): ...here. (selftest::test_compound_assignment): New selftest. (selftest::test_stack_frames): Pass null to new param of pop_frame. (selftest::analyzer_region_model_cc_tests): Call the new selftest. * region-model.h (class id_set): Delete template. (class region_id_set): Reimplement, using old id_set implementation. (class svalue_id_set): Likewise. Convert from auto_sbitmap to auto_bitmap. (region::get_active_view): New accessor. (stack_region::pop_frame): Drop return value. Add "result_dst_rid" param. (root_region::pop_frame): Likewise. (region_model::pop_frame): Likewise. (region_model::copy_region): New decl. (region_model::purge_unused_svalues): Convert third param from an svalue_id * to an svalue_id_set *. (region_model::copy_struct_region): New decl. (region_model::copy_union_region): New decl. (region_model::copy_array_region): New decl. gcc/testsuite/ChangeLog: PR analyzer/94378 * gcc.dg/analyzer/compound-assignment-1.c: New test. * gcc.dg/analyzer/compound-assignment-2.c: New test. * gcc.dg/analyzer/compound-assignment-3.c: New test.
Name |
Last commit
|
Last update |
---|---|---|
.. | ||
ChangeLog | Loading commit data... | |
analysis-plan.cc | Loading commit data... | |
analysis-plan.h | Loading commit data... | |
analyzer-logging.cc | Loading commit data... | |
analyzer-logging.h | Loading commit data... | |
analyzer-pass.cc | Loading commit data... | |
analyzer-selftests.cc | Loading commit data... | |
analyzer-selftests.h | Loading commit data... | |
analyzer.cc | Loading commit data... | |
analyzer.h | Loading commit data... | |
analyzer.opt | Loading commit data... | |
bar-chart.cc | Loading commit data... | |
bar-chart.h | Loading commit data... | |
call-string.cc | Loading commit data... | |
call-string.h | Loading commit data... | |
checker-path.cc | Loading commit data... | |
checker-path.h | Loading commit data... | |
constraint-manager.cc | Loading commit data... | |
constraint-manager.h | Loading commit data... | |
diagnostic-manager.cc | Loading commit data... | |
diagnostic-manager.h | Loading commit data... | |
engine.cc | Loading commit data... | |
engine.h | Loading commit data... | |
exploded-graph.h | Loading commit data... | |
function-set.cc | Loading commit data... | |
function-set.h | Loading commit data... | |
pending-diagnostic.cc | Loading commit data... | |
pending-diagnostic.h | Loading commit data... | |
program-point.cc | Loading commit data... | |
program-point.h | Loading commit data... | |
program-state.cc | Loading commit data... | |
program-state.h | Loading commit data... | |
reachability.h | Loading commit data... | |
region-model.cc | Loading commit data... | |
region-model.h | Loading commit data... | |
sm-file.cc | Loading commit data... | |
sm-malloc.cc | Loading commit data... | |
sm-malloc.dot | Loading commit data... | |
sm-pattern-test.cc | Loading commit data... | |
sm-sensitive.cc | Loading commit data... | |
sm-signal.cc | Loading commit data... | |
sm-taint.cc | Loading commit data... | |
sm.cc | Loading commit data... | |
sm.h | Loading commit data... | |
state-purge.cc | Loading commit data... | |
state-purge.h | Loading commit data... | |
supergraph.cc | Loading commit data... | |
supergraph.h | Loading commit data... |