From 27371176df11d58deaf746f947becc7cdb6f5a67 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Wed, 10 May 2017 16:15:28 +0300 Subject: [PATCH] core: improve Function too hairy calculation 1) Check it in merge_sm_state() which means we're checking more often and fail earlier. We were going to fail anyway, but let's just fail earlier. 2) Make the reasons more obvious. 3) Increase the memory limit. I don't know if this matters but since we're checking in merge_sm_state() we can. Signed-off-by: Dan Carpenter --- smatch_flow.c | 6 +++++- smatch_implied.c | 2 +- smatch_slist.c | 10 +++++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/smatch_flow.c b/smatch_flow.c index 08de0482..b9b58518 100644 --- a/smatch_flow.c +++ b/smatch_flow.c @@ -967,10 +967,14 @@ void __split_stmt(struct statement *stmt) return; if (out_of_memory() || taking_too_long()) { + struct timeval stop; + + gettimeofday(&stop, NULL); __bail_on_rest_of_function = 1; final_pass = 1; - sm_msg("Function too hairy. Giving up."); + sm_msg("Function too hairy. Giving up. %lu seconds", + stop.tv_sec - fn_start_time.tv_sec); fake_a_return(); final_pass = 0; /* turn off sm_msg() from here */ return; diff --git a/smatch_implied.c b/smatch_implied.c index c64924c7..f6dd15a2 100644 --- a/smatch_implied.c +++ b/smatch_implied.c @@ -563,7 +563,7 @@ static void separate_and_filter(struct sm_state *sm, int comparison, struct rang gettimeofday(&time_after, NULL); if (time_after.tv_sec - time_before.tv_sec > 20) { sm->nr_children = 4000; - sm_msg("Function too hairy. Giving up."); + sm_msg("Function too hairy. Giving up after 20 seconds."); } } diff --git a/smatch_slist.c b/smatch_slist.c index bbcef670..14bd177e 100644 --- a/smatch_slist.c +++ b/smatch_slist.c @@ -238,7 +238,7 @@ int out_of_memory(void) * It works out OK for the kernel and so it should work * for most other projects as well. */ - if (sm_state_counter * sizeof(struct sm_state) >= 50000000) + if (sm_state_counter * sizeof(struct sm_state) >= 100000000) return 1; return 0; } @@ -370,9 +370,17 @@ struct sm_state *merge_sm_states(struct sm_state *one, struct sm_state *two) { struct smatch_state *s; struct sm_state *result; + static int warned; if (one == two) return one; + if (out_of_memory()) { + if (!warned) + sm_msg("Function too hairy. No more merges."); + warned = 1; + return one; + } + warned = 0; s = merge_states(one->owner, one->name, one->sym, one->state, two->state); result = alloc_state_no_name(one->owner, one->name, one->sym, s); result->merged = 1; -- 2.11.4.GIT