aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2020-09-13 19:35:28 -0400
committerDavid Malcolm <dmalcolm@redhat.com>2020-09-14 12:29:35 -0400
commit05ab8befe1230c46116aae37d44f2ce0933e8dae (patch)
treee1880cf165139311f135f54f0e722b66c86ef01b
parent799dd4e10047a4aa772fd69c910c5c6a96c36b9f (diff)
downloadgcc-05ab8befe1230c46116aae37d44f2ce0933e8dae.zip
gcc-05ab8befe1230c46116aae37d44f2ce0933e8dae.tar.gz
gcc-05ab8befe1230c46116aae37d44f2ce0933e8dae.tar.bz2
analyzer: add -param=analyzer-max-constraints=
On attempting to run the full test suite with -fanalyzer via make check RUNTESTFLAGS="-v -v --target_board=unix/-fanalyzer" I saw it get stuck on: gcc.c-torture/compile/20001226-1.c It turns out this was on a debug build, rather than a release build; but a release build with -fanalyzer took: real 1m33.689s user 1m30.239s sys 0m2.727s as compared to: real 0m2.361s user 0m2.107s sys 0m0.214s without -fanalyzer. This torture test performs 64 * 64 uniqely-coded comparisons between elements of a pair of arrays until it finds an element that's different, leading to an accumulation of 4096 constraints along the path where no difference is found. "perf" shows most of the time is spent in canonicalizing and copying constraint_manager instances, presumably as it copies and merges states with increasingly more complex sets of constraints as it analyzes further along the "no differences yet" path. This patch crudely works around this by adding a -param=analyzer-max-constraints= limit, defaulting to 20, above which constraints will be silently dropped. With this -fanalyzer takes: real 0m6.935s user 0m6.413s sys 0m0.396s on the above case. gcc/analyzer/ChangeLog: * analyzer.opt (-param=analyzer-max-constraints=): New param. * constraint-manager.cc (constraint_manager::add_constraint_internal): Silently reject attempts to add constraints when the above limit is reached.
-rw-r--r--gcc/analyzer/analyzer.opt4
-rw-r--r--gcc/analyzer/constraint-manager.cc3
2 files changed, 7 insertions, 0 deletions
diff --git a/gcc/analyzer/analyzer.opt b/gcc/analyzer/analyzer.opt
index 07bff33..94a686d 100644
--- a/gcc/analyzer/analyzer.opt
+++ b/gcc/analyzer/analyzer.opt
@@ -30,6 +30,10 @@ The maximum number of 'after supernode' exploded nodes within the analyzer per s
Common Joined UInteger Var(param_analyzer_max_enodes_per_program_point) Init(8) Param
The maximum number of exploded nodes per program point within the analyzer, before terminating analysis of that point.
+-param=analyzer-max-constraints=
+Common Joined UInteger Var(param_analyzer_max_constraints) Init(20) Param
+The maximum number of constraints per state.
+
-param=analyzer-max-recursion-depth=
Common Joined UInteger Var(param_analyzer_max_recursion_depth) Init(2) Param
The maximum number of times a callsite can appear in a call stack within the analyzer, before terminating analysis of a call that would recurse deeper.
diff --git a/gcc/analyzer/constraint-manager.cc b/gcc/analyzer/constraint-manager.cc
index c10b770..e578e05 100644
--- a/gcc/analyzer/constraint-manager.cc
+++ b/gcc/analyzer/constraint-manager.cc
@@ -940,6 +940,9 @@ constraint_manager::add_constraint_internal (equiv_class_id lhs_id,
enum constraint_op c_op,
equiv_class_id rhs_id)
{
+ if (m_constraints.length () >= param_analyzer_max_constraints)
+ return;
+
constraint new_c (lhs_id, c_op, rhs_id);
/* Remove existing constraints that would be implied by the