analyzer: fix equivalence class state purging [PR103533]
commitc9543403c19fdc3c3b5a8db8546340de085bd14e
authorDavid Malcolm <dmalcolm@redhat.com>
Mon, 6 Dec 2021 19:04:35 +0000 (6 14:04 -0500)
committerDavid Malcolm <dmalcolm@redhat.com>
Mon, 6 Dec 2021 23:36:33 +0000 (6 18:36 -0500)
treeb6ab4e9e0cec37beb184a27c2df3b38a485e865c
parent325c6163a33af91264d1b7817a45b8425d5e6a4f
analyzer: fix equivalence class state purging [PR103533]

Whilst debugging state explosions seen when enabling taint detection
with -fanalyzer (PR analyzer/103533), I noticed that constraint
manager instances could contain stray, redundant constants, such
as this instance:

constraint_manager:
  equiv classes:
    ec0: {(int)0 == [m_constant]‘0’}
    ec1: {(size_t)4 == [m_constant]‘4’}
  constraints:

where there are two equivalence classes, each just containing a
constant, with no constraints using them.

This patch makes constraint_manager::canonicalize more aggressive
about purging state, handling the case of purging a redundant
EC containing just a constant.

gcc/analyzer/ChangeLog:
PR analyzer/103533
* constraint-manager.cc (equiv_class::contains_non_constant_p):
New.
(constraint_manager::canonicalize): Call it when determining
redundant ECs.
(selftest::test_purging): New selftest.
(selftest::run_constraint_manager_tests): Likewise.
* constraint-manager.h (equiv_class::contains_non_constant_p):
New decl.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
gcc/analyzer/constraint-manager.cc
gcc/analyzer/constraint-manager.h